Advertisement
Guest User

Untitled

a guest
May 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. /* */ package de.mevax.mineshine;
  2. /* */
  3. /* */ import java.io.File;
  4. /* */ import java.io.IOException;
  5. /* */ import java.io.PrintStream;
  6. /* */ import java.sql.Connection;
  7. /* */ import java.sql.DriverManager;
  8. /* */ import java.sql.ResultSet;
  9. /* */ import java.sql.SQLException;
  10. /* */ import java.sql.Statement;
  11. /* */ import org.bukkit.configuration.file.FileConfiguration;
  12. /* */ import org.bukkit.configuration.file.FileConfigurationOptions;
  13. /* */
  14. /* */ public class MySQL
  15. /* */ {
  16. /* */ public static String username;
  17. /* */ public static String password;
  18. /* */ public static String host;
  19. /* */ public static int port;
  20. /* */ public static String database;
  21. /* */ public static Connection con;
  22. /* */
  23. /* */ public static void loadsql()
  24. /* */ {
  25. /* 25 */ File file = new File("plugins/MineShine", "MySQL.yml");
  26. /* 26 */ FileConfiguration cfg = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(file);
  27. /* */
  28. /* 28 */ String m = "MySQL.";
  29. /* 29 */ cfg.addDefault(m + "host", "hostname");
  30. /* 30 */ cfg.addDefault(m + "port", Integer.valueOf(3306));
  31. /* 31 */ cfg.addDefault(m + "database", "database");
  32. /* 32 */ cfg.addDefault(m + "username", "username");
  33. /* 33 */ cfg.addDefault(m + "password", "password");
  34. /* 34 */ cfg.options().copyDefaults(true);
  35. /* */ try
  36. /* */ {
  37. /* 37 */ cfg.save(file);
  38. /* */ }
  39. /* */ catch (IOException e)
  40. /* */ {
  41. /* 41 */ e.printStackTrace();
  42. /* */ }
  43. /* 43 */ host = cfg.getString(m + "host");
  44. /* 44 */ port = cfg.getInt(m + "port");
  45. /* 45 */ database = cfg.getString(m + "database");
  46. /* 46 */ username = cfg.getString(m + "username");
  47. /* 47 */ password = cfg.getString(m + "password");
  48. /* */ }
  49. /* */
  50. /* */ public static void connect()
  51. /* */ {
  52. /* 52 */ if (!isConnected()) {
  53. /* */ try
  54. /* */ {
  55. /* 55 */ con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
  56. /* */ }
  57. /* */ catch (SQLException e)
  58. /* */ {
  59. /* 59 */ e.printStackTrace();
  60. /* */ }
  61. /* */ }
  62. /* */ }
  63. /* */
  64. /* */ public static void close()
  65. /* */ {
  66. /* 66 */ if (isConnected()) {
  67. /* */ try
  68. /* */ {
  69. /* 69 */ con.close();
  70. /* */ }
  71. /* */ catch (SQLException e)
  72. /* */ {
  73. /* 73 */ e.printStackTrace();
  74. /* */ }
  75. /* */ }
  76. /* */ }
  77. /* */
  78. /* */ public static boolean contains(String name)
  79. /* */ {
  80. /* 80 */ boolean value = false;
  81. /* */ try
  82. /* */ {
  83. /* 83 */ String query = "SELECT * FROM `stats` WHERE `name` = '" + name + "'";
  84. /* 84 */ ResultSet rs = Query(query);
  85. /* 85 */ if (rs.next()) {
  86. /* 86 */ value = true;
  87. /* */ } else {
  88. /* 88 */ value = false;
  89. /* */ }
  90. /* */ }
  91. /* */ catch (Exception e)
  92. /* */ {
  93. /* 93 */ value = false;
  94. /* 94 */ e.printStackTrace();
  95. /* */ }
  96. /* 96 */ return value;
  97. /* */ }
  98. /* */
  99. /* */ public static ResultSet Query(String query)
  100. /* */ {
  101. /* 101 */ ResultSet rs = null;
  102. /* */ try
  103. /* */ {
  104. /* 104 */ Statement stmt = con.createStatement();
  105. /* 105 */ stmt.executeQuery(query);
  106. /* 106 */ return stmt.getResultSet();
  107. /* */ }
  108. /* */ catch (Exception e)
  109. /* */ {
  110. /* 110 */ System.err.println(e);
  111. /* */ }
  112. /* 112 */ return rs;
  113. /* */ }
  114. /* */
  115. /* */ public static int getPoints(String name)
  116. /* */ {
  117. /* 117 */ int points = 0;
  118. /* */ try
  119. /* */ {
  120. /* 120 */ ResultSet rs = Query("SELECT `points` FROM `eps_user` WHERE `name`= '" + name + "'");
  121. /* 121 */ if (rs.next()) {
  122. /* 122 */ points = rs.getInt(1);
  123. /* */ }
  124. /* 124 */ rs.close();
  125. /* */ }
  126. /* */ catch (Exception ex)
  127. /* */ {
  128. /* 128 */ ex.printStackTrace();
  129. /* */ }
  130. /* 130 */ return points;
  131. /* */ }
  132. /* */
  133. /* */ public static void addPoints(String name, int amount)
  134. /* */ {
  135. /* 135 */ if (!contains(name)) {
  136. /* 136 */ update("INSERT INTO `eps_user` (`name`, `points`) VALUES ('" + name + "', '" + (getPoints(name) + amount) + "')");
  137. /* */ } else {
  138. /* 138 */ update("UPDATE `eps_user` SET `points` = '" + (getPoints(name) + amount) + "' WHERE `name` = '" + name + "'; ");
  139. /* */ }
  140. /* */ }
  141. /* */
  142. /* */ public static boolean isConnected()
  143. /* */ {
  144. /* 144 */ return con != null;
  145. /* */ }
  146. /* */
  147. /* */ public static void createTabel()
  148. /* */ {
  149. /* 149 */ if (isConnected()) {
  150. /* */ try
  151. /* */ {
  152. /* 152 */ con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS stats (Name VARCHAR(32), UUID VARCHAR(100), Kills int, Deaths int, Points int, Wins int)");
  153. /* 153 */ con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS money (Name VARCHAR(32), UUID VARCHAR(100), Money int)");
  154. /* */ }
  155. /* */ catch (SQLException e)
  156. /* */ {
  157. /* 157 */ e.printStackTrace();
  158. /* */ }
  159. /* */ }
  160. /* */ }
  161. /* */
  162. /* */ public static void update(String qry)
  163. /* */ {
  164. /* 164 */ if (isConnected()) {
  165. /* */ try
  166. /* */ {
  167. /* 167 */ con.createStatement().executeUpdate(qry);
  168. /* */ }
  169. /* */ catch (SQLException e)
  170. /* */ {
  171. /* 171 */ e.printStackTrace();
  172. /* */ }
  173. /* */ }
  174. /* */ }
  175. /* */
  176. /* */ public static ResultSet getResult(String qry)
  177. /* */ {
  178. /* 178 */ if (isConnected()) {
  179. /* */ try
  180. /* */ {
  181. /* 181 */ return con.createStatement().executeQuery(qry);
  182. /* */ }
  183. /* */ catch (SQLException e)
  184. /* */ {
  185. /* 185 */ e.printStackTrace();
  186. /* */ }
  187. /* */ }
  188. /* 188 */ return null;
  189. /* */ }
  190. /* */ }
  191.  
  192.  
  193. /* Location: C:\Users\tatjana\Desktop\MineShine.jar!\de\mevax\mineshine\MySQL.class
  194. * Java compiler version: 7 (51.0)
  195. * JD-Core Version: 0.7.1
  196. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement