Chat listeners with commands

Discussion in 'Plugin Development' started by Herowise, Feb 14, 2016.

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


    I want to start a Chat listener but the method will be called Only if a certain command is typed and have a cool down , after that the chat listener will close down.
    Do u guys have any idea what to do here?
  2. Offline


    You can create a class implemeting Listener and the event AsyncPlayerEvent, then create a map with something like Map<UUID, Action> so you will have to create an abstract class called Action or something like that and add a method like execute(Player player); so you will have to create a method to register the action and another to unregister it, also listen to player quit to remove the value from the map.

    So basically you will have to onCommand register the action, class.registerAction(player.getUniqueId(), new Action() {
    public void execute(Player player) {

    so when the player talk you will have to get the action from the map, check if it is nulll, if it is not then do the action and remove it from the map, you should for example store the System.currentMillies on the onCommand and then check the difference...

    I'm almost asleep, so i really don't know what i wrote.
  3. Offline


    @Herowise When the command is done add the player's uuid to a HashSet, when the chat event fires check if the player's uuid is in the hashset, wrap in cooldown.

    P.S. I believe what you're trying to do can be achieved through the conversation API.
  4. Offline


    This is overboard for what he wants to do.

    Assuming you already have the cooldown set up (if not, there are tons of threads about how to set it up), all you need to do for commands is check the CommandPreProccessEvent and check if the command sent is equal to the "certain command". If so, cancel the event.
Thread Status:
Not open for further replies.

Share This Page