mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-02 17:09:58 +01:00
Protection of signs against pistons
This commit is contained in:
parent
cc31fbed8e
commit
1ce6be5944
@ -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);
|
||||
|
@ -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)
|
||||
@ -425,7 +430,6 @@ public class EssentialsSign
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user