Solved InventoryClickEvent fired before or "after" it takes place?

Discussion in 'Plugin Development' started by KILL3RTACO, Oct 18, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    KILL3RTACO

    Hey Bukkit, long no time no develop..

    I need some clarification about a particular event (InventoryClickEvent) as the language for events in general can be quite confusing. The reason for my asking: I am currently working on some virtual inventory/menu apis (I've done it before, but back then I wasn't as experienced and now I want to make the APIs more versatile)

    I assume that because this event can be cancelled, it is fired before the game state is changed, tested if it was cancelled, and then the game state is changed accordingly.

    The ItemStacks stored via getCursor() and getCurrentItem() are nice, but there doesn't seem to be a way to easily get the result of what is going to happen. For instance, if the InventoryAction is PLACE_ALL, are the items being placed going to be located at getCursor() (because those are the items being placed) or are they going to be located at getCurrentItem() (because that's where the items are going to end up). Similarly, if the InventoryAction is PLACE_SOME or PICKUP_SOME, how am I to tell what 'some' is?
     
    Last edited: Oct 19, 2016
  2. Offline

    Zombie_Striker

    I do not understand what you are looking at, but those enum values do not exist:
    https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/inventory/ClickType.html

    If the event is cancelable, the event is triggered before the action occurs.

    In order to know what will happen, you need to know the clicktype and whether the cursor or current item is null. Since there are four combinations of nulls and thirteen different enum values, I would recommend only looking for specific combinations (e.g. only LEFT or RIGHT clicking, and canceling the event for all other enum values.)
     
  3. Offline

    KILL3RTACO

    Last edited: Oct 19, 2016
  4. Offline

    Lordloss

    Are there any further questions now or is this thread solved?
     
  5. Offline

    KILL3RTACO

    Well, some of my questions weren't exactly answered. Most of what I wanted to know comes from the following:
     
  6. Offline

    Zombie_Striker

    @KILL3RTACO
    If you read all the enum values, you should be able to figure out the results:
    1. PICKUP_ALL will only be triggered if the item will be put into the cursor.
    2. For the PLACE and PICKUP_SOME values, these are options where the amount of not any of the other values (if it is not One, Half, or All). Although I do not know how this would happen, I am going to assume this would require help from plugins/mods in order to be achieved. If you would like to make sure they are never called, try clicking around to figure out when it will be called. In short, don't worry about this.
     
  7. Offline

    KILL3RTACO

    I had a silly question, I know but thank you for the clarification and for your patience.

    I wasn't sure either, but I thought someone may have.
     
  8. Offline

    Lordloss

    Btw it would have been much easier to simply make some debug messages and check it yourself.
     
Thread Status:
Not open for further replies.

Share This Page