Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mysql.donate;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import com.ruseps.world.entity.impl.player.Player;
- import com.ruseps.util.Misc;
- /**
- * Using this class:
- * To call this class, it's best to make a new thread. You can do it below like so:
- * new Thread(new Donation(player)).start();
- */
- public class Donation implements Runnable {
- public static final String HOST = "162.218.48.215"; // website ip address
- public static final String USER = "rapidpkn_store";
- public static final String PASS = "Australia77";
- public static final String DATABASE = "rapidpkn_store";
- private static int minimum = 500; // must match what u have set on the website!
- private static int maximum = 25000;
- private static double pricePerToken = 0.01; // must match what u have set on the website!
- private Player player;
- private Connection conn;
- private Statement stmt;
- public Donation(Player player) {
- this.player = player;
- }
- @Override
- public void run() {
- try {
- if (!connect(HOST, DATABASE, USER, PASS)) {
- System.out.println("1");
- return;
- }
- System.out.println("2");
- String name = Misc.formatText(player.getUsername());
- ResultSet rs = executeQuery("SELECT * FROM donations WHERE user='"+name+"' AND claimed=0");
- while (rs.next()) {
- System.out.println("3");
- int quantity = rs.getInt("quantity");
- double total = rs.getDouble("amount");
- double ratio = total / quantity;
- if (quantity < minimum || quantity > maximum || ratio != pricePerToken) {
- System.out.println("Invalid purchase detected for "+name+"!");
- continue;
- }
- player.getPointsHandler().incrementDonatorPoints(quantity);
- player.getPointsHandler().refreshPanel();
- player.getPacketSender().sendMessage("Thank you for your donation! You have received "+Misc.format(quantity)+" Donator Points!");
- }
- destroy();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- 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;
- }
- }
- public void destroy() {
- try {
- conn.close();
- conn = null;
- if (stmt != null) {
- stmt.close();
- stmt = null;
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- 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;
- }
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement