command

Discussion in 'Plugin Development' started by isaiah8139 - BSwear, Apr 4, 2016.

Thread Status:
Not open for further replies.
  1. how can I make a command that says "PLAYER is afk" then when they type the command again it says "PLAYER is no longer afk"
    EX:

    player types /afk:
    Bukkit.broadcastMessage(event.getPlayer().getName() + " Is AFK!")}

    player types /afk again:
    Bukkit.broadcastMassage(event.getPlayer().getName() + " Is no longer AFK!")}

    I need this so I can remake http://dev.bukkit.org/bukkit-plugins/afk/ because its code gives errors beacuse the old coder did not up date it sence 1.6.2
     
    Last edited: Apr 22, 2016
  2. Offline

    mythbusterma

  3. Offline

    mcdorli

    When you have the onCommand mefhod prepared (you set the executor of the command to the current class), then first, you create an arraylist of Player UUIDs (nit players), then when someone uses your command, first you check if their UUID is inside the array, if it isn't then you put it in the arralist and you display the message, else you remove them from it, and you display the other message. If you want to make this easier, you can use the names of the players, because it is totally acceptable in this case (you don't dtore them for long)
     
  4. Offline

    xaanit

    @mcdorli

    Er, wouldn't an easier way just have a Hashmap storing the user and a Boolean, if it's false just change it to true, if it's true just change it to false.
     
  5. Offline

    mythbusterma

    @xaanit

    How is a HashMap that associates an Object to a Boolean different than a List or Set? The primary purpose is an existence check, so it would seem to me that a List or Set would be the natural choice.
     
Thread Status:
Not open for further replies.

Share This Page