summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java200
1 files changed, 118 insertions, 82 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
index b35a1346b..afa98b568 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
@@ -2,8 +2,15 @@ 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 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;
import java.util.logging.Level;
@@ -16,119 +23,148 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
-public class EssentialsProtect extends JavaPlugin implements IConf
+public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
{
- private EssentialsProtectBlockListener blockListener = null;
- 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 EssentialsProtect()
- {
- }
+ private static final Logger LOGGER = Logger.getLogger("Minecraft");
+
+ private final transient Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
+ 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;
public void onEnable()
{
- PluginManager pm = this.getServer().getPluginManager();
-
- playerListener = new EssentialsProtectPlayerListener(this);
- blockListener = new EssentialsProtectBlockListener(this);
- entityListener = new EssentialsProtectEntityListener(this);
- weatherListener = new EssentialsProtectWeatherListener(this);
- serverListener = new EssentialsProtectServerListener(this);
-
+ ess = Essentials.getStatic();
+ final PluginManager pm = this.getServer().getPluginManager();
+
+ final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);
-
- //blocklistener
+
+ final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
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
+
+ final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
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.CREATURE_SPAWN, entityListener, Priority.Highest, this);
+ pm.registerEvent(Type.ENTITY_TARGET, entityListener, Priority.Highest, this);
- //weatherlistener
- pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this);
- pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this);
+ final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this);
pm.registerEvent(Type.LIGHTNING_STRIKE, weatherListener, Priority.Highest, this);
-
- //serverlistener
- pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Highest, this);
-
+ pm.registerEvent(Type.THUNDER_CHANGE, weatherListener, Priority.Highest, this);
+ pm.registerEvent(Type.WEATHER_CHANGE, weatherListener, Priority.Highest, this);
+
reloadConfig();
- Essentials.getStatic().addReloadListener(this);
- if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
- logger.log(Level.WARNING, Util.i18n("versionMismatchAll"));
+ ess.addReloadListener(this);
+ if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion()))
+ {
+ LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
}
- logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
+ LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
}
- public static boolean checkProtectionItems(List<Integer> itemList, int id)
+ @Override
+ public boolean checkProtectionItems(final ProtectConfig list, final int id)
{
- return !itemList.isEmpty() && itemList.contains(id);
+ final List<Integer> itemList = settingsList.get(list);
+ return itemList != null && !itemList.isEmpty() && itemList.contains(id);
}
@Override
- public void onDisable()
+ public void alert(final User user, final String item, final String type)
{
- genSettings.clear();
- dataSettings.clear();
-
- blockListener = null;
- playerListener = null;
- entityListener = null;
- genSettings = null;
- dataSettings = null;
- guardSettings = null;
- playerSettings = null;
- usageList = null;
- blackListPlace = null;
- onPlaceAlert = null;
- onUseAlert = null;
- onBreakAlert = null;
+ final Location loc = user.getLocation();
+ for (Player p : this.getServer().getOnlinePlayers())
+ {
+ final User alertUser = ess.getUser(p);
+ if (alertUser.isAuthorized("essentials.protect.alerts"))
+ {
+ alertUser.sendMessage(Util.format("alertFormat", user.getName(), type, item, formatCoords(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
+ }
+ }
}
- public void reloadConfig()
+ public static String formatCoords(final int x, final int y, final int z)
{
- 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();
+ return x + "," + y + "," + z;
}
- public void alert(User user, String item, String type)
+ public void reloadConfig()
{
- Location loc = user.getLocation();
- for (Player p : this.getServer().getOnlinePlayers())
+ for (ProtectConfig protectConfig : ProtectConfig.values())
{
- User alertUser = Essentials.getStatic().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())));
+ 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()));
+ }
+
}
+
+ 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);
+ }
+ }
+
+ @Override
+ public IProtectedBlock getStorage()
+ {
+ return storage;
+ }
+
+ @Override
+ public boolean getSettingBool(final ProtectConfig protectConfig)
+ {
+ final Boolean bool = settingsBoolean.get(protectConfig);
+ return bool == null ? protectConfig.getDefaultValueBoolean() : bool;
+ }
+
+ @Override
+ public String getSettingString(final ProtectConfig protectConfig)
+ {
+ final String str = settingsString.get(protectConfig);
+ return str == null ? protectConfig.getDefaultValueString() : str;
+ }
+
+ public void onDisable()
+ {
+ }
+
+ public IEssentials getEssentials()
+ {
+ return ess;
}
}