Protection of signs against pistons

This commit is contained in:
snowleo 2011-07-18 00:50:03 +02:00
parent cc31fbed8e
commit 1ce6be5944
4 changed files with 118 additions and 50 deletions

View File

@ -197,6 +197,8 @@ public class Essentials extends JavaPlugin implements IEssentials
pm.registerEvent(Type.BLOCK_BREAK, signBlockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_IGNITE, signBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_BURN, signBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_PISTON_EXTEND, signBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_PISTON_RETRACT, signBlockListener, Priority.Low, this);
final SignPlayerListener signPlayerListener = new SignPlayerListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, signPlayerListener, Priority.Low, this);

View File

@ -189,6 +189,11 @@ public class EssentialsSign
return true;
}
public boolean onBlockPush(Block block, IEssentials ess)
{
return true;
}
public static boolean checkIfBlockBreaksSigns(final Block block)
{
if (block.getFace(BlockFace.UP).getType() == Material.SIGN_POST)
@ -333,7 +338,7 @@ public class EssentialsSign
protected final Double getDoublePositive(final String line) throws SignException
{
final double quantity = getDouble(line);
if (Math.round(quantity*100.0) < 1.0)
if (Math.round(quantity * 100.0) < 1.0)
{
throw new SignException(Util.i18n("moreThanZero"));
}
@ -425,7 +430,6 @@ public class EssentialsSign
{
return;
}
}

View File

@ -13,6 +13,8 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
@ -104,7 +106,8 @@ public class SignBlockListener extends BlockListener
User user = ess.getUser(event.getPlayer());
if (user.isAuthorized("essentials.signs.color"))
{
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++)
{
event.setLine(i, event.getLine(i).replaceAll("&([0-9a-f])", "§$1"));
}
}
@ -184,4 +187,55 @@ public class SignBlockListener extends BlockListener
event.setCancelled(true);
}
}
@Override
public void onBlockPistonExtend(BlockPistonExtendEvent event)
{
for (Block block : event.getBlocks())
{
if ((block.getType() == Material.WALL_SIGN
|| block.getType() == Material.SIGN_POST
|| EssentialsSign.checkIfBlockBreaksSigns(block)))
{
event.setCancelled(true);
return;
}
for (Signs signs : Signs.values())
{
final EssentialsSign sign = signs.getSign();
if (sign.getBlocks().contains(block.getType())
&& !sign.onBlockPush(block, ess))
{
event.setCancelled(true);
return;
}
}
}
}
@Override
public void onBlockPistonRetract(BlockPistonRetractEvent event)
{
if (event.isSticky())
{
final Block block = event.getBlock();
if ((block.getType() == Material.WALL_SIGN
|| block.getType() == Material.SIGN_POST
|| EssentialsSign.checkIfBlockBreaksSigns(block)))
{
event.setCancelled(true);
return;
}
for (Signs signs : Signs.values())
{
final EssentialsSign sign = signs.getSign();
if (sign.getBlocks().contains(block.getType())
&& !sign.onBlockPush(block, ess))
{
event.setCancelled(true);
return;
}
}
}
}
}

View File

@ -311,4 +311,12 @@ public class SignProtection extends EssentialsSign
return state == SignProtectionState.NOSIGN;
}
@Override
public boolean onBlockPush(final Block block, final IEssentials ess)
{
final SignProtectionState state = isBlockProtected(block, null, null, false);
return state == SignProtectionState.NOSIGN;
}
}