Repeating tasks

Discussion in 'Plugin Development' started by malachipclover, Jun 5, 2012.

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

    malachipclover

    For my plugin, ParanoiaPlugin, I want to add an option to play an effect multiple times. Right now I have a for loop with a delayed task in it, but it just waits the delay time and then does them all at once.

    Code:
                if(args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("bs"))
                {
                    for(int i = 0; i<=repeat; i++)
                    {
                        this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
     
                              public void run() {
                                  getServer().broadcastMessage("This message is broadcast by the main thread");
                                  other.playEffect(LC, Effect.BLAZE_SHOOT, 0);
                                  sender.sendMessage(ChatColor.GREEN + "Effect played");
                              }
                            }, delay * 20);
                    }
     
  2. Offline

    CorrieKay

    it plays them all at once because you register them in the scheduler with the same delay at the same time.

    if you want it to play, then wait, then play, then wait, you need to structure it differently.

    Try this, put an int with the number of times you want to play the effect after the delay, then in the run method, have it reschedule itsself if the countdown integer is > 0

    oh, and dont forget to subtract each time from the countdown, or it will never stop.
     
  3. Offline

    Shevchik

    It will play the effects wth a delay one second between them, so to you it seems like they are playing all at once.

    I think you want to play an effects with delay between them?
    Code:
    long delaybetweeneffects=0L;
    if(args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("bs"))
                {
                    for(int i = 0; i<=repeat; i++)
                    {
                        this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
     
                              public void run() {
                                  getServer().broadcastMessage("This message is broadcast by the main thread");
                                  other.playEffect(LC, Effect.BLAZE_SHOOT, 0);
                                  sender.sendMessage(ChatColor.GREEN + "Effect played");
                              }
                            }, delaybeforestart+delaybetweeneffects);
    delaybetweeneffects=delaybetweeneffects+somedelaythatyouwanttobebetweeneffects;
                    }
    }
     
  4. Offline

    malachipclover

    Yes, I am trying to delay them. I know the issue, I just don't know how to fix it. I need some way of knowing if a task is done before I invoke a new task.

    Oh, I misread that. I thought that that was a reply to my post, didn't realize it was a code tag. I think that will work.

    Oops, it looks like I forgot to completely clean up the sample code when I used it, I see it still has the message that says its broadcast from the main thread...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page