mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 04:25:14 +01:00
Add old piston checks back in for backwards compatibility. (Fixes #91)
These checks are completely unsupported though!
This commit is contained in:
parent
7c9dd5c3f3
commit
d84313716f
@ -77,7 +77,7 @@ public class SignBreak implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public static void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||
for (Block block : event.getBlocks()) {
|
||||
for (Block block : getExtendBlocks(event)) {
|
||||
if (!canBlockBeBroken(block, null)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -87,7 +87,7 @@ public class SignBreak implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public static void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||
for (Block block : event.getBlocks()) {
|
||||
for (Block block : getRetractBlocks(event)) {
|
||||
if (!canBlockBeBroken(block, null)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -192,4 +192,55 @@ public class SignBreak implements Listener {
|
||||
return attachedSigns;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Block> getRetractBlocks(BlockPistonRetractEvent event) {
|
||||
try {
|
||||
return event.getBlocks();
|
||||
} catch (NoSuchMethodError outdated) { // backwards compatiblity
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
Block block = getRetractLocationBlock(event);
|
||||
if (block != null && !BlockUtil.isSign(block)) {
|
||||
blocks.add(block);
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
|
||||
//Those are fixes for a very old 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) {
|
||||
try {
|
||||
return event.getBlocks();
|
||||
} catch (NoSuchMethodError outdated) { // backwards compatiblity
|
||||
BlockFace pistonDirection = getPistonDirection(event.getBlock());
|
||||
|
||||
if (pistonDirection == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Block piston = event.getBlock();
|
||||
List<Block> pushedBlocks = new ArrayList<>();
|
||||
|
||||
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