Test if player close gui

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

  1. Offline

    ilian572

    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

    ilian572

    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
     
  3. Online

    timtower Ninja on the waves Moderator

    @ilian572 Because you can't nest methods like that.
     
  4. Offline

    ilian572

    Exactly, that's why I'm coming to ask you how
     
  5. Online

    timtower Ninja on the waves Moderator

    @ilian572 Why do you need the close in the click?
    Asking so we can come up with the best solution for your problem.
     
  6. Offline

    ilian572

    I want to know when a player close an inventory called 'inv'.
    For example
    while (!(player.inventory == open))
    {
    player.sendMessage("you close your inventory");
    }
     
  7. Online

    timtower Ninja on the waves Moderator

    @ilian572 In the onClose, get the inventory, check the name.
    Don't use while loops.
     
  8. Offline

    ilian572

    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
  9. Online

    timtower Ninja on the waves Moderator

    @ilian572 Strings are conpared with equals, not with ==
     
  10. Offline

    ilian572

    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)
     
  11. Online

    timtower Ninja on the waves Moderator

    @ilian572 Where do they even come from?
    Thread was about a close event, not targets.
     
  12. Offline

    ilian572

    upload_2018-7-11_18-53-38.png
    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 at 10:30 AM

Share This Page