Skip to content
Permalink
Browse files

Cleanup piston protection code.

  • Loading branch information...
me4502 committed Dec 25, 2018
1 parent 4e672c3 commit 3052d23f3a91e151c12e9761f2b9a801b98568fc
Showing with 16 additions and 11 deletions.
  1. +16 −11 src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java
@@ -29,13 +29,13 @@
import org.bukkit.block.Dropper;
import org.bukkit.block.Furnace;
import org.bukkit.block.Jukebox;
import org.bukkit.block.data.type.Piston;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Directional;
import org.bukkit.material.PistonBaseMaterial;
import org.bukkit.util.Vector;

import java.util.ArrayList;
@@ -65,14 +65,19 @@ public void onSignChange(SignChangeEvent event) {
}

if(ProtectionUtil.shouldUseProtection()) {

Block pistonBlock;

if((isPiston(pistonBlock = SignUtil.getBackBlock(event.getBlock())))
|| (event.getBlock().getType() == Material.SIGN
&& (isPiston(pistonBlock = event.getBlock().getRelative(BlockFace.UP))
|| isPiston(pistonBlock = event.getBlock().getRelative(BlockFace.DOWN))))) {
PistonBaseMaterial pis = (PistonBaseMaterial) pistonBlock.getState().getData();
Block pistonBlock = null;

if (event.getBlock().getType() == Material.WALL_SIGN) {
pistonBlock = SignUtil.getBackBlock(event.getBlock());
} else if (event.getBlock().getType() == Material.SIGN) {
if (isPiston(event.getBlock().getRelative(BlockFace.DOWN))) {
pistonBlock = event.getBlock().getRelative(BlockFace.DOWN);
} else if (isPiston(event.getBlock().getRelative(BlockFace.UP))) {
pistonBlock = event.getBlock().getRelative(BlockFace.UP);
}
}
if(pistonBlock != null && isPiston(pistonBlock)) {
Piston pis = (Piston) pistonBlock.getBlockData();
Block off = pistonBlock.getRelative(pis.getFacing());
if (InventoryUtil.doesBlockHaveInventory(off)) {
if (!ProtectionUtil.canAccessInventory(event.getPlayer(), off)) {
@@ -207,7 +212,7 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS
}
} else if (bl.getType() == Material.PISTON) {

PistonBaseMaterial p = (PistonBaseMaterial) bl.getState().getData();
Piston p = (Piston) bl.getBlockData();

ChangedSign sign = getSignOnPiston(bl);

@@ -360,7 +365,7 @@ private void startPipe(Block block, List<ItemStack> items, boolean request) {

List<ItemStack> leftovers = new ArrayList<>();

PistonBaseMaterial p = (PistonBaseMaterial) block.getState().getData();
Piston p = (Piston) block.getBlockData();
Block fac = block.getRelative(p.getFacing());

if (fac.getType() == Material.CHEST || fac.getType() == Material.TRAPPED_CHEST || fac.getType() == Material.DROPPER || fac.getType() == Material.DISPENSER || fac.getType() == Material.HOPPER) {

0 comments on commit 3052d23

Please sign in to comment.
You can’t perform that action at this time.