Saving getCursor() to variable

Discussion in 'Plugin Development' started by wand555, Jul 1, 2019.

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

    wand555

    Hello,
    I'm trying to save the cursor from the InventoryClickEvent when the player clicks on a specific slot in a custom inventory.
    While using getCurrentItem() would appear to make more sense here, I actually want a "live update" and getCurrentItem() is only called after another click, unlike getCursor(). I want to use the two variables to build a new item from the given type (either the first or second slot).
    I started by initializing the two variables before the event is called:
    Code:
        public ItemStack olditemtype3 = new ItemStack(Material.AIR);
        public ItemStack olditemtype5 = new ItemStack(Material.AIR);
    Then I'm checking if the player has clicked in the first specific slot:
    Code:
    if(event.getRawSlot() == 3) {
                        if(cursor.getType().equals(Material.AIR) == false) {
                            olditemtype3 = cursor;
                            System.out.println(olditemtype5 + " THIS IS 5");
                            System.out.println(olditemtype3.getType() + " in 3");
                        }
                    }
    Same goes for the other slot:
    Code:
                    else if(event.getRawSlot() == 5) {
                        if(cursor.getType().equals(Material.AIR) == false) {
                            System.out.println("sdgfhdrhwgtqehetkztjertd");
                            olditemtype5 = cursor;
                            System.out.println(olditemtype3 + " THIS IS 3");
                            System.out.println(olditemtype5.getType() + " in 5");
                        }
                    }
    (Note: First slot is the third slot in the inventory and the second slot is the fith slot in the inventory)
    Now if I try and go through it slowly and look at the config messages, this happens:
    1. I put an item into the first slot.
    Screenshot_1.png
    So far so good, makes perfectly sense. In the 5th slot there's AIR, because that's what it's initialized with and I haven't assigned it to something else yet.
    2. I put an item into the second slot.
    Screenshot_2.png Now the ItemStackType (Material) in the first slot is AIR, however it still has all the meta information stored.
    And the second slot works fine.
    I also tried it the other way around and got the inverted result, what a surprise.

    My question is, why the Material changes all of a sudden and if there's another way to store these information.

    Btw: I would reassign both variables once the new item is created and I don't need the information (basically reset it)
     
  2. Offline

    wand555

Thread Status:
Not open for further replies.

Share This Page