diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 2769f35f6..d4bdc31e2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -18,7 +18,6 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.logger.Logger; import mineplex.core.timing.TimingManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -155,7 +154,6 @@ public class CoreClientManager extends MiniPlugin } catch(Exception exception) { - Logger.Instance.log(exception); event.disallow(Result.KICK_OTHER, "Error retrieving information from web, please retry in a minute."); System.out.println(exception.getMessage()); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java index 904a2b866..6848257d9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java @@ -5,7 +5,6 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import mineplex.core.database.DBPool; -import mineplex.core.logger.Logger; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -35,7 +34,6 @@ public class AntiHackRepository catch (Exception exception) { exception.printStackTrace(); - Logger.Instance.log(exception); } finally { @@ -78,7 +76,6 @@ public class AntiHackRepository catch (Exception exception) { exception.printStackTrace(); - Logger.Instance.log(exception); } finally { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java index 56b6b11cd..fa5f245d8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java @@ -10,7 +10,6 @@ import java.util.Iterator; import mineplex.core.common.util.NautHashMap; import mineplex.core.database.column.Column; -import mineplex.core.logger.Logger; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -64,14 +63,17 @@ public abstract class RepositoryBase implements Listener protected Connection getConnection() { - try + synchronized (_connectionLock) { - if (_connection == null) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } - catch (SQLException e) - { - e.printStackTrace(); + try + { + if (_connection == null) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + } + catch (SQLException e) + { + e.printStackTrace(); + } } return _connection; @@ -246,12 +248,6 @@ public abstract class RepositoryBase implements Listener { _failedQueue.put(databaseRunnable, runnableMessage); } - - Logger.Instance.log(errorPreMessage + runnableMessage); - } - else - { - Logger.Instance.log("Abandoning database call : " + runnableMessage); } } @@ -264,6 +260,32 @@ public abstract class RepositoryBase implements Listener processFailedQueue(); } + @EventHandler + public void validateConnection(UpdateEvent event) + { + if (event.getType() != UpdateType.MIN_01) + return; + + Bukkit.getScheduler().runTaskAsynchronously(Plugin, new Runnable() + { + public void run() + { + synchronized (_connectionLock) + { + try + { + if (_connection == null || !_connection.isValid(5)) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + }); + } + private void processFailedQueue() { synchronized (_queueLock) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java index ef37cfaaa..818c95df9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java @@ -16,7 +16,6 @@ import mineplex.core.donation.Donor; import mineplex.core.donation.repository.token.GemRewardToken; import mineplex.core.donation.repository.token.PurchaseToken; import mineplex.core.donation.repository.token.UnknownPurchaseToken; -import mineplex.core.logger.Logger; import mineplex.core.server.remotecall.AsyncJsonWebCall; import mineplex.core.server.remotecall.JsonWebCall; import mineplex.core.server.util.TransactionResponse; @@ -188,7 +187,6 @@ public class DonationRepository extends RepositoryBase { if (executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnVarChar("uuid", 100, uuid)) < 1) { - Logger.Instance.log("Account gold wasn't updated for " + name); callback.run(false); } else diff --git a/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java b/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java deleted file mode 100644 index 25108a02c..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java +++ /dev/null @@ -1,87 +0,0 @@ -package mineplex.core.logger; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; - -public class Logger -{ - public static Logger Instance; - - private static JavaPlugin _plugin; - private LoggerRepository _repository; - - public static void initialize(JavaPlugin plugin) - { - _plugin = plugin; - Instance = new Logger(plugin); - } - - public Logger(JavaPlugin plugin) - { - setupConfigValues(plugin); - - _repository = new LoggerRepository(plugin.getConfig().getString("log.connectionurl"), plugin.getConfig().getString("serverstatus.name")); - - Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() - { - @Override - public void uncaughtException(Thread t, Throwable e) - { - log(e); - e.printStackTrace(); - } - }); - } - - private void setupConfigValues(JavaPlugin plugin) - { - try - { - plugin.getConfig().addDefault("log.connectionurl", "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"); - plugin.getConfig().set("log.connectionurl", plugin.getConfig().getString("log.connectionurl")); - plugin.saveConfig(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - public void log(final String message) - { - System.out.println(message); - - Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable() - { - public void run() - { - _repository.saveLog(message); - } - }); - } - - public void log(Throwable exception) - { - final List messages = new ArrayList(); - - messages.add("[Exception Start]" + exception.getMessage()); - - for (StackTraceElement element : exception.getStackTrace()) - { - messages.add(element.toString()); - } - - messages.add("[Exception End]"); - - Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable() - { - public void run() - { - _repository.saveLog(messages.toArray(new String[0])); - } - }); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/logger/LoggerRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/logger/LoggerRepository.java deleted file mode 100644 index 0ba4d99ce..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/logger/LoggerRepository.java +++ /dev/null @@ -1,106 +0,0 @@ -package mineplex.core.logger; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; - -public class LoggerRepository -{ - private static Object _connectionLock = new Object(); - - private String _connectionString; - private String _userName = "root"; - private String _password = "tAbechAk3wR7tuTh"; - - private static String CREATE_LOG_TABLE = "CREATE TABLE IF NOT EXISTS errorLog (id INT NOT NULL AUTO_INCREMENT, server VARCHAR(256), message VARCHAR(256), date LONG, PRIMARY KEY (id));"; - private static String INSERT_LOG = "INSERT INTO errorLog (server, message, date) VALUES (?, ?, now());"; - - private Connection _connection = null; - private String _serverName; - - public LoggerRepository(String connectionUrl, String serverName) - { - _connectionString = connectionUrl; - _serverName = serverName; - - initialize(); - } - - public void initialize() - { - PreparedStatement preparedStatement = null; - - try - { - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - // Create table - preparedStatement = _connection.prepareStatement(CREATE_LOG_TABLE); - preparedStatement.execute(); - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - } - - public void saveLog(String...message) - { - PreparedStatement preparedStatement = null; - - try - { - synchronized (_connectionLock) - { - if (_connection.isClosed()) - { - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } - - preparedStatement = _connection.prepareStatement(INSERT_LOG); - - for (String msg : message) - { - preparedStatement.setString(1, _serverName); - preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length()))); - preparedStatement.addBatch(); - } - - preparedStatement.executeBatch(); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 9aa9503ce..922081f29 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -9,7 +9,6 @@ import mineplex.core.explosion.Explosion; import mineplex.core.friend.FriendManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.logger.Logger; import mineplex.core.memory.MemoryFix; import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; @@ -48,7 +47,7 @@ public class Clans extends JavaPlugin String webServerAddress = getConfig().getString(WEB_CONFIG); - Logger.initialize(this); + //Logger.initialize(this); //Static Modules CommandCenter.Initialize(this); @@ -69,7 +68,7 @@ public class Clans extends JavaPlugin new Spawn(this, serverStatusManager.getCurrentServerName()); Teleport teleport = new Teleport(this); Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); - new FileUpdater(this, portal); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); Punish punish = new Punish(this, webServerAddress, _clientManager); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index bcd897e22..68f39ff56 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -18,7 +18,6 @@ import mineplex.core.energy.Energy; import mineplex.core.friend.FriendManager; import mineplex.core.hologram.HologramManager; import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.logger.Logger; import mineplex.core.memory.MemoryFix; import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; @@ -70,7 +69,7 @@ public class Hub extends JavaPlugin implements IRelation String webServerAddress = getConfig().getString(WEB_CONFIG); - Logger.initialize(this); + //Logger.initialize(this); //Static Modules CommandCenter.Initialize(this); @@ -110,7 +109,7 @@ public class Hub extends JavaPlugin implements IRelation new ServerManager(this, clientManager, donationManager, portal, partyManager, serverStatusManager, hubManager, new StackerManager(hubManager), queueManager); new Chat(this, clientManager, preferenceManager, serverStatusManager.getCurrentServerName()); new MemoryFix(this); - new FileUpdater(this, portal); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); new CustomTagFix(this, packetHandler); //new Replay(this, packetHandler); new PersonalServerManager(this, clientManager); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/MapManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/MapManager.java index 264f415ef..251b856d4 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/MapManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/MapManager.java @@ -8,7 +8,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerJoinEvent; import mineplex.core.MiniPlugin; -import mineplex.core.logger.Logger; import mineplex.core.map.Map; import mineplex.core.common.Rank; import mineplex.core.common.util.UtilGear; @@ -36,7 +35,6 @@ public class MapManager extends MiniPlugin } catch (Exception ex) { - Logger.Instance.log(ex); System.out.println("[MapManager] Player Join exception"); throw ex; } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/party/PartyManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/party/PartyManager.java index 2b4e0ec0d..17d25a8fb 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/party/PartyManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/party/PartyManager.java @@ -12,7 +12,6 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; -import mineplex.core.logger.Logger; import mineplex.core.preferences.PreferencesManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -70,7 +69,6 @@ public class PartyManager extends MiniPlugin } catch (Exception ex) { - Logger.Instance.log(ex); throw ex; } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index b773cf9a7..555f9e63e 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -42,7 +42,6 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.donation.DonationManager; import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.logger.Logger; import mineplex.core.portal.Portal; import mineplex.core.recharge.Recharge; import mineplex.core.shop.ShopBase; @@ -202,7 +201,6 @@ public class ServerManager extends MiniPlugin } catch (Exception exception) { - Logger.Instance.log(exception); exception.printStackTrace(); } @@ -647,7 +645,6 @@ public class ServerManager extends MiniPlugin } catch (Exception e) { - Logger.Instance.log(e); System.out.println("ServerManager - Error parsing servers file : " + e.getMessage()); } finally diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java index 01a9aaeb0..d778d7989 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java @@ -39,7 +39,9 @@ public class ServerSorter implements Comparator if (Integer.parseInt(a.Name.split("-")[1]) < Integer.parseInt(b.Name.split("-")[1])) return -1; + else if (Integer.parseInt(a.Name.split("-")[1]) > Integer.parseInt(b.Name.split("-")[1])) + return 1; - return 1; + return 0; } } \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java index 35b8da5cf..ccf19883b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -15,7 +15,6 @@ import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilTime; import mineplex.core.donation.DonationManager; -import mineplex.core.logger.Logger; import mineplex.core.shop.item.IButton; import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.page.ShopPageBase; @@ -64,7 +63,6 @@ public class ServerNpcPage extends ShopPageBase im } catch (Exception exception) { - Logger.Instance.log(exception); exception.printStackTrace(); } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java index 7270b881e..aeff03931 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java @@ -59,7 +59,7 @@ public class StaffServer extends JavaPlugin Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); new Chat(this, clientManager, preferenceManager, serverStatusManager.getCurrentServerName()); new MemoryFix(this); - new FileUpdater(this, portal); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); new CustomerSupport(this, clientManager, donationManager, new SalesPackageManager(this, clientManager, donationManager, new InventoryManager(this, clientManager), new StatsManager(this, clientManager))); //new Password(this, serverStatusManager.getCurrentServerName()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 1f8e8e6e2..55d5ffb02 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -23,7 +23,6 @@ import mineplex.core.gadget.GadgetManager; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.logger.Logger; import mineplex.core.memory.MemoryFix; import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; @@ -72,7 +71,7 @@ public class Arcade extends JavaPlugin String webServerAddress = getConfig().getString(WEB_CONFIG); - Logger.initialize(this); + //Logger.initialize(this); //Static Modules CommandCenter.Initialize(this); @@ -94,7 +93,7 @@ public class Arcade extends JavaPlugin new Spawn(this, serverStatusManager.getCurrentServerName()); Teleport teleport = new Teleport(this); Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); - new FileUpdater(this, portal); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); PacketHandler packetHandler = new PacketHandler(this); DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);