1.15.2 Get top inventory from InventoryView

Discussion in 'Spigot Plugin Development' started by NeumimTo, Jan 17, 2020.

  1. I created inventory instance with Bukkit.createInventory(player, 6 * 9, title); and made the client to view the inventory.

    Later, while the player is still viewing the inventory, i need to get its instance.

    InventoryView openInventory = player.getOpenInventory();
    ... = openInventory.getTopInventory();

    I have assumed, that the inventory which i get by calling getTopInventory will be the one i have previously created - double chest one, with 54 slots.

    But apparently the inventory is type of CRAFTING, with total size of 5 slots.

    How am i supposed to solve this?
    - I dont want to re-create a new inventory, as this action always puts mouse cursor in the middle of the screen.
    - Am i supposed to put the 54slots inventory into the cache and lookup the cache instead of calling getOpenInventory(), does the spigot Inventory object holds reference to a player somwhere, that would mean i have to remove the inventory object from cache when player quits, dies, changes worlds etc?
    - Is this not indended behavior, in the first place?
  2. In a quick test that I made, the intended behaviour was shown...
    Code (Java):
    final Inventory inv = Bukkit.createInventory(player, 9*6, "custom inv");
    final InventoryView view = player.getOpenInventory();
    correctly prints out "CHEST" and "PLAYER".
    How are you setting the inventory of a player?
    If you get an Inventory of type "CRAFTING", this means that the InventoryView is the view of the standard player inventory.
    • Agree Agree x 3
  3. I'd gladly help but I think I didn't understand.

    1. you create an inventory named "inv".
    2. the player opens another inventory (his own?)
    3. you want to show the inventory "inv" again.

    is this correct? If you can clear things up, I may be able to help you
  4. I was a bug in paper, after updating to latest build the problem has dissapeared