Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.game.database.impl;
- import java.sql.*;
- import server.game.content.DoubleExperience;
- import server.game.database.ConnectionPool;
- import server.game.database.DatabaseConnection;
- import server.game.player.Player;
- import server.game.player.net.PlayerUpdating;
- /**
- * A system to display the servers statistics on a website.
- *
- * @author Titanium
- *
- */
- public class Statistics {
- public static Player player;
- static int totalvotes = 0;
- static int npcsKilled = 0;
- static String currentMinigame = "None";
- static String query = false;
- public static int getDoubleExperience() {
- if (DoubleExperience.isDoubleExperience()) {
- return 1;
- } else {
- return 0;
- }
- }
- private static ConnectionPool pool;
- public static void init() {
- //format is ip, port, then database name, then user name, and finally password.
- pool = new ConnectionPool("someIP", "3306", "someDB", "someuser", "somepass");
- }
- public static void execute() {
- query = "UPDATE `statistics` SET `PlayersOnline` = '"+PlayerUpdating.getPlayerCount()+"', `StaffOnline` = '"+PlayerUpdating.getStaffCount()+"', `TotalVotes` = '"+totalvotes+"', `TotalNpcsKilled` = '"+npcsKilled+"', `CurrentMinigame` = '"+currentMinigame+"', `DoubleExperience` = '"+getDoubleExperience()+"';";
- System.out.println(query);
- execQuery(query);
- //execQuery("INSERT INTO `PlayersOnline` (PlayersOnline, StaffOnline, TotalVotes, TotalNpcsKilled, CurrentMinigame, DoubleExperience) VALUES('1','"+PlayerUpdating.getPlayerCount()+"');");
- }
- private static void execQuery(String string) {
- try {
- DatabaseConnection connection = pool.nextFree();
- Statement stmt = connection.getConnection().createStatement();
- stmt.executeUpdate(string);
- stmt.close();
- connection.returnConnection();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement