Accounting for all click events

Discussion in 'Spigot Plugin Development' started by Hunky524, May 16, 2016.

  1. I have a question regarding inventory menus. Part of a plugin I am developing requires the players to navigate shops by inventory GUIs. However, every time I think I have accounted and stopped the player from being able to put an item into the menu, I find another way to do it. Whether it is shift clicking, right clicking, or dragging an item across the GUI while clicking, there always seems to be another way I find to put items into the GUI. Does anyone know if there is a list of all possible scenarios I can account for, or a nice method I might have thought of, that accounts for all issues? Thanks in advanced :)
     
  2. First you want to check if the player is in that specific inventory that you want to cancel.
    When they try to interact with that inventory, check the inventory action.

    Code (Text):
    public enum InventoryAction {
        NOTHING,
        PICKUP_ALL,
        PICKUP_SOME,
        PICKUP_HALF,
        PICKUP_ONE,
        PLACE_ALL,
        PLACE_SOME,
        PLACE_ONE,
        SWAP_WITH_CURSOR,
        DROP_ALL_CURSOR,
        DROP_ONE_CURSOR,
        DROP_ALL_SLOT,
        DROP_ONE_SLOT,
        MOVE_TO_OTHER_INVENTORY,
        HOTBAR_MOVE_AND_READD,
        HOTBAR_SWAP,
        CLONE_STACK,
        COLLECT_TO_CURSOR,
        UNKNOWN;

        private InventoryAction() {
        }
    }
    You only want to allow inventory actions that do not allow interactions with the top inventory.
    You also want to cancel all events where the clicked inventory's holder is not the player's inventory holder.
     
  3. Well, that is definitely a list of inventory actions. Thanks, I will try this when I get home. Just out of curiosity, will those events stop inventory actions like shift clicking? Or would the MOVE_TO_OTHER_INVENTORY account for that? I am not at home at my computer right now, that's why I ask.
     
  4. There's an action for everything. If you really want to test, make a temporary event that prints the action and then just mess around with inventories and watch the console.
     
  5. Yea, that's what I was planning on doing. I'll have to mess around with stuff when I get home. Thanks for you help :)