diff options
Diffstat (limited to 'EssentialsProtect/src/com/earth2me')
9 files changed, 263 insertions, 100 deletions
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/EssentialsConnect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java new file mode 100644 index 000000000..569123cd5 --- /dev/null +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java @@ -0,0 +1,124 @@ +package com.earth2me.essentials.protect; + +import com.earth2me.essentials.IConf; +import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.User; +import com.earth2me.essentials.protect.data.ProtectedBlockMemory; +import com.earth2me.essentials.protect.data.ProtectedBlockMySQL; +import com.earth2me.essentials.protect.data.ProtectedBlockSQLite; +import java.beans.PropertyVetoException; +import static com.earth2me.essentials.I18n._; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + + +public class EssentialsConnect +{ + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private final transient IEssentials ess; + private final transient IProtect protect; + + public EssentialsConnect(Plugin essPlugin, Plugin essProtect) + { + if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion())) + { + LOGGER.log(Level.WARNING, _("versionMismatchAll")); + } + ess = (IEssentials)essPlugin; + protect = (IProtect)essProtect; + ProtectReloader pr = new ProtectReloader(); + pr.reloadConfig(); + ess.addReloadListener(pr); + LOGGER.info(_("loadinfo", essProtect.getDescription().getName(), essProtect.getDescription().getVersion(), "essentials team")); + + } + + public void onDisable() + { + } + + public IEssentials getEssentials() + { + return ess; + } + + public void alert(final User user, final String item, final String type) + { + final Location loc = user.getLocation(); + final String warnMessage = _("alertFormat", user.getName(), type, item, + loc.getWorld().getName() + "," + loc.getBlockX() + "," + + loc.getBlockY() + "," + loc.getBlockZ()); + LOGGER.log(Level.WARNING, warnMessage); + for (Player p : ess.getServer().getOnlinePlayers()) + { + final User alertUser = ess.getUser(p); + if (alertUser.isAuthorized("essentials.protect.alerts")) + { + alertUser.sendMessage(warnMessage); + } + } + } + + + private class ProtectReloader implements IConf + { + @Override + public void reloadConfig() + { + if (protect.getStorage() != null) + { + protect.getStorage().onPluginDeactivation(); + } + for (ProtectConfig protectConfig : ProtectConfig.values()) + { + if (protectConfig.isList()) + { + protect.getSettingsList().put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName())); + } + else if (protectConfig.isString()) + { + protect.getSettingsString().put(protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName())); + } + else + { + protect.getSettingsBoolean().put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean())); + } + + } + + if (protect.getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql")) + { + try + { + protect.setStorage(new ProtectedBlockMySQL( + protect.getSettingString(ProtectConfig.mysqlDB), + protect.getSettingString(ProtectConfig.dbUsername), + protect.getSettingString(ProtectConfig.dbPassword))); + } + catch (PropertyVetoException ex) + { + LOGGER.log(Level.SEVERE, null, ex); + } + } + else + { + try + { + protect.setStorage(new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db")); + } + catch (PropertyVetoException ex) + { + LOGGER.log(Level.SEVERE, null, ex); + } + } + if (protect.getSettingBool(ProtectConfig.memstore)) + { + protect.setStorage(new ProtectedBlockMemory(protect.getStorage(), protect)); + } + + } + } +} diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index 897112cb6..e313298cd 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -1,14 +1,6 @@ package com.earth2me.essentials.protect; -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IConf; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; import com.earth2me.essentials.protect.data.IProtectedBlock; -import com.earth2me.essentials.protect.data.ProtectedBlockMemory; -import com.earth2me.essentials.protect.data.ProtectedBlockMySQL; -import com.earth2me.essentials.protect.data.ProtectedBlockSQLite; -import java.beans.PropertyVetoException; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -16,15 +8,15 @@ import java.util.logging.Filter; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; -import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -public class EssentialsProtect extends JavaPlugin implements IConf, IProtect +public class EssentialsProtect extends JavaPlugin implements IProtect { private static final Logger LOGGER = Logger.getLogger("Minecraft"); private static com.mchange.v2.log.MLogger C3P0logger; @@ -32,7 +24,7 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect private final transient Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class); private final transient Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class); private transient IProtectedBlock storage = null; - public transient IEssentials ess = null; + private transient EssentialsConnect ess = null; @Override public void onLoad() @@ -50,7 +42,13 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect public void onEnable() { final PluginManager pm = this.getServer().getPluginManager(); - ess = (IEssentials)pm.getPlugin("Essentials"); + final Plugin essPlugin = pm.getPlugin("Essentials"); + if (essPlugin == null || !essPlugin.isEnabled()) + { + enableEmergencyMode(pm); + return; + } + ess = new EssentialsConnect(essPlugin, this); final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this); pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this); @@ -76,14 +74,25 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this); pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this); pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this); + } - reloadConfig(); - ess.addReloadListener(this); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) + 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()) { - LOGGER.log(Level.WARNING, _("versionMismatchAll")); + player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors."); } - LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); + LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essenials Protect is in emergency mode now."); } @Override @@ -94,81 +103,35 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect } @Override - public void alert(final User user, final String item, final String type) + public IProtectedBlock getStorage() { - final Location loc = user.getLocation(); - final String warnMessage = _("alertFormat", user.getName(), type, item, - loc.getWorld().getName() + "," + loc.getBlockX() + "," - + loc.getBlockY() + "," + loc.getBlockZ()); - LOGGER.log(Level.WARNING, warnMessage); - for (Player p : this.getServer().getOnlinePlayers()) - { - final User alertUser = ess.getUser(p); - if (alertUser.isAuthorized("essentials.protect.alerts")) - { - alertUser.sendMessage(warnMessage); - } - } + return storage; } - public void reloadConfig() + @Override + public void setStorage(IProtectedBlock pb) { - if (storage != null) - { - storage.onPluginDeactivation(); - } - for (ProtectConfig protectConfig : ProtectConfig.values()) - { - if (protectConfig.isList()) - { - settingsList.put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName())); - } - else if (protectConfig.isString()) - { - settingsString.put(protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName())); - } - else - { - settingsBoolean.put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean())); - } + storage = pb; + } - } + public EssentialsConnect getEssentialsConnect() + { + return ess; + } + + public Map<ProtectConfig, Boolean> getSettingsBoolean() + { + return settingsBoolean; + } - if (getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql")) - { - try - { - storage = new ProtectedBlockMySQL( - getSettingString(ProtectConfig.mysqlDB), - getSettingString(ProtectConfig.dbUsername), - getSettingString(ProtectConfig.dbPassword)); - } - catch (PropertyVetoException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - } - else - { - try - { - storage = new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db"); - } - catch (PropertyVetoException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - } - if (getSettingBool(ProtectConfig.memstore)) - { - storage = new ProtectedBlockMemory(storage, this); - } + public Map<ProtectConfig, String> getSettingsString() + { + return settingsString; } - @Override - public IProtectedBlock getStorage() + public Map<ProtectConfig, List<Integer>> getSettingsList() { - return storage; + return settingsList; } @Override @@ -200,9 +163,4 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect { } } - - public IEssentials getEssentials() - { - return ess; - } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index a14925ccd..03ad19cb4 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java @@ -20,7 +20,7 @@ public class EssentialsProtectBlockListener extends BlockListener public EssentialsProtectBlockListener(final IProtect parent) { this.prot = parent; - this.ess = prot.getEssentials(); + this.ess = prot.getEssentialsConnect().getEssentials(); } @Override @@ -50,7 +50,7 @@ public class EssentialsProtectBlockListener extends BlockListener if (prot.checkProtectionItems(ProtectConfig.alert_on_placement, id)) { - prot.alert(user, blockPlaced.getType().toString(), _("alertPlaced")); + prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced")); } final Block below = blockPlaced.getRelative(BlockFace.DOWN); @@ -248,7 +248,7 @@ public class EssentialsProtectBlockListener extends BlockListener if (prot.checkProtectionItems(ProtectConfig.alert_on_break, typeId)) { - prot.alert(user, type.toString(), _("alertBroke")); + prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke")); } final IProtectedBlock storage = prot.getStorage(); diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index cd054d732..fbbb321f3 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -21,7 +21,7 @@ public class EssentialsProtectEntityListener extends EntityListener public EssentialsProtectEntityListener(final IProtect prot) { this.prot = prot; - this.ess = prot.getEssentials(); + this.ess = prot.getEssentialsConnect().getEssentials(); } @Override diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java index 98daecb97..ad7831a53 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java @@ -19,7 +19,7 @@ public class EssentialsProtectPlayerListener extends PlayerListener public EssentialsProtectPlayerListener(final IProtect prot) { this.prot = prot; - this.ess = prot.getEssentials(); + this.ess = prot.getEssentialsConnect().getEssentials(); } @Override @@ -83,7 +83,7 @@ public class EssentialsProtectPlayerListener extends PlayerListener if (item != null && prot.checkProtectionItems(ProtectConfig.alert_on_use, item.getTypeId())) { - prot.alert(user, item.getType().toString(), _("alertUsed")); + prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed")); } } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/IProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/IProtect.java index ac095e33d..afcb6e8ce 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/IProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/IProtect.java @@ -1,14 +1,13 @@ package com.earth2me.essentials.protect; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; import com.earth2me.essentials.protect.data.IProtectedBlock; +import java.util.List; +import java.util.Map; +import org.bukkit.plugin.Plugin; -public interface IProtect +public interface IProtect extends Plugin { - void alert(final User user, final String item, final String type); - boolean checkProtectionItems(final ProtectConfig list, final int id); boolean getSettingBool(final ProtectConfig protectConfig); @@ -17,5 +16,13 @@ public interface IProtect IProtectedBlock getStorage(); - IEssentials getEssentials(); + void setStorage(IProtectedBlock pb); + + EssentialsConnect getEssentialsConnect(); + + Map<ProtectConfig, Boolean> getSettingsBoolean(); + + Map<ProtectConfig, String> getSettingsString(); + + Map<ProtectConfig, List<Integer>> getSettingsList(); } |