From d2035f1816419b06fff18e0c0f8e3b0e30a8f3ff Mon Sep 17 00:00:00 2001 From: "U-YUE\\Sean" Date: Wed, 20 Feb 2013 12:44:17 -0800 Subject: [PATCH] Setting mcMMO to disable itself if it errors on load. Fixes most reloading errors. --- src/main/java/com/gmail/nossr50/mcMMO.java | 103 ++++++++++++--------- 1 file changed, 61 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 97db900a6..e72a6a6d5 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -8,6 +8,7 @@ import java.util.List; import net.shatteredlands.shatt.backup.ZipLibrary; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -98,46 +99,52 @@ public class mcMMO extends JavaPlugin { */ @Override public void onEnable() { - p = this; - getLogger().setFilter(new LogFilter(this)); - entityMetadata = new FixedMetadataValue(mcMMO.p, true); - setupFilePaths(); - setupSpout(); - loadConfigFiles(); + try { + p = this; + getLogger().setFilter(new LogFilter(this)); + entityMetadata = new FixedMetadataValue(mcMMO.p, true); + setupFilePaths(); + setupSpout(); + loadConfigFiles(); - if (!Config.getInstance().getUseMySQL()) { - Users.loadUsers(); + if (!Config.getInstance().getUseMySQL()) { + Users.loadUsers(); + } + + registerEvents(); + + // Setup the leader boards + if (Config.getInstance().getUseMySQL()) { + // TODO: Why do we have to check for a connection that hasn't be made yet? + Database.checkConnected(); + Database.createStructure(); + } + else { + Leaderboard.updateLeaderboards(); + } + + for (Player player : getServer().getOnlinePlayers()) { + Users.addUser(player); // In case of reload add all users back into PlayerProfile + } + + getLogger().info("Version " + getDescription().getVersion() + " is enabled!"); + + scheduleTasks(); + registerCommands(); + + MetricsManager.setup(); + + placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager + + checkForUpdates(); + + if (Config.getInstance().getPTPCommandWorldPermissions()) { + Permissions.generateWorldTeleportPermissions(); + } } - - registerEvents(); - - // Setup the leader boards - if (Config.getInstance().getUseMySQL()) { - // TODO: Why do we have to check for a connection that hasn't be made yet? - Database.checkConnected(); - Database.createStructure(); - } - else { - Leaderboard.updateLeaderboards(); - } - - for (Player player : getServer().getOnlinePlayers()) { - Users.addUser(player); // In case of reload add all users back into PlayerProfile - } - - getLogger().info("Version " + getDescription().getVersion() + " is enabled!"); - - scheduleTasks(); - registerCommands(); - - MetricsManager.setup(); - - placeStore = ChunkManagerFactory.getChunkManager(); // Get our ChunkletManager - - checkForUpdates(); - - if (Config.getInstance().getPTPCommandWorldPermissions()) { - Permissions.generateWorldTeleportPermissions(); + catch (Throwable t) { + getLogger().severe("There was an error while enabling mcMMO! Disabling now"); + Bukkit.getPluginManager().disablePlugin(this); } } @@ -210,11 +217,15 @@ public class mcMMO extends JavaPlugin { */ @Override public void onDisable() { - Users.saveAll(); // Make sure to save player information if the server shuts down - PartyManager.saveParties(); + try { + Users.saveAll(); // Make sure to save player information if the server shuts down + PartyManager.saveParties(); + placeStore.saveAll(); // Save our metadata + placeStore.cleanUp(); // Cleanup empty metadata stores + } + catch (NullPointerException e) {} + getServer().getScheduler().cancelTasks(this); // This removes our tasks - placeStore.saveAll(); // Save our metadata - placeStore.cleanUp(); // Cleanup empty metadata stores HandlerList.unregisterAll(this); // Cancel event registrations if (Config.getInstance().getBackupsEnabled()) { @@ -225,6 +236,14 @@ public class mcMMO extends JavaPlugin { catch (IOException e) { getLogger().severe(e.toString()); } + catch (Throwable e) { + if (e instanceof NoClassDefFoundError) { + getLogger().severe("Backup class not found. Do not replace the mcMMO jar during runtime."); + } + else { + getLogger().severe(e.toString()); + } + } } getLogger().info("Was disabled."); //How informative!