Advertisement
Guest User

Untitled

a guest
Dec 16th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. package com.Sanfor317;
  2.  
  3.  
  4. import java.sql.ResultSet;
  5.  
  6. import com.Sanfor317.core.network.mysql.Database;
  7. import com.Sanfor317.rs2.entity.player.Player;
  8. import com.Sanfor317.rs2.entity.player.net.out.impl.SendMessage;
  9.  
  10.  
  11. public class Donation implements Runnable {
  12.  
  13. public static final String HOST_ADDRESS = "";
  14. public static final String USERNAME = "";
  15. public static final String PASSWORD = "";
  16. public static final String DATABASE = "";
  17.  
  18. private Player player;
  19.  
  20. @Override
  21. public void run() {
  22. try {
  23. Database db = new Database(HOST_ADDRESS, USERNAME, PASSWORD, DATABASE);
  24.  
  25. if (!db.init()) {
  26. System.err.println("[Donation] Failed to connect to database!");
  27. return;
  28. }
  29.  
  30. String name = player.getUsername().replace("_", " ");
  31. ResultSet rs = db.executeQuery("SELECT * FROM payments WHERE player_name='"+name+"' AND claimed=0");
  32.  
  33. while(rs.next()) {
  34. String item_name = rs.getString("item_name");
  35. int item_number = rs.getInt("item_number");
  36. double amount = rs.getDouble("amount");
  37. int quantity = rs.getInt("quantity");
  38.  
  39. ResultSet result = db.executeQuery("SELECT * FROM products WHERE item_id="+item_number+" LIMIT 1");
  40.  
  41. if (result == null || !result.next()
  42. || !result.getString("item_name").equalsIgnoreCase(item_name)
  43. || result.getDouble("item_price") != amount
  44. || quantity < 1 || quantity > Integer.MAX_VALUE) {
  45. System.out.println("[Donation] Invalid purchase for "+name+" (item: "+item_name+", id: "+item_number+")");
  46. continue;
  47. }
  48.  
  49. handleItems(item_number);
  50. rs.updateInt("claimed", 1);
  51. rs.updateRow();
  52. }
  53.  
  54. db.destroyAll();
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. }
  58. }
  59.  
  60. public void handleItems(int productId) {
  61. switch(productId) {
  62. case 1:
  63. player.send(new SendMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!"));
  64. player.getInventory().add(9005, 1);
  65. // handle item stuff, like adding items, points, etc.
  66. break;
  67. }
  68. }
  69.  
  70. public Donation(Player player) {
  71. this.player = player;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement