Setting mcMMO to disable itself if it errors on load. Fixes most reloading errors.

This commit is contained in:
U-YUE\Sean 2013-02-20 12:44:17 -08:00 committed by Glitchfinder
parent fd821139bd
commit d2035f1816

View File

@ -8,6 +8,7 @@ import java.util.List;
import net.shatteredlands.shatt.backup.ZipLibrary; import net.shatteredlands.shatt.backup.ZipLibrary;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -98,6 +99,7 @@ public class mcMMO extends JavaPlugin {
*/ */
@Override @Override
public void onEnable() { public void onEnable() {
try {
p = this; p = this;
getLogger().setFilter(new LogFilter(this)); getLogger().setFilter(new LogFilter(this));
entityMetadata = new FixedMetadataValue(mcMMO.p, true); entityMetadata = new FixedMetadataValue(mcMMO.p, true);
@ -140,6 +142,11 @@ public class mcMMO extends JavaPlugin {
Permissions.generateWorldTeleportPermissions(); Permissions.generateWorldTeleportPermissions();
} }
} }
catch (Throwable t) {
getLogger().severe("There was an error while enabling mcMMO! Disabling now");
Bukkit.getPluginManager().disablePlugin(this);
}
}
/** /**
* Setup the various storage file paths * Setup the various storage file paths
@ -210,11 +217,15 @@ public class mcMMO extends JavaPlugin {
*/ */
@Override @Override
public void onDisable() { public void onDisable() {
try {
Users.saveAll(); // Make sure to save player information if the server shuts down Users.saveAll(); // Make sure to save player information if the server shuts down
PartyManager.saveParties(); PartyManager.saveParties();
getServer().getScheduler().cancelTasks(this); // This removes our tasks
placeStore.saveAll(); // Save our metadata placeStore.saveAll(); // Save our metadata
placeStore.cleanUp(); // Cleanup empty metadata stores placeStore.cleanUp(); // Cleanup empty metadata stores
}
catch (NullPointerException e) {}
getServer().getScheduler().cancelTasks(this); // This removes our tasks
HandlerList.unregisterAll(this); // Cancel event registrations HandlerList.unregisterAll(this); // Cancel event registrations
if (Config.getInstance().getBackupsEnabled()) { if (Config.getInstance().getBackupsEnabled()) {
@ -225,6 +236,14 @@ public class mcMMO extends JavaPlugin {
catch (IOException e) { catch (IOException e) {
getLogger().severe(e.toString()); 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! getLogger().info("Was disabled."); //How informative!