Gracefully handle botched plugin starts

This commit is contained in:
KHobbits 2013-08-13 23:37:33 +01:00
parent 66eb9202ce
commit ff41588c3b
2 changed files with 132 additions and 103 deletions

View File

@ -131,6 +131,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
@Override @Override
public void onEnable() public void onEnable()
{
try
{ {
execTimer = new ExecuteTimer(); execTimer = new ExecuteTimer();
execTimer.start(); execTimer.start();
@ -206,20 +208,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
{ {
LOGGER.log(Level.SEVERE, _("essentialsHelp1")); LOGGER.log(Level.SEVERE, _("essentialsHelp1"));
} }
LOGGER.log(Level.SEVERE, exception.toString()); handleCrash(exception);
pm.registerEvents(new Listener()
{
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(final PlayerJoinEvent event)
{
event.getPlayer().sendMessage("Essentials failed to load, read the log file.");
}
}, this);
for (Player player : getServer().getOnlinePlayers())
{
player.sendMessage("Essentials failed to load, read the log file.");
}
this.setEnabled(false);
return; return;
} }
backup = new Backup(this); backup = new Backup(this);
@ -249,6 +238,16 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
LOGGER.log(Level.INFO, "Essentials load " + timeroutput); LOGGER.log(Level.INFO, "Essentials load " + timeroutput);
} }
} }
catch (Exception ex)
{
handleCrash(ex);
}
catch (Error ex)
{
handleCrash(ex);
throw ex;
}
}
@Override @Override
public void saveConfig() public void saveConfig()
@ -308,8 +307,14 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
} }
} }
cleanupOpenInventories(); cleanupOpenInventories();
if (i18n != null)
{
i18n.onDisable(); i18n.onDisable();
}
if (backup != null)
{
backup.stopTask(); backup.stopTask();
}
Economy.setEss(null); Economy.setEss(null);
Trade.closeLog(); Trade.closeLog();
} }
@ -624,6 +629,25 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
return user; return user;
} }
private void handleCrash(Throwable exception)
{
final PluginManager pm = getServer().getPluginManager();
LOGGER.log(Level.SEVERE, exception.toString());
pm.registerEvents(new Listener()
{
@EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(final PlayerJoinEvent event)
{
event.getPlayer().sendMessage("Essentials failed to load, read the log file.");
}
}, this);
for (Player player : getServer().getOnlinePlayers())
{
player.sendMessage("Essentials failed to load, read the log file.");
}
this.setEnabled(false);
}
@Override @Override
public World getWorld(final String name) public World getWorld(final String name)
{ {

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import com.earth2me.essentials.perm.PermissionsHandler;
import net.ess3.api.IEssentials; import net.ess3.api.IEssentials;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -40,7 +41,11 @@ public class EssentialsPluginListener implements Listener, IConf
{ {
ess.getSettings().setEssentialsChatActive(false); ess.getSettings().setEssentialsChatActive(false);
} }
ess.getPermissionsHandler().checkPermissions(); PermissionsHandler permHandler = ess.getPermissionsHandler();
if (permHandler != null)
{
permHandler.checkPermissions();
}
ess.getAlternativeCommandsHandler().removePlugin(event.getPlugin()); ess.getAlternativeCommandsHandler().removePlugin(event.getPlugin());
// Check to see if the plugin thats being disabled is the one we are using // Check to see if the plugin thats being disabled is the one we are using
if (ess.getPaymentMethod() != null && ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().checkDisabled(event.getPlugin())) if (ess.getPaymentMethod() != null && ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().checkDisabled(event.getPlugin()))