Solved how to get clicked inventory name

Discussion in 'Plugin Development' started by Cat 700, Mar 12, 2020.

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

    Cat 700

    I can't find anything on how to get clicked inventory name since getname doesn't work (1.15) and all I can find is event.getview.getTitle() and that doesn't work for getting the inventory the player clicked in
     
  2. Offline

    Machine Maker

    What do you mean InventoryEvent#getView()#getTitle() doesn't work? It should work for the InventoryView the player is currently clicking in
     
  3. Offline

    Cat 700

    @Machine Maker it works but I want the inventory the player clicked in not the inventory the player is viewing

    if that is not possible then I would at least like to know how to make certain slots not be canceled by the event and also how to make it not work for the players inventory.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 12, 2020
  4. Offline

    Machine Maker

    @Cat 700 you only *ever* see 1 name, the name at the top. So the bottom inventory doesn't actually have a name.

    If you want to know what inventory they clicked in, you can get the type of inventory they clicked with InventoryEvent#getInventory()#getType(). Here is a list of inventory types
     
  5. Offline

    KarimAKL

    @Cat 700 You don't really seem to be very specific but, i guess something like this should work for what you specified:
    Code:Java
    1. @EventHandler
    2. private void onClick(InventoryClickEvent event) {
    3. List<Integer> slots = Arrays.asList(0, 5, 8, 17, 32, 53); // Slots to cancel
    4.  
    5. if (slots.contains(event.getRawSlot())) event.setCancelled(true); // Cancel if the slot clicked is in the list
    6. }
     
  6. Offline

    Cat 700

    oh that's smart
     
Thread Status:
Not open for further replies.

Share This Page