Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arlania;
- import java.sql.*;
- import com.arlania.world.entity.impl.player.Player;
- public class FoxVote implements Runnable {
- public static final String HOST = "66.85.";
- public static final String USER = "runeziuj_";
- public static final String PASS = "cKeZo";
- public static final String DATABASE = "runeziuj";
- private Player player;
- private Connection conn;
- private Statement stmt;
- public FoxVote(Player player) {
- this.player = player;
- }
- @Override
- public void run() {
- try {
- if (!connect(HOST, DATABASE, USER, PASS)) {
- return;
- }
- String name = player.getUsername().toLowerCase().replace(" ", "_");
- ResultSet rs = executeQuery(
- "SELECT * FROM fx_votes WHERE username='" + name + "' AND claimed=0 AND callback_date IS NOT NULL");
- while (rs.next()) {
- String timestamp = rs.getTimestamp("callback_date").toString();
- String ipAddress = rs.getString("ip_address");
- int siteId = rs.getInt("site_id");
- player.getInventory().add(19670, 5);
- player.getInventory().add(995, 5000000);
- player.getPacketSender().sendMessage("<shad=1>@mag@Thanks for voting!");
- System.out.println("[VOTESYSTEM] Vote claimed by " + name + ". (sid: " + siteId + ", ip: " + ipAddress
- + ", time: " + timestamp + ")");
- rs.updateInt("claimed", 1); // do not delete otherwise they can
- // reclaim!
- rs.updateRow();
- }
- 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