mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 18:45:31 +01:00
Check all blocks moved by pistons (Fixes DBO-1247)
This commit is contained in:
parent
a493cbf59d
commit
7c9dd5c3f3
@ -70,14 +70,14 @@ public class SignBreak implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public static void onBrokenSign(BlockBreakEvent event) {
|
public static void onBrokenSign(BlockBreakEvent event) {
|
||||||
if (ChestShopSign.isValid(event.getBlock()) && !event.isCancelled()) {
|
if (ChestShopSign.isValid(event.getBlock())) {
|
||||||
sendShopDestroyedEvent((Sign) event.getBlock().getState(), event.getPlayer());
|
sendShopDestroyedEvent((Sign) event.getBlock().getState(), event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public static void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
public static void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||||
for (Block block : getExtendBlocks(event)) {
|
for (Block block : event.getBlocks()) {
|
||||||
if (!canBlockBeBroken(block, null)) {
|
if (!canBlockBeBroken(block, null)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -87,8 +87,11 @@ public class SignBreak implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public static void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
public static void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||||
if (!canBlockBeBroken(getRetractBlock(event), null)) {
|
for (Block block : event.getBlocks()) {
|
||||||
event.setCancelled(true);
|
if (!canBlockBeBroken(block, null)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,43 +192,4 @@ public class SignBreak implements Listener {
|
|||||||
return attachedSigns;
|
return attachedSigns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Block getRetractBlock(BlockPistonRetractEvent event) {
|
|
||||||
Block block = getRetractLocationBlock(event);
|
|
||||||
return (block != null && !BlockUtil.isSign(block) ? block : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Those are fixes for CraftBukkit's piston bug, where piston appears not to be a piston.
|
|
||||||
private static BlockFace getPistonDirection(Block block) {
|
|
||||||
return block.getState().getData() instanceof PistonBaseMaterial ? ((Directional) block.getState().getData()).getFacing() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Block getRetractLocationBlock(BlockPistonRetractEvent event) {
|
|
||||||
BlockFace pistonDirection = getPistonDirection(event.getBlock());
|
|
||||||
return pistonDirection != null ? event.getBlock().getRelative((pistonDirection), 2).getLocation().getBlock() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Block> getExtendBlocks(BlockPistonExtendEvent event) {
|
|
||||||
BlockFace pistonDirection = getPistonDirection(event.getBlock());
|
|
||||||
|
|
||||||
if (pistonDirection == null) {
|
|
||||||
return new ArrayList<Block>();
|
|
||||||
}
|
|
||||||
|
|
||||||
Block piston = event.getBlock();
|
|
||||||
List<Block> pushedBlocks = new ArrayList<Block>();
|
|
||||||
|
|
||||||
for (int currentBlock = 1; currentBlock < event.getLength() + 1; currentBlock++) {
|
|
||||||
Block block = piston.getRelative(pistonDirection, currentBlock);
|
|
||||||
Material blockType = block.getType();
|
|
||||||
|
|
||||||
if (blockType == Material.AIR) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pushedBlocks.add(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pushedBlocks;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user