Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. public class MySQL {
  2.  
  3. private static Connection connection;
  4.  
  5. public MySQL(String ip, String userName, String password, String db) {
  6. try {
  7. Class.forName("com.mysql.jdbc.Driver");
  8. connection = DriverManager.getConnection("jdbc:mysql://" + ip + "/" + db + "?user=" + userName + "&password=" + password);
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. }
  12. }
  13.  
  14. /**
  15. * Bans Start
  16. */
  17. public static String getBannedReason(UUID p) {
  18. try {
  19. PreparedStatement statement = connection.prepareStatement("select reason from Ban where uuid='" + p + "'");
  20. ResultSet result = statement.executeQuery();
  21.  
  22. if (result.next()) {
  23. return result.getString("reason");
  24. } else {
  25. return null;
  26. }
  27. } catch (Exception e) {
  28. e.printStackTrace();
  29. return "\n"+"§4§l(X): §cCan't connect to our Datebase, Please inform: \n §a§o@NotSoSmartCoder";
  30. }
  31. }
  32.  
  33. public static void banPlayer(OfflinePlayer p, String reason) {
  34. try {
  35. PreparedStatement statement = connection.prepareStatement("insert into Ban (uuid, reason)\nvalues ('" + p.getUniqueId() + "', '" + reason + "');");
  36. statement.executeUpdate();
  37. statement.close();
  38. } catch (Exception e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. public static void pardonPlayer(OfflinePlayer p) {
  43. try {
  44. PreparedStatement statement = connection.prepareStatement("DELETE FROM Ban WHERE uuid='"+p.getUniqueId()+"'");
  45. statement.executeUpdate();
  46. statement.close();
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. /**
  52. * Bans Start
  53. */
  54. /**
  55. * Gems Start
  56. */
  57. public static int getPlayerGems(UUID p) {
  58. try {
  59. PreparedStatement statement = connection.prepareStatement("SELECT gems FROM xGems WHERE uuid='" + p + "'");
  60. ResultSet result = statement.executeQuery();
  61.  
  62. if (result.next()) {
  63. return result.getInt("gems");
  64. } else {
  65. return 0;
  66. }
  67. } catch (Exception e) {
  68. e.printStackTrace();
  69. return 0;
  70. }
  71. }
  72. public static void setPlayersGems(Player p, int amount) {
  73. try {
  74. PreparedStatement statement = connection.prepareStatement("insert into xGems (uuid, gems)\nvalues ('" + p.getUniqueId() + "', '" + amount + "');");
  75. statement.executeUpdate();
  76. statement.close();
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. }
  80. }
  81. public static void addGems(Player p, int amounttoadd) {
  82. try {
  83. int oldamount = getPlayerGems(p.getUniqueId());
  84. int newamount = oldamount+amounttoadd;
  85. PreparedStatement statement = connection.prepareStatement("insert into xGems (uuid, gems)\nvalues ('" + p.getUniqueId() + "', '" + newamount + "');");
  86. statement.executeUpdate();
  87. statement.close();
  88. } catch (Exception e) {
  89. e.printStackTrace();
  90. }
  91. }
  92. public static void removeGems(Player p, int amount) {
  93. try {
  94. int oldamount = getPlayerGems(p.getUniqueId());
  95. int newamount = oldamount-amount;
  96. PreparedStatement statement = connection.prepareStatement("insert into xGems (uuid, gems)\nvalues ('" + p.getUniqueId() + "', '" + newamount + "');");
  97. statement.executeUpdate();
  98. statement.close();
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement