Skip to content

Commit

Permalink
Fix piston extension/retraction not being cancelled with redstone flag
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Dec 2, 2023
1 parent bff8aec commit cdd3f00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "dev.booky"
version = "1.0.2-SNAPSHOT"
version = "1.0.3-SNAPSHOT"

val plugin: Configuration by configurations.creating {
isTransitive = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,27 +197,34 @@ public void onRedstone(BlockRedstoneEvent event) {
}
}

private boolean onPiston(Block piston, Iterable<Block> moved) {
private boolean checkPiston(Block piston, Iterable<Block> moved) {
if (this.manager.isProtected(piston, ProtectionFlag.REDSTONE, null)) {
return true;
return false;
}

for (Block block : moved) {
if (this.manager.isProtected(block, ProtectionFlag.REDSTONE, null)) {
return false;
}
}
return true;

return true; // allowed
}

@EventHandler(ignoreCancelled = true)
public void onPistonExtend(BlockPistonExtendEvent event) {
this.onPiston(event.getBlock(), event.getBlocks());
boolean allowed = this.checkPiston(event.getBlock(), event.getBlocks());
if (!allowed) {
event.setCancelled(true);
}
}

@EventHandler(ignoreCancelled = true)
public void onPistonRetract(BlockPistonRetractEvent event) {
this.onPiston(event.getBlock(), event.getBlocks());
boolean allowed = this.checkPiston(event.getBlock(), event.getBlocks());
if (!allowed) {
event.setCancelled(true);
}
}

@EventHandler(ignoreCancelled = true)
Expand Down

0 comments on commit cdd3f00

Please sign in to comment.