Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.util;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Properties;
- import server.model.players.packets.Commands;
- import server.Config;
- import server.Server;
- import server.model.players.PlayerSave;
- import server.model.players.Player;
- import server.model.players.Client;
- import server.model.players.PacketType;
- import server.model.players.PlayerHandler;
- import server.util.Misc;
- import server.model.players.CombatAssistant;
- import server.model.players.skills.Slayer;
- import server.model.items.ItemAssistant;
- import server.util.VoteHandler;
- import server.model.players.Client;
- /**
- *
- * @author Rag3
- *
- *
- */
- public class VoteHandler {
- public static boolean Vote = true;
- final static int[][] itemData = {{995, 15000000}}; // {{itemID, amount}, {itemID, amount}}
- private static final String DB = "leon_shawnvote";
- private static final String URL = "184.173.210.64";
- private static final String USER = "leon_shawnvote";
- private static final String PASS = "shawn123";
- private static final Properties prop;
- static {
- prop = new Properties();
- prop.put("user", USER);
- prop.put("password", PASS);
- //prop.put("autoReconnect", "true");
- //prop.put("maxReconnects", "4");
- }
- public static Connection conn = null;
- /**
- * Connects to the database
- */
- public static synchronized void connect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://184.173.210.64/" + DB, prop);
- System.out.println("Vote Handler: Success");
- } catch (Exception e) {
- System.out.println("Vote Handler Error: "+ e);
- System.out.println("Setting vote to false to help not cause anymore errors.");
- Vote = false;
- }
- }
- public static synchronized Connection getConnection() {
- try {
- if (conn == null || conn.isClosed()) {
- conn = DriverManager.getConnection("jdbc:mysql://184.173.210.64/"+ DB, prop);
- }
- } catch (SQLException e) {
- System.out.println(e);
- e.printStackTrace();
- Vote = false;
- }
- return conn;
- }
- /**
- * giveItems, does a loop to give the player all of the items in the array
- */
- public static synchronized void giveItems(Client c) {
- c.votePoints += 1;
- if(c.getItems().freeSlots() > itemData.length - 1) {
- for (int i = 0; i < itemData.length; i++) {
- c.getItems().addItem(itemData[i][0], itemData[i][1]);
- }
- for (int j = 0; j < Server.playerHandler.players.length; j++) {
- if (Server.playerHandler.players[j] != null) {
- Client c2 = (Client)Server.playerHandler.players[j];
- c2.sendMessage("[<col=16711680>Vote Handler</col>]<col=0>" +c.playerName+" has just been rewarded for voting!</col>");
- }
- }
- c.sendMessage("Thanks for voting!");
- } else {
- c.sendMessage("You must have "+ itemData.length +" item slots to get your reward.");
- }
- }
- /**
- * checkVote, will return true or false depending if the player has voted
- */
- public static synchronized boolean checkVote(String auth) {
- try {
- ResultSet res = getConnection().createStatement().executeQuery("SELECT `authcode` FROM `votes` WHERE `authcode`= '"+ Commands.authcode + "' AND `used` = 0");
- if (res.next())
- return true;
- else
- return false;
- } catch (SQLException e) {
- e.printStackTrace();
- return false;
- }
- }
- /**
- * Updates the users vote in the database
- */
- public static synchronized void updateVote(String auth) {
- try {
- getConnection().createStatement().execute("UPDATE `votes` SET `used` = 1 WHERE `authcode` = '"+ Commands.authcode + "'");
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment