Test if player close gui

Discussion in 'Plugin Development' started by ilian572, Jul 8, 2018.

Thread Status:
Not open for further replies.
  1. Hello, I have try a lot a things but nothing work...

    I just want to know when a player close a inventory / gui called "invPlayer".

    It's been 5 hours since I'm looking for a solution...
     
  2. Offline

    tkuiyeager1

  3. Code:
    public void onClick(InventoryClickEvent event)
        {
        @EventHandler
        public void InvClose(InventoryCloseEvent event){
            Inventory inv = event.getInventory();
            Player player = (Player) event.getPlayer();
            if(inv.getName() == "§aActuellement en trade"){
                player.sendMessage("you close your inventory");
            }
        }
    }
    And why this code don't work ? Thanks
     
  4. Online

    timtower Administrator Administrator Moderator

    @ilian572 Because you can't nest methods like that.
     
  5. Exactly, that's why I'm coming to ask you how
     
  6. Online

    timtower Administrator Administrator Moderator

    @ilian572 Why do you need the close in the click?
    Asking so we can come up with the best solution for your problem.
     
  7. I want to know when a player close an inventory called 'inv'.
    For example
    while (!(player.inventory == open))
    {
    player.sendMessage("you close your inventory");
    }
     
  8. Online

    timtower Administrator Administrator Moderator

    @ilian572 In the onClose, get the inventory, check the name.
    Don't use while loops.
     
  9. I already try with the name but it is updated just when we clic on an invnentory

    Oh! got it ! I'm going to check this

    Code:
    @EventHandler
        public void onClose(InventoryCloseEvent event){
            Inventory inv = event.getInventory();
            Player player = (Player) event.getPlayer();
            if (inv.getName() == "§aActuellement en trade"){
                player.sendMessage("you close your inventory");
            }
        }
    Like that all right?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 9, 2018
  10. Online

    timtower Administrator Administrator Moderator

    @ilian572 Strings are conpared with equals, not with ==
     
  11. All rigth, thanks. Now, I have an other problem...

    I get the hashmap "playersAccepte" from an other class with
    Code:
    @EventHandler
        public void onClose(InventoryCloseEvent event){
            Inventory inv = event.getInventory();
            Player player = (Player) event.getPlayer();
            if(inv.getName().equals("§aActuellement en trade.")){
                CommandTest CommandTestImport = new CommandTest();
              
              
                CommandTestImport.playersAccepte.remove(player);  
                //CommandTestImport.playersAccepte.remove(CommandTest.target);
            }
        }
    but I don't find how get the value of "target" and "player" in this class. This two vars are on a
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args)
    so I can't use a
    Code:
    return player;
    or
    Code:
    myFirstClass.player
    Can u enlighten me pls ? (i don't know if this word exists lmao)
     
  12. Online

    timtower Administrator Administrator Moderator

    @ilian572 Where do they even come from?
    Thread was about a close event, not targets.
     
  13. View attachment 31688
    player and target are in "CommandTest" in a
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args)
    and I want to use them in "tradeitListener". Yes it's not the subjet. Should I tag this one as "resolved" and create an other ?
    Thanks
     
    Last edited: Jul 11, 2018
Thread Status:
Not open for further replies.

Share This Page