diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-03-30 12:56:34 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-03-30 12:56:34 +0000 |
commit | 08041599fffe85ef4e5da59cc060a690c7dc8994 (patch) | |
tree | 9c214b0328d346aaefb4d9f69cc10d3877fd44eb /EssentialsProtect | |
parent | 81c9b91561fa978bcfa9f5824d5d60c949a622e5 (diff) | |
download | Essentials-08041599fffe85ef4e5da59cc060a690c7dc8994.tar Essentials-08041599fffe85ef4e5da59cc060a690c7dc8994.tar.gz Essentials-08041599fffe85ef4e5da59cc060a690c7dc8994.tar.lz Essentials-08041599fffe85ef4e5da59cc060a690c7dc8994.tar.xz Essentials-08041599fffe85ef4e5da59cc060a690c7dc8994.zip |
Revert to 1013
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1021 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsProtect')
5 files changed, 107 insertions, 151 deletions
diff --git a/EssentialsProtect/build.xml b/EssentialsProtect/build.xml index 3e57911b3..e5e614e3e 100644 --- a/EssentialsProtect/build.xml +++ b/EssentialsProtect/build.xml @@ -78,7 +78,6 @@ <zipfileset src="${dist.jar}" excludes="META-INF/*" />
<zipfileset src="../lib/mysql.jar" excludes="META-INF/*" />
<zipfileset src="../lib/sqlite.jar" excludes="META-INF/*" />
- <zipfileset src="../lib/c3p0-0.9.1.2.jar" excludes="META-INF/*" />
<manifest>
<attribute name="Classpath" value="Essentials.jar"/>
</manifest>
diff --git a/EssentialsProtect/nbproject/project.properties b/EssentialsProtect/nbproject/project.properties index 3f2895ed5..dcce6d152 100644 --- a/EssentialsProtect/nbproject/project.properties +++ b/EssentialsProtect/nbproject/project.properties @@ -26,7 +26,6 @@ dist.jar=${dist.dir}/original-EssentialsProtect.jar dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
-file.reference.c3p0-0.9.1.2.jar=..\\lib\\c3p0-0.9.1.2.jar
file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar
file.reference.mysql.jar=..\\lib\\mysql.jar
file.reference.sqlite.jar=..\\lib\\sqlite.jar
@@ -38,8 +37,7 @@ javac.classpath=\ ${reference.Essentials.jar}:\
${file.reference.mysql.jar}:\
${file.reference.sqlite.jar}:\
- ${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\
- ${file.reference.c3p0-0.9.1.2.jar}
+ ${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index d6869519b..798153b1c 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -1,13 +1,7 @@ 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; @@ -21,7 +15,7 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -public class EssentialsProtect extends JavaPlugin implements IConf +public class EssentialsProtect extends JavaPlugin { private EssentialsProtectBlockListener blockListener = null; private EssentialsProtectPlayerListener playerListener = null; @@ -39,8 +33,6 @@ public class EssentialsProtect extends JavaPlugin implements IConf public static ArrayList onUseAlert = null; public static ArrayList onBreakAlert = null; - private IProtectedBlock storage = null; - private static EssentialsProtect instance = null; public EssentialsProtect() { @@ -50,18 +42,15 @@ public class EssentialsProtect extends JavaPlugin implements IConf { 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_PICKUP_ITEM, playerListener, Priority.Low, this); pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this); + // Why is this commented? + //pm.registerEvent(Type.BLOCK_DAMAGED, blockListener, Priority.High, 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); @@ -71,6 +60,7 @@ public class EssentialsProtect extends JavaPlugin implements IConf 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."); } @@ -102,23 +92,8 @@ public class EssentialsProtect extends JavaPlugin implements IConf onBreakAlert = null; } - public void alert(User user, String item, String type) + public static void loadSettings() { - 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(); @@ -129,26 +104,17 @@ public class EssentialsProtect extends JavaPlugin implements IConf onUseAlert = Essentials.getSettings().getEpAlertOnUse(); onBreakAlert = Essentials.getSettings().getEpAlertOnBreak(); playerSettings = Essentials.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); - } + EssentialsProtectData.createSqlTable(); } - - public static IProtectedBlock getStorage() { - return EssentialsProtect.instance.storage; + + 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())); + } } } diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index 2028edf42..e96165ecd 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java @@ -2,24 +2,28 @@ package com.earth2me.essentials.protect; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; -import java.util.ArrayList; -import java.util.List; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; 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.BlockInteractEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockRightClickEvent; import org.bukkit.inventory.ItemStack; public class EssentialsProtectBlockListener extends BlockListener { private EssentialsProtect parent; + private int railBlockX; + private int railBlockY; + private int railBlockZ; + private EssentialsProtectData spData; public EssentialsProtectBlockListener(EssentialsProtect parent) { @@ -27,10 +31,17 @@ public class EssentialsProtectBlockListener extends BlockListener this.parent = parent; } + private void initialize() + { + if (spData != null) return; + spData = new EssentialsProtectData(); + } + @Override public void onBlockPlace(BlockPlaceEvent event) { if (event.isCancelled()) return; + initialize(); ItemStack item = event.getItemInHand(); User user = User.get(event.getPlayer()); @@ -40,6 +51,7 @@ public class EssentialsProtectBlockListener extends BlockListener return; } + Block blockPlaced = event.getBlockAgainst(); int id = event.getBlockPlaced().getTypeId(); if (EssentialsProtect.checkProtectionItems(EssentialsProtect.blackListPlace, id) && !user.isAuthorized("essentials.protect.exemptplacement")) @@ -53,48 +65,33 @@ public class EssentialsProtectBlockListener extends BlockListener parent.alert(user, item.getType().toString(), "placed: "); } - Block blockPlaced = event.getBlockPlaced(); - Block below = blockPlaced.getFace(BlockFace.DOWN); - if (below.getType() == Material.RAILS) { + if (spData.isBlockAboveProtectedRail(blockPlaced)) + { if (EssentialsProtect.genSettings.get("protect.protect.prevent.block-on-rail")) { - if (EssentialsProtect.getStorage().isProtected(below, user.getName())) { - event.setCancelled(true); - return; - } + event.setCancelled(true); + return; } } - List<Block> protect = new ArrayList<Block>(); - if (blockPlaced.getType() == Material.RAILS) { + if (item.getTypeId() == 66) + { if (EssentialsProtect.genSettings.get("protect.protect.rails")) { if (user.isAuthorized("essentials.protect")) { - protect.add(blockPlaced); - if (EssentialsProtect.genSettings.get("protect.protect.block-below")) - { - protect.add(blockPlaced.getFace(BlockFace.DOWN)); - } - } - } - } - if (blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN) { - if (EssentialsProtect.genSettings.get("protect.protect.signs")) - { - if (user.isAuthorized("essentials.protect")) - { - protect.add(blockPlaced); + railBlockX = blockPlaced.getX(); + railBlockY = blockPlaced.getY(); + railBlockZ = blockPlaced.getZ(); + + spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), railBlockX, railBlockY + 1, railBlockZ); if (EssentialsProtect.genSettings.get("protect.protect.block-below")) { - protect.add(event.getBlockAgainst()); + spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), railBlockX, railBlockY, railBlockZ); } } } } - for (Block block : protect) { - EssentialsProtect.getStorage().protectBlock(block, user.getName()); - } } @Override @@ -131,7 +128,7 @@ public class EssentialsProtectBlockListener extends BlockListener } @Override - public void onBlockFromTo(BlockFromToEvent event) + public void onBlockFlow(BlockFromToEvent event) { if (event.isCancelled()) return; Block block = event.getBlock(); @@ -190,6 +187,7 @@ public class EssentialsProtectBlockListener extends BlockListener public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) return; + initialize(); User user = User.get(event.getPlayer()); Block block = event.getBlock(); if (EssentialsProtect.playerSettings.get("protect.disable.build") && !user.canBuild()) @@ -213,57 +211,28 @@ public class EssentialsProtectBlockListener extends BlockListener { if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST || block.getType() == Material.RAILS) { - EssentialsProtect.getStorage().unprotectBlock(block); - if (block.getType() == Material.RAILS || block.getType() == Material.SIGN_POST) { - Block below = block.getFace(BlockFace.DOWN); - EssentialsProtect.getStorage().unprotectBlock(below); - } else { - BlockFace[] faces = new BlockFace[] { - BlockFace.NORTH, - BlockFace.EAST, - BlockFace.SOUTH, - BlockFace.WEST - }; - for (BlockFace blockFace : faces) { - Block against = block.getFace(blockFace); - EssentialsProtect.getStorage().unprotectBlock(against); - } - } + spData.removeProtectionFromDB(block, true); } else { - EssentialsProtect.getStorage().unprotectBlock(block); + spData.removeProtectionFromDB(block); } return; } else { - - boolean isProtected = EssentialsProtect.getStorage().isProtected(block, user.getName()); - if (!isProtected) { + boolean canDestroy = spData.canDestroy(user.getWorld().getName(), user.getName(), block); + if (canDestroy) + { if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST || block.getType() == Material.RAILS) - { - EssentialsProtect.getStorage().unprotectBlock(block); - if (block.getType() == Material.RAILS || block.getType() == Material.SIGN_POST) { - Block below = block.getFace(BlockFace.DOWN); - EssentialsProtect.getStorage().unprotectBlock(below); - } else { - BlockFace[] faces = new BlockFace[] { - BlockFace.NORTH, - BlockFace.EAST, - BlockFace.SOUTH, - BlockFace.WEST - }; - for (BlockFace blockFace : faces) { - Block against = block.getFace(blockFace); - EssentialsProtect.getStorage().unprotectBlock(against); - } - } + { + spData.removeProtectionFromDB(block, true); } else { - EssentialsProtect.getStorage().unprotectBlock(block); + spData.removeProtectionFromDB(block); } + return; } event.setCancelled(true); return; diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java index 2497a733d..c75bb6324 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java @@ -3,68 +3,92 @@ package com.earth2me.essentials.protect; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; import org.bukkit.ChatColor; +import org.bukkit.block.Block; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemEvent; import org.bukkit.event.player.PlayerListener; -import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; public class EssentialsProtectPlayerListener extends PlayerListener { private EssentialsProtect parent; - + private int signBlockX; + private int signBlockY; + private int signBlockZ; + private EssentialsProtectData spData = null; + public EssentialsProtectPlayerListener(EssentialsProtect parent) { Essentials.loadClasses(); this.parent = parent; } + public void initialize() + { + if (spData != null) return; + spData = new EssentialsProtectData(); + } + @Override public void onPlayerInteract(PlayerInteractEvent event) { + initialize(); if (event.isCancelled()) return; + ItemStack item = event.getItem(); User user = User.get(event.getPlayer()); + Block blockClicked = event.getClickedBlock(); if (EssentialsProtect.playerSettings.get("protect.disable.build") && !user.canBuild()) { event.setCancelled(true); return; } - - if (user.isAuthorized("essentials.protect.admin")) - { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (String owner : EssentialsProtect.getStorage().getOwners(event.getClickedBlock())) { - if (!first) { - sb.append(", "); - } - first = false; - sb.append(owner); - } - String ownerNames = sb.toString(); - if (ownerNames != null) - { - user.sendMessage(ChatColor.GOLD + "[EssentialsProtect] Protection owners: " + ownerNames); - } - } - } - @Override - public void onPlayerPickupItem(PlayerPickupItemEvent event) - { - if(event.isCancelled()) return; - ItemStack item = event.getItem().getItemStack(); - User user = User.get(event.getPlayer()); if (EssentialsProtect.checkProtectionItems(EssentialsProtect.usageList, item.getTypeId()) && !user.isAuthorized("essentials.protect.exemptusage")) { event.setCancelled(true); return; } + if (user.isAuthorized("essentials.protect.admin")) + { + String ownerName = spData.getBlockOwner(user.getWorld().getName(), user.getName(), + blockClicked); + if (ownerName != null) + { + user.sendMessage(ChatColor.GOLD + "[EssentialsProtect] Protection owner: " + + ownerName); + } + } if (EssentialsProtect.onUseAlert.contains(String.valueOf(item.getTypeId()))) { parent.alert(user, item.getType().toString(), "used: "); } + + if (item.getTypeId() == 323) + { + if (EssentialsProtect.genSettings.get("protect.protect.signs")) + { + if (user.isAuthorized("essentials.protect")) + { + + signBlockX = blockClicked.getX(); + signBlockY = blockClicked.getY(); + signBlockZ = blockClicked.getZ(); + + initialize(); + spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), signBlockX, + signBlockY + 1, signBlockZ); + + if (EssentialsProtect.genSettings.get("protect.protect.block-below")) + { + spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), signBlockX, + signBlockY, signBlockZ); + } + } + } + } + } } |