Solved Cooldown On Command

Discussion in 'Plugin Development' started by hamelech2007, May 8, 2020.

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

    hamelech2007

    I am trying to create a plugin that allows you to randomly teleport. I want to add like a cooldown so if they move then it cancels the command and if they do not move for 3 seconds then it runs the command. I am very new to programming so please make it as detailed as you can. Thanks for any help given.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @hamelech2007 When they run the command you start a BukkitRunnable for that player if none exists yet.
    In the run method of that BukkitRunnable you teleport the player.

    You also listen to the PlayerMoveEvent, if they move then you cancel the BukkitRunnable.
     
  3. Offline

    hamelech2007

    how do I listen to the event?
     
  4. Offline

    timtower Administrator Administrator Moderator

    Same way as you listen to other events, with a listener.
     
  5. Offline

    hamelech2007

    but how do I do that inside the command?
    like do I need to create an event inside the command?
     
  6. Offline

    timtower Administrator Administrator Moderator

    No, outside of the command.
    Java won't allow it to be in the command.
     
  7. Offline

    hamelech2007

    make it like in the same class?
     
  8. Offline

    timtower Administrator Administrator Moderator

    Probably the easiest as you also need access to the same map.
     
  9. Offline

    hamelech2007

    I'll try that even though I didn't fully understand the HashMap part maybe you can explain it a little bit more since I don't remember using hashmaps...
     
  10. Offline

    timtower Administrator Administrator Moderator

    UUID, BukkitTask
    Put when they run the command
    Cancel the BukkitTask when they walk, then remove the key from the map.
     
  11. Offline

    hamelech2007

    and how do I listen to an event I searched and I couldn't find an explanation....
    and how do i cancel bukkit task?
     
  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    hamelech2007

    do I need to do like
    Code:
    if(PlayerMoveEvent){
    }
    or something like that?
     
  14. Offline

    timtower Administrator Administrator Moderator

    No, you need to listen to the event, and cancel the BukkitTask inside of it.
    You will have 2 methods.
    1. The onCommand.
    2. The listener..
     
  15. Offline

    hamelech2007

    ok I don't understand how to do it maybe you can send me an example that all it does is say hi and with like 3s delay and if they move it cancels it? please
     
  16. Offline

    timtower Administrator Administrator Moderator

    No, then I would just be writing your plugin.
    Not gonna do that.
     
  17. Offline

    hamelech2007

    no I mean just see how to do it...
     
  18. Offline

    timtower Administrator Administrator Moderator

    I explained that a couple of times.
    2 steps now:
    write the onCommand
    write the listener

    Just the methods, no need to fill them yet.
     
  19. Offline

    hamelech2007

    I don't understand how to use the listener and I've what you sent me
     
  20. Offline

    timtower Administrator Administrator Moderator

    Then my suggestion is to follow a tutorial on how to use a listener.
     
  21. Offline

    hamelech2007

    by using a listener do you mean like create an event?
     
  22. Offline

    timtower Administrator Administrator Moderator

    And the thing that gets called is the listener.
    The method with the @EventHandler above it.
     
  23. Offline

    hamelech2007

    no I know how to create an event I just don't understand how to use it like when the run the command...
     
  24. Offline

    timtower Administrator Administrator Moderator

    It will run all the time.
    It works independent of the command.
     
  25. Offline

    hamelech2007

    waaaaaait I need to make it like remove them from the hashmap everytime they move right?
     
  26. Offline

    timtower Administrator Administrator Moderator

    That is why I have been saying yes.
     
  27. Offline

    hamelech2007

    ok now I understand it

    I need to make when they run the command it adds them to the hashmap then make a bukkit runable that waits 3s and then runs the command and removes them from the hashmap but if they move it removes them from the hashmap and stops the bukkit runable right?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 8, 2020
  28. Offline

    timtower Administrator Administrator Moderator

    @hamelech2007 Yes.
     
  29. Offline

    hamelech2007

    Code:
    plugin.timer.put(player.getUniqueId(), <here>);
    what do i put as the key when I add them to the Hashmap?
     
  30. Offline

    timtower Administrator Administrator Moderator

    That would be the BukkitTask
     
Thread Status:
Not open for further replies.

Share This Page