how do i put a delay on a command

Discussion in 'Plugin Development' started by IcyRelic, May 22, 2012.

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

    IcyRelic

    ok how do i put a delay in seconds on a teleport command like essentials does?
     
  2. Offline

    r0306

    Icyrelic
    Once a player used the command, add them to an arraylist and schedule a delayed task that removes them after X amount of time. On command usage, check if the player is in the list and if they are, simply return (with an optional message).
     
  3. Offline

    IcyRelic

    so what your saying is i start the schedule when the command is typed? but how would i stop the schedule?
     
  4. Offline

    r0306

    Icyrelic
    I don't understand. Why would you want to stop the schedule? It waits until the set time and then runs the code that you need it to run. What I am saying is that when the player uses a command, it toggles a "switch," which disallows them to use the code. It also schedules a task to run after the delay you want between commands which flips the "switch" again, allowing them to use the command. Here's the documentation for delayed tasks: http://wiki.bukkit.org/Scheduler_Programming#Delayed_Tasks
     
  5. Offline

    IcyRelic

    ok so i would setup the command and the command would send a message saying teleport will occur in 10 seconds
    then run the delayed task that will send a message saying the teleport is happening and make the teleport happen

    i have made a delayed task how do i get the senders name and the targets name

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  6. Offline

    r0306

  7. Offline

    IcyRelic

    i know how to make a command what im saying is how will i make the teleport happen in the delayed task because there is no sender in a delayed task how do i get who typed the command
     
  8. Offline

    r0306

    Icyrelic
    Use an inner method in your command executor class.
    Code:
    public onCommand(args blah blah blah) {
    if (cmd.getName().equalsIgnoreCase("blah")) {
    //do something  this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    public void run() {
    //remove players from hashmap
    }
    }, your delay time);
    Note! You will have to make your sender variable final.
     
Thread Status:
Not open for further replies.

Share This Page