Checking if a command with args has been executed

Discussion in 'Plugin Development' started by Praxounet, Jan 1, 2019.

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

    Praxounet

    So hum, I'm making a party plugin, in which the player has to invite a player, and then the other player has to accept the request.

    So, my question is : how to I check if a command with arguments has been executed ?

    For exemple :

    The Player A is the one who wants to create the party. He has to execute the command /party invite PlayerB in order to invite Player B. Player B has to execute the command /party join in order to join the party. But he can't do it unless the Player A has invited him. How do I check if the Player A invited the specific player ?

    Here is my code of the /party invite <nickname>

    Code:
    Player player = (Player)sender;
          
          
          
            if (cmd.getName().equalsIgnoreCase("party")) {
                if (args.length == 2) {
                  
                    Player p = Bukkit.getPlayer(args[1]);
                  
                    if (args[0].equalsIgnoreCase("invite")) {
                      
                        if (p != null) {
                         player.sendMessage("§6[Party]" + " " + ChatColor.WHITE + p.getName() + " a bien été invité !");
                         p.sendMessage("§6[Party]" + " " + ChatColor.WHITE + player.getName() + " vous a invité !");
                  
                       
                       
                          
                            return true;
                        }
                    }
                }

    Any ideas ?
     
    Last edited: Jan 1, 2019
  2. Offline

    KarimAKL

    @Praxounet I would probably use a HashMap<UUID, UUID> (or HashMap<UUID, List<UUID>> in case you want players to be able to invite multiple players at the same time)
    Then put PlayerA as a key to the hashmap and then PlayerB as the value to PlayerA.
    Anything else you need help with?
     
  3. Offline

    DontActLikeMe

    If im understanding correctly,(this is how i do it) i use two accounts to make sure my invite and join commands are working. Besides that, idk if you can ever truly see it work unless you do that. With other commands that require just one player, i broadcast variables to the server to make sure variables are going in the right place or are reacting correctly etc. Sure you can hashmap the variables as karim says, but how do you get a player if a player is not online to begin with, so you would have 2 players anyway also that doesn't show you if your invite/join message is displaying properly etc.
     
    Last edited: Jan 2, 2019
Thread Status:
Not open for further replies.

Share This Page