This commit is contained in:
Ilya 2022-02-15 17:36:56 +03:00
parent 14afabd37d
commit c891bdf3ad

View File

@ -82,7 +82,7 @@ public class WorldListener implements Listener {
List<Block> toBreak = checker.getBrokenBlocksObjects(); List<Block> toBreak = checker.getBrokenBlocksObjects();
if (isMovable) { if (isMovable) {
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) continue; if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak),piston.getFacing())) continue;
for (Block block1 : toBreak) { for (Block block1 : toBreak) {
block1.breakNaturally(); block1.breakNaturally();
} }
@ -193,7 +193,7 @@ public class WorldListener implements Listener {
} }
if (isMovable) { if (isMovable) {
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) return; if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak),piston.getFacing())) return;
Collections.reverse(blocks); Collections.reverse(blocks);
for (Block block1 : toBreak) { for (Block block1 : toBreak) {
block1.breakNaturally(); block1.breakNaturally();
@ -264,7 +264,7 @@ public class WorldListener implements Listener {
List<Block> toBreak = checker.getBrokenBlocksObjects(); List<Block> toBreak = checker.getBrokenBlocksObjects();
if (isMovable) { if (isMovable) {
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) continue; if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak),piston.getFacing())) continue;
for (Block block1 : toBreak) { for (Block block1 : toBreak) {
block1.breakNaturally(); block1.breakNaturally();
} }
@ -362,7 +362,7 @@ public class WorldListener implements Listener {
} }
if (isMovable) { if (isMovable) {
if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak))) return; if(!isBlocksAllowedToInteract(copyWithAdd(blocks,toBreak),piston.getFacing())) return;
Collections.reverse(blocks); Collections.reverse(blocks);
for (Block block1 : toBreak) { for (Block block1 : toBreak) {
block1.breakNaturally(); block1.breakNaturally();
@ -403,7 +403,7 @@ public class WorldListener implements Listener {
return 12; return 12;
} }
public boolean isBlocksAllowedToInteract(List<Block> blocks) { public boolean isBlocksAllowedToInteract(List<Block> blocks, BlockFace bf) {
WorldGuardPlugin wg = ExtendedPistons.INSTANCE.wg; WorldGuardPlugin wg = ExtendedPistons.INSTANCE.wg;
RegionContainer container = wg.getRegionContainer(); RegionContainer container = wg.getRegionContainer();
RegionQuery query = container.createQuery(); RegionQuery query = container.createQuery();
@ -411,6 +411,9 @@ public class WorldListener implements Listener {
boolean state = query.testState(block.getLocation(),(Player)null, DefaultFlag.PISTONS); boolean state = query.testState(block.getLocation(),(Player)null, DefaultFlag.PISTONS);
if(!state) if(!state)
return false; return false;
state = query.testState(block.getRelative(bf).getLocation(),(Player)null, DefaultFlag.PISTONS);
if(!state)
return false;
} }
return true; return true;
} }