1.15.2 Bukkit.createInventory(InventoryHolder,InventoryType) for InventoryType.DISPENSER

Discussion in 'Spigot Plugin Development' started by AlonsoAliaga, Jan 29, 2020.

  1. I tried using a custom class that implements InventoryHolder and use
    Code (Java):
    Bukkit.createInventory(new MyClass(),InventoryType.DISPENSER,"Title")
    But when checking the inventory holder, it returns null.

    However, when using
    Code (Java):
    Bukkit.createInventory(new MyClass(), 9,"Title")
    It works correctly, is that normal? Or i should be doing something different?
     
  2. Why do you need the inventory holder at first place? Some storage mumbo-jumbo in order to prevent other players from accesing that inventory?
     
  3. Probably to uniquely identify this inventory with instanceof or something.

    To OP: It is not recommended to create your own inventoryholder. Use a set or map to identify your inventories.
     
  4. Or Player#getInventoryView#getTitle
     
  5. Yes. But that can be messy if either the inventory title is used for custom text eg. a description or ID numbers etc. or if the server allows access to eg. custom items with custom names, players can create chests with similar names and mess stuff up.
     
  6. Yes to check specific inventories, for example my plugin gui.
    Using title is not an option.

    I'd like to know if it's only not working for me. If its not working for anyone i guess ill just use a chest inventory type.
     
  7. Again, you should not be doing this. People using the spigot API correctly will not have this problem, do not make your own class implement InventoryHolder. Save it somewhere else instead.