Implementing Inventory vs InventoryHolder

Discussion in 'Plugin Development' started by Googlelover1234, Apr 29, 2018.

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

    Googlelover1234

    Hey there, at the moment, I'm attempting to create a simple GUI that will be shown to players when they run a command. To achieve this, I've created my own class which holds a few methods to populate the inventory and all that good stuff, and this works fine. However, when I want to check for click events, I don't want to check for the title of the inventory as that seems a little hacky. I've looked at this thread, which suggests making your GUI class implement InventoryHolder, but I'm wondering if it is a particularly a bad idea to implement Inventory instead.

    Essentially, all I'd have to do at the beginning of my InventoryClickEvent is

    Code:
    if (e.getInventory() instanceof SentenceGUI) return;
    in order to ensure that it is an inventory that I want to check.

    Thank you in advance for any tips or advice.
     
  2. Offline

    Sploon

    The easiest way is probably just a HashMap:
    Code:
    HashMap<Inventory, GUI_Class> map ...;
    
    // in InventoryClickEvent
    GUI_Class gui = map.get(event.getClickedInventory());
    if(gui != null) {
       ...
    }
     
Thread Status:
Not open for further replies.

Share This Page