SHARE
TWEET

Untitled

a guest Feb 14th, 2020 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package mysql.impl;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.Files;
  5. import java.nio.file.Path;
  6. import java.nio.file.Paths;
  7. import java.nio.file.StandardOpenOption;
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import java.util.concurrent.TimeUnit;
  14.  
  15. import com.arlania.model.PlayerRights;
  16. import com.arlania.util.Misc;
  17. import com.arlania.world.World;
  18. import com.arlania.world.content.PlayerPanel;
  19. import com.arlania.world.entity.impl.player.Player;
  20.  
  21. /**
  22.  * Using this class: To call this class, it's best to make a new thread. You can
  23.  * do it below like so: new Thread(new Donation(player)).start();
  24.  */
  25. public class Donation implements Runnable {
  26.  
  27.     public static final String HOST = "";
  28.     public static final String USER = "";
  29.     public static final String PASS = "";                                                  
  30.     public static final String DATABASE = "";
  31.  
  32.     private Player player;
  33.     private Connection conn;
  34.     private Statement stmt;
  35.  
  36.     /**
  37.      * The constructor
  38.      *  no sec
  39.      * @param player
  40.      */
  41.     public Donation(Player player) {
  42.         this.player = player;
  43.     }
  44.     @Override
  45.     public void run() {
  46.         if (System.currentTimeMillis() - player.lastDonationClaim < TimeUnit.SECONDS.toMillis(30)) {
  47.             player.sendMessage("@red@You cant claim for another 30 seconds, please wait.");
  48.             return;
  49.         }
  50.         try {
  51.             if (!connect(HOST, DATABASE, USER, PASS)) {
  52.                 return;
  53.             }
  54.             String name = player.getUsername().replace("_", " ");
  55.             ResultSet rs = executeQuery("SELECT * FROM payments WHERE player_name='"+name+"' AND status='Completed' AND claimed=0");
  56.             while (rs.next()) {
  57.                 int item_number = rs.getInt("item_number");
  58.                 double paid = rs.getDouble("amount");
  59.                 int quantity = 1 * rs.getInt("quantity");
  60.                 switch (item_number) {// add products according to their ID in
  61.                                         // the ACP         
  62.                 case 96:
  63.                     player.getInventory().add(619, 1 * quantity);
  64.                     player.sendMessage("Thanks for donating!");
  65.                     World.sendMessage("[<img=10>][@red@Donation@bla@] @red@" + player.getUsername()
  66.                             + "@bla@ has just donated Thanks for @red@Contributing@bla@!");
  67.                     Misc.println_debug(""+player.getUsername()+" has just donated $"+paid+"");
  68.                     break;
  69.                 }
  70.                 rs.updateInt("claimed", 1 * quantity); // set claimed(row) to 1. (= cant claim twice)
  71.                 rs.updateRow(); // send update to sql.
  72.                 player.lastDonationClaim = System.currentTimeMillis();
  73.                 Misc.println_debug("Purchased Name: "+player.getUsername()+" - information saved upon donation.");
  74.                 Misc.println_debug("Purchased Amount: "+paid+" - information saved upon donation.");
  75.                 Misc.println_debug("Host Address: "+player.getHostAddress()+" - information has been uploaded.");
  76.                 Misc.println_debug("Serial Number: "+player.getSerialNumber()+" - information has been uploaded.");
  77.                 Misc.println_debug("Payment Method: "+player.getMethod()+" - information has been uploaded.");
  78.                 Misc.println_debug("Claimed At: "+player.getClaimedAt()+" - information has been uploaded.");
  79.             }
  80.             player.getClaimedAt();
  81.             player.getMethod();
  82.             player.getSerialNumber();
  83.             player.getHostAddress();
  84.             destroy();
  85.         } catch (Exception e) {
  86.             e.printStackTrace();
  87.         }
  88.     }
  89.     public boolean connect(String host, String database, String user, String pass) {
  90.         try {
  91.             this.conn = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database, user, pass);
  92.             System.out.println("YES LORD!");
  93.             return true;
  94.         } catch (SQLException e) {
  95.             System.out.println("Failing connecting to database!");
  96.             return false; //done updatekk sec
  97.         }
  98.     }
  99.  
  100.     /**
  101.      * Disconnects from the MySQL server and destroy the connection and
  102.      * statement instances
  103.      */
  104.     public void destroy() {
  105.         try {
  106.             conn.close();
  107.             conn = null;
  108.             if (stmt != null) {
  109.                 stmt.close();
  110.                 stmt = null;
  111.             }
  112.         } catch (Exception e) {
  113.             e.printStackTrace();
  114.         }
  115.     }
  116.  
  117.     /**
  118.      * Executes an update query on the database
  119.      *
  120.      * @param query
  121.      * @see {@link Statement#executeUpdate}
  122.      */
  123.     public int executeUpdate(String query) {
  124.         try {
  125.             this.stmt = this.conn.createStatement(1005, 1008);
  126.             int results = stmt.executeUpdate(query);
  127.             return results;
  128.         } catch (SQLException ex) {
  129.             ex.printStackTrace();
  130.         }
  131.         return -1;
  132.     }
  133.  
  134.     /**
  135.      * Executres a query on the database
  136.      *
  137.      * @param query
  138.      * @see {@link Statement#executeQuery(String)}
  139.      * @return the results, never null
  140.      */
  141.     public ResultSet executeQuery(String query) {
  142.         try {
  143.             this.stmt = this.conn.createStatement(1005, 1008);
  144.             ResultSet results = stmt.executeQuery(query);
  145.             return results;
  146.         } catch (SQLException ex) {
  147.             ex.printStackTrace();
  148.         }
  149.         return null;
  150.     }
  151. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top