1.12.2 How to stop item move, in inventory, with 1-9 number keys.

Discussion in 'Spigot Plugin Development' started by Shadowty1232, Jun 27, 2021.

  1. As explained in the title, I'm unable to find a way to stop this. I've straight up cancelled the ItemClickEvent and tried to check if they ClickType is NUMBER_KEY or not. Both still not working.

    For further explanation, I need help with cancelling the move even when you have your item in slot 1, then go to another item and press the 1 key to move it away. Any ideas?

    Here's my code:

    Code (Java):
    public void onItemClickInGUI(InventoryClickEvent e) {

        if (!(e.getWhoClicked() instanceof Player)) return;

        Player p = (Player) e.getWhoClicked();
        ItemStack item = e.getCurrentItem();

        if (item.getType() != Material.valueOf((String) config.get("Backpack.Material"))) return;

        NBTItem nbtItem = new NBTItem(item);

        if (nbtItem.getString("id").equals("")) return;

        if (!e.getInventory().getTitle().equals(backpackStorage.get(nbtItem.getString("id")).getTitle())) return;



    #1 Shadowty1232, Jun 27, 2021
    Last edited: Jun 27, 2021
  2. Just for reference, the item does actually cancel the move event normally, just having a problem with the number key issue.
  3. not equls use equalsIgnoreCase
    • Funny Funny x 1
  4. ?

    Everything works fine just not the number thing
  5. InventoryDragEvent
  6. Ty for the comment, I'll try now

    Edit: Did not work
  7. How did you try it?
  8. Exact same way as the code above, but i tried both ItemStack functions on the InvDragEvent but again none worked.
    And for the player, i got the invholder
  9. Then add debug to your code to see what's going on in each step and so making sure everything is working fine
    • Like Like x 1
  10. Acording to the javadocs, this event is only fired when an item is moved from an inventory to another

    For example, moving a diamond from a chest, into your inventory, or moving a diamond to a hopper.

    So if what the thread owner wants is to prevent moving an item from a same inventory slot, to another same inventory slot, this event does nothing
  11. I've literally done everything and search it up almost everywhere that matters, and for some reason cannot find a solution. Oh and I have debugged the code, add msgs etc, and everything works it just doesnt do what I want it to do.