Solved Double Unknown ClickType

Discussion in 'Spigot Plugin Development' started by MrWaffleman, May 30, 2016.

  1. Basically what I'm trying to do is to limit a player from taking an item out from his/her inventory. BUT, on the other hand they can interact however they want INSIDE the inventory. I disabled all click types including DROP, CONTROL_DROP, NUMBER_KEY, WINDOW_BORDER_LEFT, WINDOW_BORDER_RIGHT, SHIFT_LEFT, SHIFT_RIGHT, and UNKNOWN. But I still one ClickType that I can use that is "double unknown". Meaning it doesn't register as a click type. It's whenever I left click (or right click I support) on an item, then drag it outside of the inventory, then left click again. I'm pretty sure the problem could be with Spigot, considering this should be ClickType.WINDOW_BORDER...

    My Solution (Which failed lol): I listened for PlayerDropEvent and I did the following code:
    Code (Text):
    public void onPlayerDrop(PlayerDropItemEvent e) {
            Player p = e.getPlayer();
            if(p.getOpenInventory() != null) {
                System.out.println("debug 1");
                if(p.getOpenInventory().getTopInventory() != null) {
                    System.out.println("debug 2");
                    Inventory inv = p.getOpenInventory().getTopInventory();
                    if(inv.getName().equals(ChatColor.GOLD + "Edit Kit")) {
                        System.out.println("debug 3");
                        ItemStack stack = e.getItemDrop().getItemStack();
    I found that this actually worked, but it had drawbacks. Whenever I clicked on the bottom inventory it added items onto the top, I only wanted it to listen for clicks on the top inventory, but there's no way of tracing the ItemStack back to the inventory...

    What I'm talking about can be shown in this relatively short GIF:


    The new problem in a GIF:

    • Informative Informative x 1
  2. Instead, you can check if the inventory clicked is null.
  3. Wow, that was pretty pathetic, I guess my problem is solved...