Solved Inventory Name Deprecation

Discussion in 'Spigot Plugin Development' started by Qhucy, Jan 18, 2020.

  1. Hello,

    Inventory#getTitle() and Inventory#getName() are both deprecated methods under the Inventory object. What is the more correct way that I am supposed to use to get the name of an inventory by only having the Inventory object? (this is not done from an InventoryEvent where the event itself gives you a better option)
  2. drives_a_ford


    Read the javadocs for Inventory#getName and Inventory#getTitle and use InventoryView#getTitle instead as they both suggest.
  3. Yes this is true but you can't get an inventory's view from a single Inventory object, you can however get it from an InventoryEvent like I mentioned previously but the question is if there is a way you can get the name of an Inventory directly from an InventoryObject that is recommended (i.e. not deprecated).
  4. drives_a_ford


    I'm fairly certain you're looking at this all wrong to begin with.

    What you want to do is identify an inventory that is your custom inventory, right?
    Just keep a set of your custom (and currently in use) inventory instances and check if a certain inventory is within that set. Once an inventory isn't in use (i.e inventory is closed), just remove it from the set. And if a new one gets brought up, add it to the set.
  5. Much better to use InventoryHolder to identify inventories.
  6. The inventory holder is null.

    So instead of identifying it per name, identify it per inventory instance (object)? I think I will use this method instead then if its the better way to do it.

    Thank you for your replies.
  7. Then make it not null?
  8. Using an InventoryHolder to distinguish between different inventories is hacky and isn’t what it was intended for. You should avoid doing this if you ever hope to have forwards compatibility.
    • Informative Informative x 1
  9. How should inventories be compared then?
  10. I mean inventory to inventory comparisons use .equals() if that’s what you’re asking. They can be used as HashMap keys as well in a more practical use case.