[trunk] Prevent explosions near protected objects

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1091 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
snowleo 2011-04-02 02:43:58 +00:00
parent 348cb29469
commit 3496a85228
3 changed files with 66 additions and 2 deletions

View file

@ -75,7 +75,8 @@ public class Essentials extends JavaPlugin
"Settings", "Settings",
"OfflinePlayer", "OfflinePlayer",
"ItemDb", "ItemDb",
"Mob" "Mob",
"EssentialsBlockListener"
}; };
try try

View file

@ -180,7 +180,7 @@ public class EssentialsBlockListener extends BlockListener
return NOSIGN; return NOSIGN;
} }
private Block[] getAdjacentBlocks(Block block) private static Block[] getAdjacentBlocks(Block block)
{ {
return new Block[] return new Block[]
{ {
@ -229,4 +229,37 @@ public class EssentialsBlockListener extends BlockListener
} }
return protect; 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;
}
} }

View file

@ -1,6 +1,7 @@
package com.earth2me.essentials.protect; package com.earth2me.essentials.protect;
import com.earth2me.essentials.Essentials; import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.EssentialsBlockListener;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -8,7 +9,9 @@ import java.util.List;
import net.minecraft.server.ChunkPosition; import net.minecraft.server.ChunkPosition;
import net.minecraft.server.Packet60Explosion; import net.minecraft.server.Packet60Explosion;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
@ -187,6 +190,33 @@ public class EssentialsProtectEntityListener extends EntityListener
return; 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 @Override