Solved Check wich inventory is clicked

Discussion in 'Plugin Development' started by xelatercero, Dec 29, 2019.

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

    xelatercero

    I am having issues to tell wich inventory is clicked , i just testing , but for example if im checking with #event.getView().getTitle() if my inventory is clicked , the thing is yes it prints the debug message but it does even if u click the playen inventory. Which would be the best way to tell what inetory is the player clicking (custom or player inventory)
     
  2. Offline

    KarimAKL

    @xelatercero InventoryEvent#getView returns the InventoryView, the InventoryView is both inventories. (the only title is the top inventory's name)
    You can check which inventory the player clicked with something like this:
    Code:Java
    1. @EventHandler
    2. private void onClick(InventoryClickEvent event) {
    3. if (event.getSlot() < event.getView().getTopInventory().getSize()) {
    4. // The player clicked the top inventory
    5. } else {
    6. // The player clicked their own inventory
    7. }
    8. }
     
  3. Offline

    xelatercero

    @KarimAKL

    In MY CASE i did this , i know is not best way but works for what i want to do:

    PHP:
    @EventHandler
        
    public void onClickSend(InventoryClickEvent e) {
       
            
    //not using all because im just testing for now
            
    Player player = (Playere.getWhoClicked();
            
    Inventory inv e.getView().getTopInventory();
            
    InventoryView invView e.getView();
            
    System.out.println(e.getSlot());
       
       
       
            
    ItemStack clickedItem e.getCurrentItem();

            if(
    invView.getTitle().equals(Text.MAIL_ITEMS)) {
                if(
    clickedItem!=null && clickedItem.equals(Items.sendButton())) {
               
                    
    e.setCancelled(true);
                    
    player.sendMessage("cancelled");
               
                }
       
               
           
            }
       
       
       
       
       
        }
     
Thread Status:
Not open for further replies.

Share This Page