Solved InventoryClickEvent: How can I get the new item?

Discussion in 'Bukkit Help' started by MrGameEdit, Jun 18, 2017.

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

    MrGameEdit

    I try to make a plugin where I need to get the old and the new ItemStack at the InventoryClickEvent.

    Example:

    in slot 1 is a diamond sword and I have no item to move with my cursor. I click the diamond sword
    -> new item: null, old item: diamond sword

    in slot 2 is nothing and i have the diamond sword on my cursor. I click the empty slot
    -> new item: diamond sword, old item: null


    Can someone say me how I can get the new and the old item in InventoryClickEvent? I only know that I get the old one with
    Code:
    e.getInventory().getItem(e.getRawSlot())
    and the one on the curser (the new one -> the old one from the slot)
    Code:
    e.getCurrentItem()

    And sorry if my Englisch is not the best one :)

    I solved it!
    Now I save the old item instantly and the new one after 1 tick delay
    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(
                Main.getInstance(), new Runnable() {
                @Override
                public void run() {
                    newItem = e.getInventory().getItem(e.getRawSlot());
                }
            }, 1L);
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 18, 2017
  2. Offline

    Zombie_Striker

    @MrGameEdit
    Why not just use event#getCursor to get the item on the cursor?

    If your problem has been solved, mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page