package org.paolo565.drills.listeners;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;

public class PlayerListener implements Listener {
    @EventHandler
    public void onPlayerInventoryEvent(InventoryClickEvent event) {
        if(!(event.getWhoClicked() instanceof Player)) {
            return;
        }

        Player player = (Player) event.getWhoClicked();
        InventoryView openInventory = player.getOpenInventory();
        ItemStack clickedStack = event.getCurrentItem();
        Inventory clickedInventory = event.getClickedInventory();
        InventoryAction action = event.getAction();
        if(openInventory.getType() == InventoryType.FURNACE && clickedInventory != null && clickedInventory.getType() != InventoryType.FURNACE
                && action == InventoryAction.MOVE_TO_OTHER_INVENTORY && clickedStack.getType() == Material.SUGAR_CANE) {
            ItemStack furnaceSlot = openInventory.getItem(1);
            int count;

            if(furnaceSlot == null || furnaceSlot.getType() == Material.AIR) {
                count = 0;
            } else if(furnaceSlot.getType() == Material.SUGAR_CANE) {
                count = furnaceSlot.getAmount();
            } else {
                return;
            }
            event.setCancelled(true);

            int insert = 64 - count;
            insert = clickedStack.getAmount() > insert ? insert : clickedStack.getAmount();
            furnaceSlot.setType(Material.SUGAR_CANE);
            furnaceSlot.setAmount(count + insert);
            openInventory.setItem(1, furnaceSlot);

            if(insert == clickedStack.getAmount()) {
                clickedStack.setType(Material.AIR);
            } else {
                clickedStack.setAmount(clickedStack.getAmount() - insert);
            }
            clickedInventory.setItem(event.getSlot(), clickedStack);
        }
    }
}

@@ -162,24 +162,69 @@
 t.Listener;%0A
+import org.bukkit.event.inventory.ClickType;%0A
 import org.b
@@ -262,16 +262,16 @@
 Action;%0A
-
 import o
@@ -1023,88 +1023,1887 @@
  if(
-openInventory.getType() == InventoryType.FURNACE && clickedInventory != null && 
+clickedInventory == null %7C%7C openInventory.getType() != InventoryType.FURNACE) %7B%0A            return;%0A        %7D%0A%0A        if(clickedInventory.getType() == InventoryType.FURNACE && event.getSlot() == 1%0A                && player.getItemOnCursor().getType() == Material.SUGAR_CANE && action == InventoryAction.NOTHING) %7B%0A            event.setCancelled(true);%0A            ItemStack cursorStack = player.getItemOnCursor();%0A            player.setItemOnCursor(openInventory.getItem(1));%0A            openInventory.setItem(1, cursorStack);%0A        %7D else if(clickedInventory.getType() == InventoryType.FURNACE && event.getSlot() == 1%0A                && player.getItemOnCursor().getType() == Material.SUGAR_CANE && (action == InventoryAction.PLACE_ALL%0A                %7C%7C action == InventoryAction.PICKUP_ALL %7C%7C action == InventoryAction.PLACE_ONE)) %7B%0A            event.setCancelled(true);%0A            ItemStack furnaceSlot = openInventory.getItem(1);%0A            int space = 0;%0A%0A            if(furnaceSlot == null %7C%7C furnaceSlot.getType() == Material.AIR) %7B%0A                space = 64;%0A            %7D else if(furnaceSlot.getType() == Material.SUGAR_CANE) %7B%0A                space = 64 - furnaceSlot.getAmount();%0A            %7D%0A%0A            if(space %3E 0) %7B%0A                int toPlace = event.getClick() == ClickType.RIGHT ? 1 : player.getItemOnCursor().getAmount();%0A                if(space %3C toPlace) %7B%0A                    toPlace = space;%0A                %7D%0A%0A                openInventory.setItem(1, new ItemStack(Material.SUGAR_CANE, furnaceSlot.getAmount() + toPlace));%0A                if(toPlace == player.getItemOnCursor().getAmount()) %7B%0A                    player.setItemOnCursor(new ItemStack(Material.AIR));%0A                %7D else %7B%0A                    player.getItemOnCursor().setAmount(player.getItemOnCursor().getAmount() - toPlace);%0A                %7D%0A            %7D%0A        %7D else if(
 clic

Allow the player to interact with the fuel slot inside the furnace with sugar canes on cursor