summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-04-02 02:43:58 +0000
committersnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-04-02 02:43:58 +0000
commit3496a8522849034d53e52f1412d7f0459b2c01cb (patch)
treec3cd0e48fe9ca91844eaa6175c49ff98c47ba183
parent348cb29469b8fbb133044ae7d20bf73d5df43b2b (diff)
downloadEssentials-3496a8522849034d53e52f1412d7f0459b2c01cb.tar
Essentials-3496a8522849034d53e52f1412d7f0459b2c01cb.tar.gz
Essentials-3496a8522849034d53e52f1412d7f0459b2c01cb.tar.lz
Essentials-3496a8522849034d53e52f1412d7f0459b2c01cb.tar.xz
Essentials-3496a8522849034d53e52f1412d7f0459b2c01cb.zip
[trunk] Prevent explosions near protected objects
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1091 e251c2fe-e539-e718-e476-b85c1f46cddb
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java35
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java30
3 files changed, 66 insertions, 2 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index e91216d87..1d1422b9f 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -75,7 +75,8 @@ public class Essentials extends JavaPlugin
"Settings",
"OfflinePlayer",
"ItemDb",
- "Mob"
+ "Mob",
+ "EssentialsBlockListener"
};
try
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
index 91a22f0e1..3462f9d79 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
@@ -180,7 +180,7 @@ public class EssentialsBlockListener extends BlockListener
return NOSIGN;
}
- private Block[] getAdjacentBlocks(Block block)
+ private static Block[] getAdjacentBlocks(Block block)
{
return new Block[]
{
@@ -229,4 +229,37 @@ public class EssentialsBlockListener extends BlockListener
}
return protect;
}
+
+ public static boolean isBlockProtected(Block block)
+ {
+ Block[] faces = getAdjacentBlocks(block);
+ for (Block b : faces)
+ {
+ if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN)
+ {
+ Sign sign = new CraftSign(b);
+ if (sign.getLine(0).equalsIgnoreCase("§1[Protection]"))
+ {
+ return true;
+ }
+ }
+ if (protectedBlocks.contains(b.getType()))
+ {
+ Block[] faceChest = getAdjacentBlocks(b);
+
+ for (Block a : faceChest)
+ {
+ if (a.getType() == Material.SIGN_POST || a.getType() == Material.WALL_SIGN)
+ {
+ Sign sign = new CraftSign(a);
+ if (sign.getLine(0).equalsIgnoreCase("§1[Protection]"))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
index cad4389d6..29118bdfb 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
@@ -1,6 +1,7 @@
package com.earth2me.essentials.protect;
import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.EssentialsBlockListener;
import com.earth2me.essentials.User;
import java.util.ArrayList;
import java.util.HashSet;
@@ -8,7 +9,9 @@ import java.util.List;
import net.minecraft.server.ChunkPosition;
import net.minecraft.server.Packet60Explosion;
import org.bukkit.Location;
+import org.bukkit.Material;
import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Creeper;
@@ -187,6 +190,33 @@ public class EssentialsProtectEntityListener extends EntityListener
return;
}
}
+ // This code will prevent explosions near protected rails, signs or protected chests
+ // TODO: Use protect db instead of this code
+ for (Block block : event.blockList())
+ {
+ if ((block.getType() == Material.RAILS || block.getFace(BlockFace.UP).getType() == Material.RAILS) && EssentialsProtect.genSettings.get("protect.protect.rails"))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (( block.getType() == Material.WALL_SIGN ||
+ block.getFace(BlockFace.NORTH).getType() == Material.WALL_SIGN ||
+ block.getFace(BlockFace.EAST).getType() == Material.WALL_SIGN ||
+ block.getFace(BlockFace.SOUTH).getType() == Material.WALL_SIGN ||
+ block.getFace(BlockFace.WEST).getType() == Material.WALL_SIGN ||
+ block.getType() == Material.SIGN_POST ||
+ block.getFace(BlockFace.UP).getType() == Material.SIGN_POST) &&
+ EssentialsProtect.genSettings.get("protect.protect.signs"))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if ( EssentialsBlockListener.protectedBlocks.contains(block.getType()) &&
+ EssentialsBlockListener.isBlockProtected(block)) {
+ event.setCancelled(true);
+ return;
+ }
+ }
}
@Override