InventoryClickEvent, keeping an item in the hotbar!

Discussion in 'Plugin Development' started by TerraVale, May 12, 2013.

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

    TerraVale

    I haven't yet worked with much inventory related stuff, and have thus messed around with it quite a bit before posting. I'm working with the InventoryClickEvent and wish to keep my custom item within the hotbar. To some it might seem simple, however here's a very basic snippet of code to show what I want to accomplish:

    Code:JAVA
    1.  
    2.  
    3. @EventHandler
    4. public void onPlayerClick(InventoryClickEvent event)
    5. {
    6. if (event.getCursor().getTypeId() == 403 && event.getCursor().getItemMeta().getLore() != null)
    7. {
    8. if (!event.getSlotType().equals(SlotType.QUICKBAR))
    9. {
    10. event.setCancelled(true);
    11. }
    12. }
    13. }
    14.  
    15.  


    It works fine, aside from the fact that the player's inventory doesn't actually update when you're clicking outside of the quickbar on an open slot. The item then stays there until you close your inventory, then drops. When you pick it up, there's then a leftover copy of the item in your inventory until you update your inventory -- it then is back to normal. I would like for the item to either:

    1. Be added back into the quickbar when the inventory updates one way or another. This method may not be seamless as far as visuals, but it is effective.

    2. Be added back onto the cursor, totally preventing the user from placing the item anywhere else but their quickbar. It worked fine with a manual update using player.updateInventory();, however that method is deprecated.

    All help is much appreciated. In the mean time, I will continue experimenting!
    Here's the javadoc for reference: InventoryClickEvent

    EDIT: I'm now wondering. Since player.updateInventory(); is deprecated yet still works flawlessly for myself, would it hurt to use it?
     
Thread Status:
Not open for further replies.

Share This Page