Solved How Can i check the Name of an Custom Inventory?

Discussion in 'Spigot Plugin Help' started by CypDasHuhn, Jul 13, 2021.

  1. I want to have an Inventory where the Player can select an Item which would lead him to other Inventory's.
    My Problem is that i want to specify in which Inventory the player is clicking an Item, so i want to check the Name of the Inventory. Sadly i don't know how to do it, so here i am, asking how it goes.

    Code (Text):
    public class KitClassSelection implements Listener{
        @EventHandler
        public void Meele(InventoryClickEvent click){  
            if (!(click.getWhoClicked() instanceof Player)) return;
            Player clicker = (Player) click.getWhoClicked();
            if (){ //Here i want to Check which Name the Inventory has, This code i would need also in other
                   //Situations, so Avoiding it just by doing something other would just delay the problem.
            click.setCancelled(true);
            switch (click.getCurrentItem().getType()){
                case RED_CONCRETE:
                    //pass on a next Class
                    clicker.closeInventory();
                    break;
         
                //There would be more, but its not important in this case
                    default:
                        break;
                }
            }
        }
     
    #1 CypDasHuhn, Jul 13, 2021
    Last edited: Jul 15, 2021
  2. if (e.getInventory().getTitle() == "NAME") {

    easy :D
     
  3. ehhh thanks for the Reply, but it doesn't work. I'm making a plugin with the 1.17.1 Api, and it doesn't work. Is there a modern alternative?
    ("the method getTitle() is undefined for the type Inventory")
     
  4. Im glad i found someone with an Answer! I looked at this post, but im not quite sure what i have to do. I started making plugins just 3 days ago, but had begginer c# experience before that. What im trying to say, i don't realy know how to do an InventoryMap and what even this thing is, because i couldn't finde anything usefull when i searched about it. Could you help me? (btw ich hab gesehen das du deutsch bist, also wenn du willst kannste auch auf deutsch antworten (ist mir eig egal, wollte nur sagen))
     
  5. Code (Java):
    final Map<String, Inventory> inventoryMap = new ConcurrentHashMap<>();
    I better stick to English, since most people here don't understand German :)
     
    • Like Like x 1
  6. thank you! No more questions about java coding, just wanted to ask how i turn this thread into a solved one?
     
  7. Lol no
     
    • Funny Funny x 1
  8. use if (e.getView().getTitle().equalsIgnoreCase("your name")
     
  9. So, the getTitle() method has been removed from the Inventory interface, instead it now lives in InventoryView. You can get the inventory view using
    Code (Java):
    event.getView();
    or
    Code (Java):
    player.getOpenInventory();
    .

    But I'd just recommend storing the gui Inventory in a field or HashMap, and just check whether an inventory is your gui by simply by checking for equality.
    Code (Java):
    guiInventory.equals(event.getInventory());
     
  10. Thank you chocochoco4777 & Jannyboy11, may use it in other situations!
     
    • Friendly Friendly x 1
  11. Working with the inventory title is of course not ideal, but for beginners it is rather too difficult to work with abstract classes.