Skip to content

Commit

Permalink
Ensure all blocks moved by pistons are checked for protections
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed Feb 27, 2019
1 parent a05860e commit 09f368f
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions src/main/java/com/griefcraft/listeners/LWCBlockListener.java
Expand Up @@ -46,7 +46,6 @@
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.type.Chest;
import org.bukkit.block.data.type.Piston;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -304,18 +303,14 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event) {
return;
}
LWC lwc = this.plugin.getLWC();
Block pistonBlock = event.getBlock();
Piston piston = null;
try {
piston = (Piston) pistonBlock.getBlockData();
} catch (ClassCastException e) {
return;
}
BlockFace facing = piston.getFacing();
Block pulledBlock = pistonBlock.getRelative(facing).getRelative(facing);
Protection protection = lwc.findProtection(pulledBlock);
if (protection != null) {
event.setCancelled(true);
for (Block block : event.getBlocks()) {
if (lwc.isProtectable(block)) {
Protection protection = lwc.findProtection(block);
if (protection != null) {
event.setCancelled(true);
return;
}
}
}
}

Expand All @@ -324,19 +319,15 @@ public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (!LWC.ENABLED || event.isCancelled()) {
return;
}
LWC lwc = plugin.getLWC();
Block pistonBlock = event.getBlock();
Piston piston = null;
try {
piston = (Piston) pistonBlock.getBlockData();
} catch (ClassCastException e) {
return;
}
BlockFace facing = piston.getFacing();
Block pushedBlock = pistonBlock.getRelative(facing);
Protection protection = lwc.findProtection(pushedBlock);
if (protection != null) {
event.setCancelled(true);
LWC lwc = this.plugin.getLWC();
for (Block block : event.getBlocks()) {
if (lwc.isProtectable(block)) {
Protection protection = lwc.findProtection(block);
if (protection != null) {
event.setCancelled(true);
return;
}
}
}
}

Expand Down

0 comments on commit 09f368f

Please sign in to comment.