diff options
author | ementalo <ementalo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-06-02 23:09:59 +0000 |
---|---|---|
committer | ementalo <ementalo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-06-02 23:09:59 +0000 |
commit | f6cedda1e227f4e8e5a18bfc864ef515f286850e (patch) | |
tree | 5f3e873e899cb893ca9e8f7b524538e138fc1f77 /EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java | |
parent | 3dab3d8df8ab31ce5330bb447983bcc498c2f9c6 (diff) | |
download | Essentials-f6cedda1e227f4e8e5a18bfc864ef515f286850e.tar Essentials-f6cedda1e227f4e8e5a18bfc864ef515f286850e.tar.gz Essentials-f6cedda1e227f4e8e5a18bfc864ef515f286850e.tar.lz Essentials-f6cedda1e227f4e8e5a18bfc864ef515f286850e.tar.xz Essentials-f6cedda1e227f4e8e5a18bfc864ef515f286850e.zip |
[trunk] Protect refactors (formally known as 3.0) needs ***EXTENSIVE*** testing
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1574 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java')
-rw-r--r-- | EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java | 144 |
1 files changed, 92 insertions, 52 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index b35a1346b..bdcb167b8 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -2,10 +2,16 @@ package com.earth2me.essentials.protect; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.IConf; +import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; -import java.util.List; -import java.util.Map; +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.ArrayList; +import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Location; @@ -22,19 +28,21 @@ public class EssentialsProtect extends JavaPlugin implements IConf private EssentialsProtectPlayerListener playerListener = null; private EssentialsProtectEntityListener entityListener = null; private EssentialsProtectWeatherListener weatherListener = null; - private EssentialsProtectServerListener serverListener = null; public static final String AUTHORS = Essentials.AUTHORS; private static final Logger logger = Logger.getLogger("Minecraft"); - public static Map<String, Boolean> genSettings = null; - public static Map<String, String> dataSettings = null; - public static Map<String, Boolean> guardSettings = null; - public static Map<String, Boolean> playerSettings = null; - public static List<Integer> usageList = null; - public static List<Integer> blackListPlace = null; - public static List<Integer> breakBlackList = null; - public static List<Integer> onPlaceAlert = null; - public static List<Integer> onUseAlert = null; - public static List<Integer> onBreakAlert = null; + public static HashMap<String, Boolean> genSettings = null; + public static HashMap<String, String> dataSettings = null; + public static HashMap<String, Boolean> guardSettings = null; + public static HashMap<String, Boolean> playerSettings = null; + public static ArrayList usageList = null; + public static ArrayList blackListPlace = null; + public static ArrayList breakBlackList = null; + public static ArrayList onPlaceAlert = null; + public static ArrayList onUseAlert = null; + public static ArrayList onBreakAlert = null; + private IProtectedBlock storage = null; + IEssentials ess = null; + private static EssentialsProtect instance = null; public EssentialsProtect() { @@ -42,48 +50,44 @@ public class EssentialsProtect extends JavaPlugin implements IConf public void onEnable() { + ess = Essentials.getStatic(); PluginManager pm = this.getServer().getPluginManager(); + Essentials ess = (Essentials)pm.getPlugin("Essentials"); + if (!ess.isEnabled()) + { + pm.enablePlugin(ess); + } + + instance = this; + reloadConfig(); playerListener = new EssentialsProtectPlayerListener(this); blockListener = new EssentialsProtectBlockListener(this); entityListener = new EssentialsProtectEntityListener(this); weatherListener = new EssentialsProtectWeatherListener(this); - serverListener = new EssentialsProtectServerListener(this); - pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this); - - //blocklistener pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Highest, this); pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this); pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this); pm.registerEvent(Type.BLOCK_BURN, blockListener, Priority.Highest, this); - pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this); - - //entitylistener pm.registerEvent(Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this); pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this); - pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this); + pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this); pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this); - - //weatherlistener - pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this); - pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this); 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); - //serverlistener - pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Highest, this); - - reloadConfig(); - Essentials.getStatic().addReloadListener(this); - if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) { - logger.log(Level.WARNING, Util.i18n("versionMismatchAll")); + if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) + { + logger.log(Level.WARNING, "Version mismatch! Please update all Essentials jars to the same version."); } - logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS)); + logger.info("Loaded " + this.getDescription().getName() + " build " + this.getDescription().getVersion() + " maintained by " + AUTHORS); } - public static boolean checkProtectionItems(List<Integer> itemList, int id) + public static boolean checkProtectionItems(ArrayList itemList, int id) { - return !itemList.isEmpty() && itemList.contains(id); + return !itemList.isEmpty() && itemList.contains(String.valueOf(id)); } @Override @@ -106,29 +110,65 @@ public class EssentialsProtect extends JavaPlugin implements IConf onBreakAlert = null; } - public void reloadConfig() - { - dataSettings = Essentials.getStatic().getSettings().getEpDBSettings(); - genSettings = Essentials.getStatic().getSettings().getEpSettings(); - guardSettings = Essentials.getStatic().getSettings().getEpGuardSettings(); - usageList = Essentials.getStatic().getSettings().epBlackListUsage(); - blackListPlace = Essentials.getStatic().getSettings().epBlackListPlacement(); - breakBlackList = Essentials.getStatic().getSettings().epBlockBreakingBlacklist(); - onPlaceAlert = Essentials.getStatic().getSettings().getEpAlertOnPlacement(); - onUseAlert = Essentials.getStatic().getSettings().getEpAlertOnUse(); - onBreakAlert = Essentials.getStatic().getSettings().getEpAlertOnBreak(); - playerSettings = Essentials.getStatic().getSettings().getEpPlayerSettings(); - EssentialsProtectData.createSqlTable(); - } - public void alert(User user, String item, String type) { Location loc = user.getLocation(); for (Player p : this.getServer().getOnlinePlayers()) { - User alertUser = Essentials.getStatic().getUser(p); + User alertUser = ess.getUser(p); if (alertUser.isAuthorized("essentials.protect.alerts")) - alertUser.sendMessage(Util.format("alertFormat", user.getName(), type, item, EssentialsProtectData.formatCoords(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))); + alertUser.sendMessage(Util.format("alertFormat", user.getName(), type, item, formatCoords(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))); + } + } + + public static String formatCoords(int x, int y, int z) + { + return x + "," + y + "," + z; + } + + public void reloadConfig() + { + dataSettings = ess.getSettings().getEpDBSettings(); + genSettings = ess.getSettings().getEpSettings(); + guardSettings = ess.getSettings().getEpGuardSettings(); + usageList = ess.getSettings().epBlackListUsage(); + blackListPlace = ess.getSettings().epBlackListPlacement(); + breakBlackList = ess.getSettings().epBlockBreakingBlacklist(); + onPlaceAlert = ess.getSettings().getEpAlertOnPlacement(); + onUseAlert = ess.getSettings().getEpAlertOnUse(); + onBreakAlert = ess.getSettings().getEpAlertOnBreak(); + playerSettings = ess.getSettings().getEpPlayerSettings(); + + if (dataSettings.get("protect.datatype").equals("mysql")) + { + try + { + storage = new ProtectedBlockMySQL(dataSettings.get("protect.mysqlDb"), dataSettings.get("protect.username"), dataSettings.get("protect.password")); + } + 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 (genSettings.get("protect.memstore")) + { + storage = new ProtectedBlockMemory(storage); + } + } + + public static IProtectedBlock getStorage() + { + return EssentialsProtect.instance.storage; } } |