if(!EventUtil.passesFilter(event)) return;
if(event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) return;
ChangedSign sign = event.getSign();
if(!sign.getLine(1).equals("[Cook]")) return;
CraftBookPlugin.inst().getSelfTriggerManager().registerSelfTrigger(event.getClickedBlock().getLocation());
LocalPlayer p = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block b = SignUtil.getBackBlock(event.getClickedBlock());
Block cb = b.getRelative(0, 2, 0);
if (cb.getType() == Material.CHEST) {
Player player = event.getPlayer();
if(!player.hasPermission("craftbook.mech.cook.refuel")) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
p.printError("mech.restock-permission");
event.setCancelled(true);
return;
}
if(!ProtectionUtil.canUse(event.getPlayer(), event.getClickedBlock().getLocation(), event.getBlockFace(), event.getAction())) {
if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
p.printError("area.use-permissions");
return;
}
if (ItemUtil.isStackValid(player.getItemInHand()) && Ingredients.isIngredient(player.getItemInHand().getType())) {
Material itemID = player.getItemInHand().getType();
increaseMultiplier(sign, Ingredients.getTime(itemID));
if (player.getItemInHand().getAmount() <= 1) {
player.setItemInHand(null);
} else {
player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
}
if(itemID == Material.LAVA_BUCKET && !cookingPotDestroyBuckets)
player.getInventory().addItem(new ItemStack(Material.BUCKET, 1));
p.print("mech.cook.add-fuel");
event.setCancelled(true);
} else if (cookingPotSignOpen) {
player.openInventory(((Chest) cb.getState()).getBlockInventory());
event.setCancelled(true);
}
}
if(sign.hasChanged())
sign.update(false);
} else {
event.getPlayer().setFireTicks(getMultiplier(sign)+40);
LocalPlayer player = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());
player.printError("mech.cook.ouch");
}