Make a delay for timer?

Discussion in 'Plugin Development' started by FenixAzul, Oct 9, 2011.

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

    FenixAzul

    its there a way to make a delay to make a timer like thing, I want to make a time counter but im unable to do it with
    Code:
    int i = 10;
       getServer().getScheduler().scheduleSyncRepeatingTask(TronTrails.this, new Runnable(){
                    public void run(){
    
                     do{
                    getServer().broadcastMessage("Arena starting in"+  i);
                    i--;
                 }while(i > 0);
    
                    }
                    }, 100L, 20L);
    because i can't run that since scheduler doesnt allow variables it only allows finals, i tryed with the java mode sleep but it doesnot seem to work.
     
  2. Is it something like this you are looking for?
    Code:java
    1. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    2. public void run() {
    3. // THIS WILL BE RUN WHEN 3 SECONDS HAS PASSED
    4. }
    5. }, 3 * 20L); // 20 ticks = 1 second. So 3*20 ticks = 3 seconds.
     
  3. Offline

    FenixAzul

    no really a deleyedtask i need something like reapetingtask so it will repeat until u cancel the sheduler

    solved with ta tor hammer

    Code:
               getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                    public void run() {
                   System.out.println("Arena starting in 10");
                   getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                        public void run() {
                       System.out.println("Arena starting in 9");
                       getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                            public void run() {
                           System.out.println("Arena starting in 8");
                           getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                                public void run() {
                               System.out.println("Arena starting in 7");
                               getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                                    public void run() {
                                   System.out.println("Arena starting in 6");
                                   getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                                        public void run() {
                                       System.out.println("Arena starting in 5");
                                       getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                                            public void run() {
                                           System.out.println("Arena starting in 4");
                                           getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                                                public void run() {
                                               System.out.println("Arena starting in 3");
                                               getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                                                    public void run() {
                                                   System.out.println("Arena starting in 2");
                                                   getServer().getScheduler().scheduleSyncDelayedTask(TronTrails.this, new Runnable() {
                                                        public void run() {
                                                       System.out.println("Arena starting in 1" );
                                                        }
                                                        }, 3 * 20L);
                                                    }
                                                    }, 3 * 20L);
                                                }
                                                }, 3 * 20L);
                                            }
                                            }, 3 * 20L);
                                        }
                                        }, 3 * 20L);
                                    }
                                    }, 3 * 20L);
                                }
                                }, 3 * 20L);
                            }
                            }, 3 * 20L);
                        }
                        }, 3 * 20L);
                    }
                    }, 3 * 20L); // 20 ticks = 1 second. So 3*20 ticks = 3 seconds.
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  4. Try messing around with this. The method you came up with looks rather messy.

    RandomClass.java
    Code:java
    1. public int timer;
    2.  
    3. public void start() {
    4. timer = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Timer(), 20L, 20L);
    5. }
    6.  
    7. public void stop() {
    8. Bukkit.getServer().getScheduler().cancelTask(timer);
    9. }


    Timer.java
    Code:java
    1. package com.fuze.CraftOfDuty.timers;
    2.  
    3. public class Timer implements Runnable {
    4. public static int time;
    5.  
    6. public void run() {
    7. if(time == 0) RandomClass.stop();
    8. System.out.println("Arena starting in " + time);
    9. time--;
    10. }
    11. }
     
Thread Status:
Not open for further replies.

Share This Page