if (!EventUtil.passesFilter(event))
return;
if(event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
LocalPlayer player = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());
ChangedSign sign = event.getSign();
if (!sign.getLine(1).equals("[Gate]") && !sign.getLine(1).equals("[DGate]")) return;
boolean smallSearchSize = sign.getLine(1).equals("[DGate]");
ItemInfo gateBlock = getGateBlock(sign, smallSearchSize);
if (CraftBookPlugin.inst().getConfiguration().safeDestruction && (gateBlock == null || gateBlock.getType() == Material.AIR || gateBlock.getType() == player.getHeldItemInfo().getType()) && isValidGateBlock(sign, smallSearchSize, player.getHeldItemInfo(), false)) {
if (!player.hasPermission("craftbook.mech.gate.restock")) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
player.printError("mech.restock-permission");
return;
}
int amount = 1;
if (event.getPlayer().isSneaking())
amount = Math.min(5, event.getPlayer().getItemInHand().getAmount());
addBlocks(sign, amount);
if (!(event.getPlayer().getGameMode() == GameMode.CREATIVE))
if (event.getPlayer().getItemInHand().getAmount() <= amount)
event.getPlayer().setItemInHand(null);
else
event.getPlayer().getItemInHand().setAmount(event.getPlayer().getItemInHand().getAmount() - amount);
player.print("mech.restock");
event.setCancelled(true);
return;
}
if (!player.hasPermission("craftbook.mech.gate.use")) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
player.printError("mech.use-permission");
return;
}
if(!ProtectionUtil.canUse(event.getPlayer(), event.getClickedBlock().getLocation(), event.getBlockFace(), event.getAction())) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
player.printError("area.use-permissions");
return;
}
if (toggleGates(player, event.getClickedBlock(), smallSearchSize, null))
player.print("mech.gate.toggle");
else
player.printError("mech.gate.not-found");
event.setCancelled(true);
}