Move item, but dont readd: HOTBAR_MOVE_AND_READD action

Discussion in 'Plugin Development' started by Jameshobbs, Aug 3, 2014.

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



    I have setup an InventoryClickEvent in my plugin and want to modify the effects of the HOTBAR_MOVE_AND_READD InventoryAction and the HOTBAR_SWAP Inventory Action.

    Essentially I am representing my hotbar as a series of special slots that cannot be modified except from the hotkeys. I want to hover over an item in my custom inventory to remove the previous entry in the hotbar and replace it with the custom inventory item.

    Unfortunately I cant seem to figure out how to customize this event's action. Any tips on how to basically remove the effects that these two actions have and replace them with my own actions?

    Current action for HOTBAR_MOVE_AND_READD: Adds the item to the number key slot and move the item that was previously in the slot into my inventory

    Desired action for HOTBAR_MOVE_AND_READD: Clone the item that I am hovering over, leaving it in the previous slot, and replace item in the number key slot and essentially delete the previous item that was in that hotbar slot.

    Current action for HOTBAR_SWAP: Swaps Material.AIR that exists in the hotkey slot with the item I have hovered over

    Desired action for HOTBAR_SWAP: Clones the item I was hovering over leaving it in the previous slot and place the clone into the hotkey slot.


    Thanks for any help with this... been pulling my hair out over it lol.
  2. Offline


    I think what you mean is, you would check if the item is clicked. If it is cancel the event, after the event is canceled set the item into a the hotbar slot?
  3. Offline


    Basically, but I need to know which hotbar slot to place in. I did implement a temporary method, which I'm not a huge fan of, where I basically lock down moving items using left click. I think using the HOTBAR actions would be much more graceful, but it appears to not be possible to modify the effects of the action.
  4. Offline


    So... if I understood you correctly, basically you want to do this?
    1. @EventHandler(ignoreCancelled=true, priority=EventPriority.LOW)
    2. public void onInventoryClickEvent(final InventoryClickEvent event)
    3. {
    4. final InventoryAction action = event.getAction();
    5. switch (action)
    6. {
    8. case HOTBAR_SWAP:
    9. event.getWhoClicked().getInventory().setItem(event.getHotbarButton(), event.getCurrentItem().clone());
    10. event.setCancelled(true);
    11. break;
    12. default:
    13. return;
    14. }
    15. }

    + ofc some other stuff related to checking where the item is coming from... unless this should be the simplest item-duplication cheat ever, hehe :p

    (Found this thread simply because I wanted more info on when exactly HOTBAR_MOVE_AND_READD is triggered - dont worry, got that covered now - and got a bit curious of what you where trying to do -> decided to test it since I was writing InvetoryClickEvent-code at this very moment anyway...
    Oh, you might find this useful (or maybe not?)
    ...sorry if this is a too-late reply.)
Thread Status:
Not open for further replies.

Share This Page