Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Sanfor317;
- import java.sql.ResultSet;
- import com.Sanfor317.core.network.mysql.Database;
- import com.Sanfor317.rs2.entity.player.Player;
- import com.Sanfor317.rs2.entity.player.net.out.impl.SendMessage;
- public class Donation implements Runnable {
- public static final String HOST_ADDRESS = "";
- public static final String USERNAME = "";
- public static final String PASSWORD = "";
- public static final String DATABASE = "";
- private Player player;
- @Override
- public void run() {
- try {
- Database db = new Database(HOST_ADDRESS, USERNAME, PASSWORD, DATABASE);
- if (!db.init()) {
- System.err.println("[Donation] Failed to connect to database!");
- return;
- }
- String name = player.getUsername().replace("_", " ");
- ResultSet rs = db.executeQuery("SELECT * FROM payments WHERE player_name='"+name+"' AND claimed=0");
- while(rs.next()) {
- String item_name = rs.getString("item_name");
- int item_number = rs.getInt("item_number");
- double amount = rs.getDouble("amount");
- int quantity = rs.getInt("quantity");
- ResultSet result = db.executeQuery("SELECT * FROM products WHERE item_id="+item_number+" LIMIT 1");
- if (result == null || !result.next()
- || !result.getString("item_name").equalsIgnoreCase(item_name)
- || result.getDouble("item_price") != amount
- || quantity < 1 || quantity > Integer.MAX_VALUE) {
- System.out.println("[Donation] Invalid purchase for "+name+" (item: "+item_name+", id: "+item_number+")");
- continue;
- }
- handleItems(item_number);
- rs.updateInt("claimed", 1);
- rs.updateRow();
- }
- db.destroyAll();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void handleItems(int productId) {
- switch(productId) {
- case 1:
- player.send(new SendMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!"));
- player.getInventory().add(9005, 1);
- // handle item stuff, like adding items, points, etc.
- break;
- }
- }
- public Donation(Player player) {
- this.player = player;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement