Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.util;
- import java.sql.*;
- import server.model.players.Client;
- public class Edy extends Thread {
- private static String url = "jdbc:mysql://quantumx-rsps.com/teemu_mybb";
- private static String user = "teemu_server";
- private static String pass = "lotto9469";//the pass u just entered
- public static Connection con = null;
- public static Statement stm;
- public static void createConnection() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection(url, user, pass);
- stm = con.createStatement();
- } catch (Exception e) {
- e.printStackTrace();
- con = null;
- stm = null;
- }
- }
- public Edy() {
- }
- public void run() {
- while(true) {
- try {
- if(con == null)
- createConnection();
- else
- ping();
- Thread.sleep(10000);//10 seconds
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public static void ping(){
- try {
- String query = "SELECT * FROM donation WHERE Username = 'null'";
- ResultSet rs = stm.executeQuery(query);
- rs.close();
- } catch (Exception e) {
- e.printStackTrace();
- con = null;
- stm = null;
- }
- }
- public static void giveDonor(final Client c) {
- if(con == null){
- if(stm != null){
- try {
- stm = con.createStatement();
- } catch(Exception e){
- con = null;
- stm = null;
- c.sendMessage("An error occured while trying to make you a donor");
- c.sendMessage("please try again in 1 minute.");
- return;
- }
- } else {
- c.sendMessage("An error occured while trying to make you a donor");
- c.sendMessage("please try again in 1 minute.");
- return;
- }
- }
- new Thread(){
- @Override
- public void run()
- {
- try {
- stm.executeUpdate("UPDATE `mybb_users` SET additionalgroups='8' WHERE username LIKE '"+c.playerName+"'");
- c.playerRights = 4;
- } catch (Exception e) {
- e.printStackTrace();
- con = null;
- stm = null;
- }
- }
- }.start();
- }
- public static void handleVoted(final Client c) {
- if(con == null){
- if(stm != null){
- try {
- stm = con.createStatement();
- } catch(Exception e){
- con = null;
- stm = null;
- c.sendMessage("an error occured while trying to claim your vote reward");
- c.sendMessage("please try again in 1 minute.");
- return;
- }
- } else {
- c.sendMessage("an error occured while trying to claim your vote reward");
- c.sendMessage("please try again in 1 minute.");
- return;
- }
- }
- new Thread(){
- @Override
- public void run()
- {
- try {
- stm.executeQuery("SELECT * FROM votes WHERE playerName LIKE '"+c.playerName+"' AND taken='0'");
- ResultSet results = stm.getResultSet();
- if(results.next()) {
- if (rewardVoter(c, false)) {
- stm.executeUpdate("UPDATE `votes` SET taken='1' WHERE playerName LIKE '"+c.playerName+"'");
- rewardVoter(c, true);
- c.sendMessage("Thank you for voting to QuantumX! Vote again every day!.");
- } else {
- c.sendMessage("You don't have enough free space in your inventory.");
- c.sendMessage("Try again when you do.");
- }
- } else {
- c.sendMessage("You didn't ::vote, please vote then try again.");
- }
- } catch (Exception e) {
- e.printStackTrace();
- con = null;
- stm = null;
- }
- }
- }.start();
- }
- public static boolean rewardVoter(Client c, boolean give) {
- if (give) {
- //reward voters with 20 pkp
- c.pkp += 20;
- }
- return true;
- }
- public static void handleDonated(final Client c) {
- if(con == null){
- if(stm != null){
- try {
- stm = con.createStatement();
- } catch(Exception e){
- con = null;
- stm = null;
- c.sendMessage("an error occured while trying to check your donation");
- c.sendMessage("please try again in 1 minute.");
- //e.printStackTrace();
- return;
- }
- } else {
- c.sendMessage("an error occured while trying to check your donation");
- c.sendMessage("please try again in 1 minute.");
- return;
- }
- }
- new Thread(){
- @Override
- public void run()
- {
- try {
- stm.executeQuery("SELECT * FROM donation WHERE username LIKE '"+c.playerName+"' AND Taken='0'");
- ResultSet results = stm.getResultSet();
- if(results.next()) {
- int ID = results.getInt("ID");
- int Package = results.getInt("Package");
- if (rewardDonator(c, Package, false)) {
- stm.executeUpdate("UPDATE `donation` SET Taken='1' WHERE ID='" + ID + "'");
- rewardDonator(c, Package, true);
- c.sendMessage("Thank you very much for your donation to QuantumX.");
- } else {
- c.sendMessage("You don't have enough free space in your inventory.");
- c.sendMessage("Try again when you do.");
- }
- } else {
- c.sendMessage("You didn't donate, please donate then try again.");
- c.sendMessage("Type ::donate to check the store out!");
- }
- } catch (Exception e) {
- e.printStackTrace();
- con = null;
- stm = null;
- }
- }
- }.start();
- }
- public static boolean rewardDonator(Client c, int pack, boolean give) {
- switch (pack) {
- /* Donor Rank*/
- case 5: //Case is the number of the package for the item. For example we have whip with package 5 so we do case 5
- //if (c.getItems().freeSlots() > 0) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
- if (give) {
- //c.getItems().addItem(4151, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
- giveDonor(c);
- }
- //} else {
- //return false;
- //}
- break;
- case 10:
- //if (c.getItems().freeSlots() > 0) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
- if (give) {
- //c.getItems().addItem(4151, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
- c.pkp += 100;
- }
- //} else {
- //return false;
- //}
- break;
- case 20:
- //if (c.getItems().freeSlots() > 0) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
- if (give) {
- //c.getItems().addItem(4151, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
- c.pkp += 200;
- }
- //} else {
- //return false;
- //}
- break;
- case 30:
- //if (c.getItems().freeSlots() > 0) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
- if (give) {
- //c.getItems().addItem(4151, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
- c.pkp += 500;
- }
- //} else {
- //return false;
- //}
- break;
- case 40:
- if (c.getItems().freeSlots() > 2) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
- if (give) {
- c.getItems().addItem(20135, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
- c.getItems().addItem(20139, 1);
- c.getItems().addItem(20143, 1);
- }
- } else {
- return false;
- }
- break;
- case 50:
- if (c.getItems().freeSlots() > 2) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
- if (give) {
- c.getItems().addItem(20159, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
- c.getItems().addItem(20163, 1);
- c.getItems().addItem(20167, 1);
- }
- } else {
- return false;
- }
- break;
- case 60:
- if (c.getItems().freeSlots() > 2) { //if an item needs like 2 slots we change the 0 to 1 (2-1)
- if (give) {
- c.getItems().addItem(20147, 1); //here we have the 4151 being the item id and the 1 being the amount of this item.
- c.getItems().addItem(20151, 1);
- c.getItems().addItem(20155, 1);
- }
- } else {
- return false;
- }
- break;
- default:
- break;
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment