Advertisement
Guest User

Untitled

a guest
Dec 21st, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. package com.gamesmadeinpola.gmipbungee;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.util.concurrent.TimeUnit;
  9. import net.md_5.bungee.api.ProxyServer;
  10. import net.md_5.bungee.api.ServerPing;
  11. import net.md_5.bungee.api.event.ProxyPingEvent;
  12. import net.md_5.bungee.api.plugin.Listener;
  13. import net.md_5.bungee.api.plugin.PluginManager;
  14. import net.md_5.bungee.api.scheduler.TaskScheduler;
  15. import net.md_5.bungee.config.Configuration;
  16. import net.md_5.bungee.event.EventHandler;
  17.  
  18. public class MOTD
  19. implements Listener, Runnable
  20. {
  21. String motd = "§f§l§k|| §2§lGames§1§lMade§2§lIn§1§lPola§7§l.com §6§lNetwork §4§l4§e§l.§4§l3§f§l§k|| §7www.gamesmadeinpola.com §b§l@tatinYT";
  22. Connection connection = null;
  23. String connectionString = "jdbc:mysql://" + Core.config.getString("MOTD.Host") + ":3306/" + Core.config.getString("MOTD.Db") + "?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
  24. String userName = Core.config.getString("MOTD.User");
  25. String password = Core.config.getString("MOTD.Password");
  26. String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS MOTD (id INT NOT NULL AUTO_INCREMENT, motd VARCHAR(256), PRIMARY KEY (id));";
  27.  
  28. MOTD(Core plugin)
  29. {
  30. PreparedStatement preparedStatement = null;
  31. try
  32. {
  33. if ((this.connection == null) || (this.connection.isClosed())) {
  34. this.connection = DriverManager.getConnection(this.connectionString, this.userName, this.password);
  35. }
  36. preparedStatement = this.connection.prepareStatement(this.CREATE_TABLE);
  37. preparedStatement.execute();
  38. if (preparedStatement != null) {
  39. try
  40. {
  41. preparedStatement.close();
  42. }
  43. catch (SQLException e)
  44. {
  45. e.printStackTrace();
  46. }
  47. }
  48. plugin.getProxy().getPluginManager().registerListener(plugin, this);
  49. if (preparedStatement != null) {
  50. try
  51. {
  52. preparedStatement.close();
  53. }
  54. catch (SQLException e)
  55. {
  56. e.printStackTrace();
  57. }
  58. }
  59. plugin.getProxy().getScheduler().schedule(plugin, this, 0L, 5L, TimeUnit.SECONDS);
  60. }
  61. catch (Exception exception)
  62. {
  63. exception.printStackTrace();
  64. if (preparedStatement != null) {
  65. try
  66. {
  67. preparedStatement.close();
  68. }
  69. catch (SQLException e)
  70. {
  71. e.printStackTrace();
  72. }
  73. }
  74. }
  75. finally
  76. {
  77. if (preparedStatement != null) {
  78. try
  79. {
  80. preparedStatement.close();
  81. }
  82. catch (SQLException e)
  83. {
  84. e.printStackTrace();
  85. }
  86. }
  87. }
  88. }
  89.  
  90. @EventHandler
  91. public void ServerPing(ProxyPingEvent event)
  92. {
  93. ServerPing serverPing = event.getResponse();
  94. serverPing.setDescription(this.motd.replaceAll("%left%", Countdown.left));
  95. }
  96.  
  97. public void run()
  98. {
  99. this.motd = update();
  100. }
  101.  
  102. public String update()
  103. {
  104. String motd = "§f§l§k|| §2§lGames§1§lMade§2§lIn§1§lPola§7§l.com §6§lNetwork §4§l4§e§l.§4§l3§f§l§k|| §7www.gamesmadeinpola.com §b§l@tatinYT";
  105. ResultSet resultSet = null;
  106. PreparedStatement preparedStatement = null;
  107. try
  108. {
  109. if ((this.connection == null) || (this.connection.isClosed())) {
  110. this.connection = DriverManager.getConnection(this.connectionString, this.userName, this.password);
  111. }
  112. preparedStatement = this.connection.prepareStatement("SELECT motd FROM MOTD;");
  113. resultSet = preparedStatement.executeQuery();
  114. if (resultSet.next()) {
  115. return resultSet.getString(1).replaceAll("&", "§");
  116. }
  117. if (preparedStatement != null) {
  118. try
  119. {
  120. preparedStatement.close();
  121. }
  122. catch (SQLException e)
  123. {
  124. e.printStackTrace();
  125. }
  126. }
  127. if (resultSet != null) {
  128. try
  129. {
  130. resultSet.close();
  131. }
  132. catch (SQLException e)
  133. {
  134. e.printStackTrace();
  135. }
  136. }
  137. if (preparedStatement == null) {
  138. preparedStatement = this.connection.prepareStatement("SELECT motd FROM MOTD;");
  139. }
  140. if (preparedStatement != null) {
  141. try
  142. {
  143. preparedStatement.close();
  144. }
  145. catch (SQLException e)
  146. {
  147. e.printStackTrace();
  148. }
  149. }
  150. if (resultSet != null) {
  151. try
  152. {
  153. resultSet.close();
  154. }
  155. catch (SQLException e)
  156. {
  157. e.printStackTrace();
  158. }
  159. }
  160. try
  161. {
  162. preparedStatement.close();
  163. }
  164. catch (SQLException e)
  165. {
  166. e.printStackTrace();
  167. }
  168. }
  169. catch (Exception exception)
  170. {
  171. exception.printStackTrace();
  172. }
  173. finally
  174. {
  175. if (preparedStatement != null) {
  176. try
  177. {
  178. preparedStatement.close();
  179. }
  180. catch (SQLException e)
  181. {
  182. e.printStackTrace();
  183. }
  184. }
  185. if (resultSet != null) {
  186. try
  187. {
  188. resultSet.close();
  189. }
  190. catch (SQLException e)
  191. {
  192. e.printStackTrace();
  193. }
  194. }
  195. }
  196. if (resultSet != null) {
  197. try
  198. {
  199. resultSet.close();
  200. }
  201. catch (SQLException e)
  202. {
  203. e.printStackTrace();
  204. }
  205. }
  206. return motd;
  207. }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement