Thread: Donation Claim Command

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 Donation Claim Command 
    Registered Member
    Join Date
    Oct 2020
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Solved this one!
    Reply With Quote  
     

  2. #2  
    BoomScape #1
    BoomScape's Avatar
    Join Date
    May 2013
    Posts
    2,422
    Thanks given
    289
    Thanks received
    234
    Rep Power
    48
    Quote Originally Posted by jocitaclifton View Post
    I am having trouble setting up a command to automatically claim a donation on my 667 revision server. I have everything set up on the backend, including the webstore and mySQL databases. I have also implemented server side code in a Donation.java class.

    Here is the important part of the donation.java class, excluding database information:

    Code:
    public class Donation implements Runnable {
    
    	public static final String HOST = "removed"; // website ip address
    	public static final String USER = "removed";
    	public static final String PASS = "removed";
    	public static final String DATABASE = "removed";
    
    	private Player player;
    	private Connection conn;
    	private Statement stmt;
    
    	/**
    	 * The constructor
    	 * @Param player
    	 */
    	public Donation(Player player) {
    		this.player = player;
    	}
    
    	@Override
    	public void run() {
    		try {
    			if (!connect(HOST, DATABASE, USER, PASS)) {
    				return;
    			}
    
    			String name = player.getUsername().replace("_", " ");
    			ResultSet rs = executeQuery("SELECT * FROM payments WHERE player_name='"+name+"' AND status='Completed' AND claimed=0");
    
    			while (rs.next()) {
    				int item_number = rs.getInt("item_number");
    				double paid = rs.getDouble("amount");
    				int quantity = rs.getInt("quantity");
    
    				switch (item_number) {// add products according to their ID in the ACP
    
    				case 1023: // example
    					player.getInventory().addItem(14484, 1);
              	    			player.getPackets().sendGameMessage("<col=00ff00>Thanks for donating.");
    					break;
    
    				}
    
    				rs.updateInt("claimed", 1); // do not delete otherwise they can reclaim!
    				rs.updateRow();
    			}
    
    			destroy();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	/**
    	 *
    	 * @Param host the host ip address or url
    	 * @Param database the name of the database
    	 * @Param user the user attached to the database
    	 * @Param pass the users password
    	 * @Return true if connected
    	 */
    	public boolean connect(String host, String database, String user, String pass) {
    		try {
    			this.conn = DriverManager.getConnection("jdbc:mysql://"+host+":3306/"+database, user, pass);
    			return true;
    		} catch (SQLException e) {
    			System.out.println("Failing connecting to database!");
    			return false;
    		}
    	}
    
    	/**
    	 * Disconnects from the MySQL server and destroy the connection
    	 * and statement instances
    	 */
    	public void destroy() {
            try {
        		conn.close();
            	conn = null;
            	if (stmt != null) {
        			stmt.close();
            		stmt = null;
            	}
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    
    	/**
    	 * Executes an update query on the database
    	 * @Param query
    	 * @see {@link Statement#executeUpdate}
    	 */
    	public int executeUpdate(String query) {
            try {
            	this.stmt = this.conn.createStatement(1005, 1008);
                int results = stmt.executeUpdate(query);
                return results;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return -1;
        }
    
    	/**
    	 * Executres a query on the database
    	 * @Param query
    	 * @see {@link Statement#executeQuery(String)}
    	 * @Return the results, never null
    	 */
    	public ResultSet executeQuery(String query) {
            try {
            	this.stmt = this.conn.createStatement(1005, 1008);
                ResultSet results = stmt.executeQuery(query);
                return results;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return null;
        }
    }
    Here is the command I created to claim a donation:

    Code:
    			if (cmd[0].equalsIgnoreCase("claim")) {
    				new Thread(new Donation(player)).start();
    				return true;
    			}
    I have performed a real transaction in my webstore and have attempted to claim the donation on the server. Absolutely nothing happens and I get no output in the server console. I cannot tell if it is even trying to establish a connection with the MySQL database. Any insight appreciated! Thanks guys.
    Sounds most likely as if the database you are connecting to doesn't have the data, please also show the database table content you currently have
    Attached image
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Oct 2020
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by BoomScape View Post
    Sounds most likely as if the database you are connecting to doesn't have the data, please also show the database table content you currently have
    https://imgur.com/a/FCJZwj0

    Here is the database table. I can confirm that under payments, I can see my test transaction, so it does seem to have the necessary information in the database. Let me know what you think.
    Reply With Quote  
     

  4. #4  
    BoomScape #1
    BoomScape's Avatar
    Join Date
    May 2013
    Posts
    2,422
    Thanks given
    289
    Thanks received
    234
    Rep Power
    48
    Quote Originally Posted by jocitaclifton View Post
    https://imgur.com/a/FCJZwj0

    Here is the database table. I can confirm that under payments, I can see my test transaction, so it does seem to have the necessary information in the database. Let me know what you think.
    In payments tables show the contents, or add me on Discord so I can check further
    Attached image
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Oct 2020
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Here is the payment table. My test transaction is present as expected. I am not currently thinking it has anything to do with the SQL file or the database.

    https://imgur.com/a/2mhye1V
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Oct 2020
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Willing to pay for help with this
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Aug 2021
    Posts
    19
    Thanks given
    1
    Thanks received
    5
    Rep Power
    9
    Hey, check your db
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Oct 2020
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Onyxia RSPS View Post
    Hey, check your db
    What about it? There is no console output when I try to claim the donation, so it doesn't seem like the thread is even being called.
    Reply With Quote  
     

  9. #9  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Damnnn new thread on every command good shit man
    Reply With Quote  
     

  10. Thankful user:


  11. #10  
    Registered Member
    Join Date
    Oct 2020
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Tyrant View Post
    Damnnn new thread on every command good shit man
    Doesn’t seem ideal but I’m not sure how else to go about it
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 2
    Last Post: 01-08-2020, 08:52 AM
  2. Replies: 4
    Last Post: 02-11-2017, 07:00 PM
  3. Replies: 4
    Last Post: 09-09-2013, 10:29 PM
  4. 614 Vote and Donate Claim Commands [Buying]
    By WorldRevival in forum Buying
    Replies: 0
    Last Post: 09-09-2013, 03:19 AM
  5. [PI] Vote4Cash ::Claim Command
    By owner will in forum Help
    Replies: 3
    Last Post: 07-18-2012, 05:43 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •