Multiple Repeating Tasks!

Discussion in 'Spigot Plugin Development' started by KingDotCom, May 25, 2016.

  1. Hello, I was wondering if someone could help me develop this Multiple Repeating Tasks.
    What I want to do is when a player executes a command it does the beginning then it does the first delay(30 seconds) then broadcasts, there's about 14 delays that's why I need help.
    What I tried is I tried to put multiple runnables in the inside each of the Schedulers like this;
    Code (Text):
    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(pl, new Runnable(){
                                                                    public void run() {
                                                                        Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&4&lPvP is on!"));
                                                                        Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&4Meetup is in 35 minutes"));
                                                                        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(pl, new Runnable(){
                                  public void run(){
                                                                                Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&4&lPvP is on!"));
    but it did not work. I was wondering if someone could help me.
    If you want to help me you can either message me on skype (Skype is CrunchMini) or you can reply to this post.
    Thanks a ton.
     
  2. Not sure why you have made another post :/

    In this situation I would create a new bukkit runnable to repeat every second, within that runnable initialise an integer that increments each time the runnable goes off. Using the integer you can then work out how much time has elapsed and do whatever based on that.

    I don't really want to spoon feed but this is a simple example of what you can do...

    Code (Text):
    new BukkitRunnable() {
                int step = 0;
                @Override
                public void run() {
                    step++;
                    if (step == 2) {
                        //Do something after two seconds.
                    }
                    else if (step == 60) {
                        //Do something after a minute.
                    }
                }
            }.runTaskTimer({YOUR_PLUGIN_INSTANCE}, 20L, 20L );
     
    • Agree Agree x 1