Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package server.game.database.impl;
  2.  
  3. import java.sql.*;
  4.  
  5. import server.game.content.DoubleExperience;
  6. import server.game.database.ConnectionPool;
  7. import server.game.database.DatabaseConnection;
  8. import server.game.player.Player;
  9. import server.game.player.net.PlayerUpdating;
  10.  
  11. /**
  12. * A system to display the servers statistics on a website.
  13. *
  14. * @author Titanium
  15. *
  16. */
  17. public class Statistics {
  18. public static Player player;
  19. static int totalvotes = 0;
  20. static int npcsKilled = 0;
  21. static String currentMinigame = "None";
  22.  
  23. static String query = false;
  24.  
  25. public static int getDoubleExperience() {
  26. if (DoubleExperience.isDoubleExperience()) {
  27. return 1;
  28. } else {
  29. return 0;
  30. }
  31. }
  32. private static ConnectionPool pool;
  33.  
  34. public static void init() {
  35. //format is ip, port, then database name, then user name, and finally password.
  36. pool = new ConnectionPool("someIP", "3306", "someDB", "someuser", "somepass");
  37. }
  38. public static void execute() {
  39.  
  40. query = "UPDATE `statistics` SET `PlayersOnline` = '"+PlayerUpdating.getPlayerCount()+"', `StaffOnline` = '"+PlayerUpdating.getStaffCount()+"', `TotalVotes` = '"+totalvotes+"', `TotalNpcsKilled` = '"+npcsKilled+"', `CurrentMinigame` = '"+currentMinigame+"', `DoubleExperience` = '"+getDoubleExperience()+"';";
  41.  
  42. System.out.println(query);
  43. execQuery(query);
  44.  
  45. //execQuery("INSERT INTO `PlayersOnline` (PlayersOnline, StaffOnline, TotalVotes, TotalNpcsKilled, CurrentMinigame, DoubleExperience) VALUES('1','"+PlayerUpdating.getPlayerCount()+"');");
  46.  
  47. }
  48.  
  49. private static void execQuery(String string) {
  50. try {
  51. DatabaseConnection connection = pool.nextFree();
  52. Statement stmt = connection.getConnection().createStatement();
  53. stmt.executeUpdate(string);
  54. stmt.close();
  55. connection.returnConnection();
  56. } catch (Exception e) {
  57. e.printStackTrace();
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement