From 5e2123c91e44b9ea0a2aa61ca8d889e506274875 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 30 Nov 2011 20:48:42 +0100 Subject: [PATCH] If Essentials core fails to read one of the configs now, it will disable itself. If other modules detect that Essentials is not enabled, they will be disabled too. EssentialsProtect will go into emergency mode, canceling all events that could hurt your world. Fix the file and either restart or reload the server. --- .../com/earth2me/essentials/Essentials.java | 98 +++++++++++++------ .../earth2me/essentials/EssentialsConf.java | 3 +- Essentials/src/messages.properties | 3 + Essentials/src/messages_da.properties | 3 + Essentials/src/messages_de.properties | 3 + Essentials/src/messages_en.properties | 3 + Essentials/src/messages_es.properties | 3 + Essentials/src/messages_fr.properties | 3 + Essentials/src/messages_nl.properties | 3 + .../essentials/chat/EssentialsChat.java | 19 +++- .../essentials/geoip/EssentialsGeoIP.java | 10 +- .../protect/EmergencyBlockListener.java | 36 +++++++ .../protect/EmergencyEntityListener.java | 22 +++++ .../protect/EmergencyPlayerListener.java | 16 +++ .../essentials/protect/EssentialsProtect.java | 31 +++++- EssentialsProtect/src/plugin.yml | 2 +- .../essentials/spawn/EssentialsSpawn.java | 13 ++- .../essentials/xmpp/EssentialsXMPP.java | 18 ++-- 18 files changed, 232 insertions(+), 57 deletions(-) create mode 100644 EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyBlockListener.java create mode 100644 EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyEntityListener.java create mode 100644 EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyPlayerListener.java diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 629b6bbba..e5cd3ea4b 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -47,17 +47,21 @@ import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerListener; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.error.YAMLException; public class Essentials extends JavaPlugin implements IEssentials { - public static final int BUKKIT_VERSION = 1522; + public static final int BUKKIT_VERSION = 1526; private static final Logger LOGGER = Logger.getLogger("Minecraft"); private transient ISettings settings; private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); @@ -112,32 +116,6 @@ public class Essentials extends JavaPlugin implements IEssentials i18n = new I18n(this); i18n.onEnable(); execTimer.mark("I18n1"); - final EssentialsUpgrade upgrade = new EssentialsUpgrade(this); - upgrade.beforeSettings(); - execTimer.mark("Upgrade"); - confList = new ArrayList(); - settings = new Settings(this); - confList.add(settings); - execTimer.mark("Settings"); - upgrade.afterSettings(); - execTimer.mark("Upgrade2"); - i18n.updateLocale(settings.getLocale()); - userMap = new UserMap(this); - confList.add(userMap); - execTimer.mark("Init(Usermap)"); - spawn = new Spawn(getServer(), this.getDataFolder()); - confList.add(spawn); - warps = new Warps(getServer(), this.getDataFolder()); - confList.add(warps); - execTimer.mark("Init(Spawn/Warp)"); - worth = new Worth(this.getDataFolder()); - confList.add(worth); - itemDb = new ItemDb(this); - confList.add(itemDb); - execTimer.mark("Init(Worth/ItemDB)"); - reload(); - backup = new Backup(this); - final PluginManager pm = getServer().getPluginManager(); for (Plugin plugin : pm.getPlugins()) { @@ -153,7 +131,10 @@ public class Essentials extends JavaPlugin implements IEssentials final int versionNumber = Integer.parseInt(versionMatch.group(4)); if (versionNumber < BUKKIT_VERSION) { - LOGGER.log(Level.WARNING, _("notRecommendedBukkit")); + LOGGER.log(Level.SEVERE, _("notRecommendedBukkit")); + LOGGER.log(Level.SEVERE, _("requiredBukkit", Integer.toString(BUKKIT_VERSION))); + this.setEnabled(false); + return; } } else @@ -162,7 +143,62 @@ public class Essentials extends JavaPlugin implements IEssentials LOGGER.log(Level.INFO, getServer().getVersion()); LOGGER.log(Level.INFO, getServer().getBukkitVersion()); } + execTimer.mark("BukkitCheck"); + try + { + final EssentialsUpgrade upgrade = new EssentialsUpgrade(this); + upgrade.beforeSettings(); + execTimer.mark("Upgrade"); + confList = new ArrayList(); + settings = new Settings(this); + confList.add(settings); + execTimer.mark("Settings"); + upgrade.afterSettings(); + execTimer.mark("Upgrade2"); + i18n.updateLocale(settings.getLocale()); + userMap = new UserMap(this); + confList.add(userMap); + execTimer.mark("Init(Usermap)"); + spawn = new Spawn(getServer(), this.getDataFolder()); + confList.add(spawn); + warps = new Warps(getServer(), this.getDataFolder()); + confList.add(warps); + execTimer.mark("Init(Spawn/Warp)"); + worth = new Worth(this.getDataFolder()); + confList.add(worth); + itemDb = new ItemDb(this); + confList.add(itemDb); + execTimer.mark("Init(Worth/ItemDB)"); + reload(); + } + catch (YAMLException exception) + { + if (pm.getPlugin("EssentialsUpdate") != null) + { + LOGGER.log(Level.SEVERE, _("essentialsHelp2")); + } + else + { + LOGGER.log(Level.SEVERE, _("essentialsHelp1")); + } + LOGGER.log(Level.SEVERE, exception.toString()); + pm.registerEvent(Type.PLAYER_JOIN, new PlayerListener() { + @Override + public void onPlayerJoin(PlayerJoinEvent event) + { + event.getPlayer().sendMessage("Essentials failed to load, read the log file."); + } + + }, Priority.Low, this); + for (Player player : getServer().getOnlinePlayers()) + { + player.sendMessage("Essentials failed to load, read the log file."); + } + this.setEnabled(false); + return; + } + backup = new Backup(this); permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions()); alternativeCommandsHandler = new AlternativeCommandsHandler(this); final EssentialsPluginListener serverListener = new EssentialsPluginListener(this); @@ -275,7 +311,7 @@ public class Essentials extends JavaPlugin implements IEssentials if (pc != null) { alternativeCommandsHandler.executed(commandLabel, pc.getLabel()); - LOGGER.log(Level.FINE,"Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel()); + LOGGER.log(Level.FINE, "Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel()); return pc.execute(sender, commandLabel, args); } } @@ -444,7 +480,9 @@ public class Essentials extends JavaPlugin implements IEssentials if (user == null) { user = new User(base, this); - } else { + } + else + { user.update(base); } return user; diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 8b8b79279..35252532f 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -2,7 +2,6 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; import java.io.*; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -112,7 +111,7 @@ public class EssentialsConf extends Configuration } catch (RuntimeException e) { - LOGGER.log(Level.INFO, "File: " + configFile.toString()); + LOGGER.log(Level.SEVERE, "File broken: " + configFile.toString()); throw e; } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 387e07375..22881e5a1 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -75,6 +75,8 @@ enchantmentRemoved = \u00a77The enchantment {0} has been removed from your item enchantments = \u00a77Enchantments: {0} errorCallingCommand=Error calling command /{0} errorWithMessage=\u00a7cError: {0} +essentialsHelp1=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, go to http://tiny.cc/EssentialsChat +essentialsHelp2=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, either type /essentialshelp in game or go to http://tiny.cc/EssentialsChat essentialsReload=\u00a77Essentials Reloaded {0} extinguish=\u00a77You extinguished yourself. extinguishOthers=\u00a77You extinguished {0}. @@ -280,6 +282,7 @@ requestAcceptedFrom=\u00a77{0} accepted your teleport request. requestDenied=\u00a77Teleport request denied. requestDeniedFrom=\u00a77{0} denied your teleport request. requestSent=\u00a77Request sent to {0}\u00a77. +requiredBukkit=You need atleast build {0} of CraftBukkit, download it from http://ci.bukkit.org. returnPlayerToJailError=Error occurred when trying to return player to jail. second=second seconds=seconds diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index 0178410ec..c7cccbb00 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -75,6 +75,8 @@ enchantmentRemoved = \u00a77The enchantment {0} has been removed from your item enchantments = \u00a77Enchantments: {0} errorCallingCommand=Fejl ved opkald af kommando /{0} errorWithMessage=\u00a7cFejl: {0} +essentialsHelp1=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, go to http://tiny.cc/EssentialsChat +essentialsHelp2=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, either type /essentialshelp in game or go to http://tiny.cc/EssentialsChat essentialsReload=\u00a77Essentials Genindl\u00e6st {0} extinguish=\u00a77Du slukkede dig selv. extinguishOthers=\u00a77Du slukkede {0}. @@ -280,6 +282,7 @@ requestAcceptedFrom=\u00a77{0} accepted your teleport request. requestDenied=\u00a77Teleporterings anmodning n\u00e6gtet. requestDeniedFrom=\u00a77{0} denied your teleport request. requestSent=\u00a77Anmodning sendt til {0}\u00a77. +requiredBukkit=You need atleast build {0} of CraftBukkit, download it from http://ci.bukkit.org. returnPlayerToJailError=En fejl opstod ved fors\u00f8g p\u00e5 at returnere spiller til f\u00e6ngsel. second=sekunde seconds=sekunder diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 783411356..01a328774 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -75,6 +75,8 @@ enchantmentRemoved = \u00a77The enchantment {0} has been removed from your item enchantments = \u00a77Enchantments: {0} errorCallingCommand=Fehler beim Aufrufen des Befehls /{0} errorWithMessage=\u00a7cFehler: {0} +essentialsHelp1=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, go to http://tiny.cc/EssentialsChat +essentialsHelp2=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, either type /essentialshelp in game or go to http://tiny.cc/EssentialsChat essentialsReload=\u00a77Essentials neu geladen {0} extinguish=\u00a77Du hast dich selbst gel\u00f6scht. extinguishOthers=\u00a77Du hast {0} gel\u00f6scht. @@ -280,6 +282,7 @@ requestAcceptedFrom=\u00a77{0} hat deine Teleportierungsanfrage angenommen. requestDenied=\u00a77Teleportierungsanfrage verweigert. requestDeniedFrom=\u00a77{0} hat deine Teleportierungsanfrage abgelehnt. requestSent=\u00a77Anfrage gesendet an {0}\u00a77. +requiredBukkit=You need atleast build {0} of CraftBukkit, download it from http://ci.bukkit.org. returnPlayerToJailError=Fehler beim Versuch, den Spieler ins Gef\u00e4ngnis zu teleportieren. second=Sekunde seconds=Sekunden diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index a90364ca6..4045b70e5 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -75,6 +75,8 @@ enchantmentRemoved = \u00a77The enchantment {0} has been removed from your item enchantments = \u00a77Enchantments: {0} errorCallingCommand=Error calling command /{0} errorWithMessage=\u00a7cError: {0} +essentialsHelp1=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, go to http://tiny.cc/EssentialsChat +essentialsHelp2=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, either type /essentialshelp in game or go to http://tiny.cc/EssentialsChat essentialsReload=\u00a77Essentials Reloaded {0} extinguish=\u00a77You extinguished yourself. extinguishOthers=\u00a77You extinguished {0}. @@ -280,6 +282,7 @@ requestAcceptedFrom=\u00a77{0} accepted your teleport request. requestDenied=\u00a77Teleport request denied. requestDeniedFrom=\u00a77{0} denied your teleport request requestSent=\u00a77Request sent to {0}\u00a77. +requiredBukkit=You need atleast build {0} of CraftBukkit, download it from http://ci.bukkit.org. returnPlayerToJailError=Error occurred when trying to return player to jail. second=second seconds=seconds diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index e1e78aa1d..8fdb84408 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -75,6 +75,8 @@ enchantmentRemoved = \u00a77The enchantment {0} has been removed from your item enchantments = \u00a77Enchantments: {0} errorCallingCommand=Error al ejecutar el comando /{0} errorWithMessage=\u00a7cError: {0} +essentialsHelp1=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, go to http://tiny.cc/EssentialsChat +essentialsHelp2=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, either type /essentialshelp in game or go to http://tiny.cc/EssentialsChat essentialsReload=\u00a77Essentials Recargado {0} extinguish=\u00a77Te has suicidado. extinguishOthers=\u00a77Has matado a {0}. @@ -280,6 +282,7 @@ requestAcceptedFrom=\u00a77{0} acepto tu peticion de teletransporte. requestDenied=\u00a77Peticion de teletransporte denegada. requestDeniedFrom=\u00a77{0} ha denegado tu peticion de teletransporte. requestSent=\u00a77Peticion enviada a {0}\u00a77. +requiredBukkit=You need atleast build {0} of CraftBukkit, download it from http://ci.bukkit.org. returnPlayerToJailError=Error al intentar quitar al jugador de la carcel. second=segundo seconds=segundos diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 22a093ec5..28b0edc1c 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -75,6 +75,8 @@ enchantmentRemoved = \u00a77The enchantment {0} has been removed from your item enchantments = \u00a77Enchantments : {0} errorCallingCommand=Erreur en appelant la commande /{0} errorWithMessage=\u00a7cErreur : {0} +essentialsHelp1=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, go to http://tiny.cc/EssentialsChat +essentialsHelp2=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, either type /essentialshelp in game or go to http://tiny.cc/EssentialsChat essentialsReload=\u00a77Essentials Recharg\u00e9 {0} extinguish=\u00a77Vous cessez de br\u00fbler. extinguishOthers=\u00a77Vous avez \u00e9teint la combustion de {0}. @@ -280,6 +282,7 @@ requestAcceptedFrom=\u00a77{0} a accept\u00e9 votre demande de t\u00e9l\u00e9por requestDenied=\u00a77Demande de t\u00e9l\u00e9portation refus\u00e9e. requestDeniedFrom=\u00a77{0} a refus\u00e9 votre demande de t\u00e9l\u00e9portation. requestSent=\u00a77Requ\u00eate envoy\u00e9e \u00e0 {0}\u00a77. +requiredBukkit=You need atleast build {0} of CraftBukkit, download it from http://ci.bukkit.org. returnPlayerToJailError=Erreur survenue lors de la tentative d''emprisonner de nouveau un joueur. second=seconde seconds=secondes diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index efcdf3716..0f083e0fe 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -75,6 +75,8 @@ enchantmentRemoved = \u00a77The enchantment {0} has been removed from your item enchantments = \u00a77Enchantments: {0} errorCallingCommand=Fout bij het aanroepen van de opdracht /{0} errorWithMessage=\u00a7cFout: {0} +essentialsHelp1=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, go to http://tiny.cc/EssentialsChat +essentialsHelp2=The file is broken and Essentials can't open it. Essentials is now disabled. If you can't fix the file yourself, either type /essentialshelp in game or go to http://tiny.cc/EssentialsChat essentialsReload=\u00a77Essentials is herladen {0} extinguish=\u00a77Je hebt jezelf geblust. extinguishOthers=\u00a77Je hebt {0} geblust. @@ -280,6 +282,7 @@ requestAcceptedFrom=\u00a77{0} accepted your teleport request. requestDenied=\u00a77Teleporteer aanvraag geweigerd. requestDeniedFrom=\u00a77{0} denied your teleport request. requestSent=\u00a77Aanvraag verstuurd naar {0}\u00a77. +requiredBukkit=You need atleast build {0} of CraftBukkit, download it from http://ci.bukkit.org. returnPlayerToJailError=Fout opgetreden bij terugzetten van speler in gevangenis. second=seconde seconds=seconde diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java index f547f0da0..6600ff91d 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java @@ -21,6 +21,15 @@ public class EssentialsChat extends JavaPlugin { final PluginManager pluginManager = getServer().getPluginManager(); final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials"); + if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) + { + LOGGER.log(Level.WARNING, _("versionMismatchAll")); + } + if (!ess.isEnabled()) + { + this.setEnabled(false); + return; + } chatListener = new HashMap(); @@ -30,16 +39,16 @@ public class EssentialsChat extends JavaPlugin pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerLowest, Priority.Lowest, this); pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerNormal, Priority.Normal, this); pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerHighest, Priority.Highest, this); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) - { - LOGGER.log(Level.WARNING, _("versionMismatchAll")); - } + LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); } public void onDisable() { - chatListener.clear(); + if (chatListener != null) + { + chatListener.clear(); + } } public void addEssentialsChatListener(final String plugin, final IEssentialsChatListener listener) diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java index 6bc0c2022..e0ca6cd7c 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java @@ -28,13 +28,17 @@ public class EssentialsGeoIP extends JavaPlugin { final PluginManager pm = getServer().getPluginManager(); final IEssentials ess = (IEssentials)pm.getPlugin("Essentials"); - final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess); - pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { logger.log(Level.WARNING, _("versionMismatchAll")); } + if (!ess.isEnabled()) { + this.setEnabled(false); + return; + } + final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess); + pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this); + logger.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); logger.log(Level.INFO, "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/."); diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyBlockListener.java new file mode 100644 index 000000000..479d2eda6 --- /dev/null +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyBlockListener.java @@ -0,0 +1,36 @@ +package com.earth2me.essentials.protect; + +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockListener; + + +public class EmergencyBlockListener extends BlockListener +{ + + @Override + public void onBlockBurn(final BlockBurnEvent event) + { + event.setCancelled(true); + } + + @Override + public void onBlockIgnite(final BlockIgniteEvent event) + { + event.setCancelled(true); + } + + @Override + public void onBlockFromTo(final BlockFromToEvent event) + { + event.setCancelled(true); + } + + @Override + public void onBlockBreak(final BlockBreakEvent event) + { + event.setCancelled(true); + } +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyEntityListener.java new file mode 100644 index 000000000..a220f07d5 --- /dev/null +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyEntityListener.java @@ -0,0 +1,22 @@ +package com.earth2me.essentials.protect; + +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityListener; + + +public class EmergencyEntityListener extends EntityListener +{ + + @Override + public void onEntityExplode(final EntityExplodeEvent event) + { + event.setCancelled(true); + } + + @Override + public void onEntityDamage(final EntityDamageEvent event) + { + event.setCancelled(true); + } +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyPlayerListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyPlayerListener.java new file mode 100644 index 000000000..e92325946 --- /dev/null +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EmergencyPlayerListener.java @@ -0,0 +1,16 @@ +package com.earth2me.essentials.protect; + +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerListener; + + +public class EmergencyPlayerListener extends PlayerListener +{ + + @Override + public void onPlayerJoin(PlayerJoinEvent event) + { + event.getPlayer().sendMessage("Essentials Protect is in emergency mode. Check your log for errors."); + } + +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index 897112cb6..13e931f8d 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -51,6 +51,14 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect { final PluginManager pm = this.getServer().getPluginManager(); ess = (IEssentials)pm.getPlugin("Essentials"); + if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) + { + LOGGER.log(Level.WARNING, _("versionMismatchAll")); + } + if (!ess.isEnabled()) { + enableEmergencyMode(pm); + return; + } final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this); pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this); @@ -79,13 +87,28 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect reloadConfig(); ess.addReloadListener(this); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) - { - LOGGER.log(Level.WARNING, _("versionMismatchAll")); - } LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); } + private void enableEmergencyMode(final PluginManager pm) + { + final EmergencyBlockListener emBlockListener = new EmergencyBlockListener(); + final EmergencyEntityListener emEntityListener = new EmergencyEntityListener(); + final EmergencyPlayerListener emPlayerListener = new EmergencyPlayerListener(); + pm.registerEvent(Type.PLAYER_JOIN, emPlayerListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_BURN, emBlockListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_IGNITE, emBlockListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_FROMTO, emBlockListener, Priority.Low, this); + pm.registerEvent(Type.BLOCK_BREAK, emBlockListener, Priority.Low, this); + pm.registerEvent(Type.ENTITY_DAMAGE, emEntityListener, Priority.Low, this); + pm.registerEvent(Type.ENTITY_EXPLODE, emEntityListener, Priority.Low, this); + for (Player player : getServer().getOnlinePlayers()) + { + player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors."); + } + LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now."); + } + @Override public boolean checkProtectionItems(final ProtectConfig list, final int id) { diff --git a/EssentialsProtect/src/plugin.yml b/EssentialsProtect/src/plugin.yml index 31fc1ae99..770d51e64 100644 --- a/EssentialsProtect/src/plugin.yml +++ b/EssentialsProtect/src/plugin.yml @@ -6,4 +6,4 @@ version: TeamCity website: http://www.earth2me.net:8001/ description: Provides protection for various parts of the world. authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology] -depend: [Essentials] \ No newline at end of file +softdepend: [Essentials] \ No newline at end of file diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java index 8ffdb5c97..256faf6c7 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -21,15 +21,18 @@ public class EssentialsSpawn extends JavaPlugin { final PluginManager pluginManager = getServer().getPluginManager(); ess = (IEssentials)pluginManager.getPlugin("Essentials"); - final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess); - pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, Priority.Low, this); - pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Low, this); - - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { LOGGER.log(Level.WARNING, _("versionMismatchAll")); } + if (!ess.isEnabled()) { + this.setEnabled(false); + return; + } + final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess); + pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, Priority.Low, this); + pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Low, this); + LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); } diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java index 06575851d..56126e23b 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java @@ -36,9 +36,14 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP final PluginManager pluginManager = getServer().getPluginManager(); ess = (IEssentials)pluginManager.getPlugin("Essentials"); - if (ess == null) + if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { - LOGGER.log(Level.SEVERE, "Failed to load Essentials before EssentialsXMPP"); + LOGGER.log(Level.WARNING, _("versionMismatchAll")); + } + if (!ess.isEnabled()) + { + this.setEnabled(false); + return; } final EssentialsXMPPPlayerListener playerListener = new EssentialsXMPPPlayerListener(ess); @@ -52,17 +57,16 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP ess.addReloadListener(users); ess.addReloadListener(xmpp); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) - { - LOGGER.log(Level.WARNING, _("versionMismatchAll")); - } LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); } @Override public void onDisable() { - xmpp.disconnect(); + if (xmpp != null) + { + xmpp.disconnect(); + } } @Override