Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gamesmadeinpola.gmipbungee;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.concurrent.TimeUnit;
- import net.md_5.bungee.api.ProxyServer;
- import net.md_5.bungee.api.ServerPing;
- import net.md_5.bungee.api.event.ProxyPingEvent;
- import net.md_5.bungee.api.plugin.Listener;
- import net.md_5.bungee.api.plugin.PluginManager;
- import net.md_5.bungee.api.scheduler.TaskScheduler;
- import net.md_5.bungee.config.Configuration;
- import net.md_5.bungee.event.EventHandler;
- public class MOTD
- implements Listener, Runnable
- {
- 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";
- Connection connection = null;
- String connectionString = "jdbc:mysql://" + Core.config.getString("MOTD.Host") + ":3306/" + Core.config.getString("MOTD.Db") + "?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
- String userName = Core.config.getString("MOTD.User");
- String password = Core.config.getString("MOTD.Password");
- String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS MOTD (id INT NOT NULL AUTO_INCREMENT, motd VARCHAR(256), PRIMARY KEY (id));";
- MOTD(Core plugin)
- {
- PreparedStatement preparedStatement = null;
- try
- {
- if ((this.connection == null) || (this.connection.isClosed())) {
- this.connection = DriverManager.getConnection(this.connectionString, this.userName, this.password);
- }
- preparedStatement = this.connection.prepareStatement(this.CREATE_TABLE);
- preparedStatement.execute();
- if (preparedStatement != null) {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- plugin.getProxy().getPluginManager().registerListener(plugin, this);
- if (preparedStatement != null) {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- plugin.getProxy().getScheduler().schedule(plugin, this, 0L, 5L, TimeUnit.SECONDS);
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- if (preparedStatement != null) {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- finally
- {
- if (preparedStatement != null) {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
- @EventHandler
- public void ServerPing(ProxyPingEvent event)
- {
- ServerPing serverPing = event.getResponse();
- serverPing.setDescription(this.motd.replaceAll("%left%", Countdown.left));
- }
- public void run()
- {
- this.motd = update();
- }
- public String update()
- {
- 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";
- ResultSet resultSet = null;
- PreparedStatement preparedStatement = null;
- try
- {
- if ((this.connection == null) || (this.connection.isClosed())) {
- this.connection = DriverManager.getConnection(this.connectionString, this.userName, this.password);
- }
- preparedStatement = this.connection.prepareStatement("SELECT motd FROM MOTD;");
- resultSet = preparedStatement.executeQuery();
- if (resultSet.next()) {
- return resultSet.getString(1).replaceAll("&", "§");
- }
- if (preparedStatement != null) {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- if (resultSet != null) {
- try
- {
- resultSet.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- if (preparedStatement == null) {
- preparedStatement = this.connection.prepareStatement("SELECT motd FROM MOTD;");
- }
- if (preparedStatement != null) {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- if (resultSet != null) {
- try
- {
- resultSet.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- finally
- {
- if (preparedStatement != null) {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- if (resultSet != null) {
- try
- {
- resultSet.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- if (resultSet != null) {
- try
- {
- resultSet.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- return motd;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement