summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
diff options
context:
space:
mode:
authorZenexer <Zenexer@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-03-30 04:04:57 +0000
committerZenexer <Zenexer@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-03-30 04:04:57 +0000
commitcbbe0d8beb749ea042283df347f6302f810b9e56 (patch)
treef1584fe391f77c648a1d7d25385ef16229b756de /EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
parent063f5940695cd6d488d1113a90cee44acb30356c (diff)
parentcb21bc4d7a67f0974c2773fdd0f5376f177c068e (diff)
downloadEssentials-cbbe0d8beb749ea042283df347f6302f810b9e56.tar
Essentials-cbbe0d8beb749ea042283df347f6302f810b9e56.tar.gz
Essentials-cbbe0d8beb749ea042283df347f6302f810b9e56.tar.lz
Essentials-cbbe0d8beb749ea042283df347f6302f810b9e56.tar.xz
Essentials-cbbe0d8beb749ea042283df347f6302f810b9e56.zip
Renamed 2.1 -> trunk
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1017 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.java78
1 files changed, 55 insertions, 23 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
index a2c577789..d6869519b 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
@@ -1,7 +1,13 @@
package com.earth2me.essentials.protect;
import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.IConf;
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.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
@@ -15,7 +21,7 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
-public class EssentialsProtect extends JavaPlugin
+public class EssentialsProtect extends JavaPlugin implements IConf
{
private EssentialsProtectBlockListener blockListener = null;
private EssentialsProtectPlayerListener playerListener = null;
@@ -33,6 +39,8 @@ public class EssentialsProtect extends JavaPlugin
public static ArrayList onUseAlert = null;
public static ArrayList onBreakAlert = null;
+ private IProtectedBlock storage = null;
+ private static EssentialsProtect instance = null;
public EssentialsProtect()
{
@@ -42,27 +50,27 @@ public class EssentialsProtect extends JavaPlugin
{
PluginManager pm = this.getServer().getPluginManager();
Essentials ess = (Essentials)pm.getPlugin("Essentials");
- if (!ess.isEnabled())
+ if (!ess.isEnabled()) {
pm.enablePlugin(ess);
+ }
+
+ instance = this;
+ reloadConfig();
playerListener = new EssentialsProtectPlayerListener(this);
blockListener = new EssentialsProtectBlockListener(this);
entityListener = new EssentialsProtectEntityListener(this);
- pm.registerEvent(Type.PLAYER_ITEM, playerListener, Priority.Low, this);
- // Why is this commented?
- //pm.registerEvent(Type.BLOCK_DAMAGED, blockListener, Priority.High, this);
- pm.registerEvent(Type.BLOCK_RIGHTCLICKED, blockListener, Priority.Low, this);
- pm.registerEvent(Type.BLOCK_PLACED, blockListener, Priority.Highest, this);
- pm.registerEvent(Type.BLOCK_INTERACT, blockListener, Priority.Highest, this);
- pm.registerEvent(Type.BLOCK_FLOW, blockListener, Priority.Highest, this);
+ pm.registerEvent(Type.PLAYER_PICKUP_ITEM, playerListener, Priority.Low, this);
+ pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, 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.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
- pm.registerEvent(Type.ENTITY_DAMAGED, entityListener, Priority.Highest, this);
+ pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);
- loadSettings();
if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
logger.log(Level.WARNING, "Version mismatch! Please update all Essentials jars to the same version.");
}
@@ -94,8 +102,23 @@ public class EssentialsProtect extends JavaPlugin
onBreakAlert = null;
}
- public static void loadSettings()
+ public void alert(User user, String item, String type)
{
+ Location loc = user.getLocation();
+ for (Player p : this.getServer().getOnlinePlayers())
+ {
+ User alertUser = User.get(p);
+ if (alertUser.isAuthorized("essentials.protect.alerts"))
+ alertUser.sendMessage(ChatColor.DARK_AQUA + "[" + user.getName() + "] " + ChatColor.WHITE + type + ChatColor.GOLD + item + " at: " + 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 = Essentials.getSettings().getEpDBSettings();
genSettings = Essentials.getSettings().getEpSettings();
guardSettings = Essentials.getSettings().getEpGuardSettings();
@@ -106,17 +129,26 @@ public class EssentialsProtect extends JavaPlugin
onUseAlert = Essentials.getSettings().getEpAlertOnUse();
onBreakAlert = Essentials.getSettings().getEpAlertOnBreak();
playerSettings = Essentials.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 = User.get(p);
- if (alertUser.isAuthorized("essentials.protect.alerts"))
- alertUser.sendMessage(ChatColor.DARK_AQUA + "[" + user.getName() + "] " + ChatColor.WHITE + type + ChatColor.GOLD + item + " at: " + EssentialsProtectData.formatCoords(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
+
+ 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;
+ }
}