Solved Creating a Timer?

Discussion in 'Plugin Development' started by chasechocolate, Jan 1, 2013.

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

    chasechocolate

    Hi, I need something for my plugin that run a method later, but every x seconds it will broadcast a message to an ArrayList of players. Something like:
    Starting in one minute.
    Starting in 45 seconds.
    Starting in 30 seconds.
    Starting in 15 seconds.
    Starting in 10 seconds.
    Starting in 3 seconds.
    *run a method*
    I was told that it is possible with java Timers or BukkitRunnables? How can I make this?
     
  2. Offline

    EnvisionRed

    Hopefully you meant an ArrayList of player names corresponding to players. Otherwise you'll just be causing memory leaks.
     
  3. Offline

    chasechocolate

    yeah, sorry for being unclear
     
  4. Offline

    fireblast709

    Code:java
    1. new BukkitRunnable()
    2. {
    3. int count = 60;
    4. Player p;
    5. @Override
    6. public void run()
    7. {
    8. if(count % 15 == 0 || (count % 5 == 0 && count < 15) || (count < 4))
    9. {
    10. for(String player : yourList)
    11. {
    12. p = Bukkit.getPlayer(player);
    13. if(p != null)
    14. {
    15. p.sendMessage("Only "+count+" second left");
    16. }
    17. }
    18. }
    19. count--;
    20. if(count == 0)
    21. {
    22. // run method
    23. }
    24. }
    25. }.runTaskTimer(<plugin instance>, 0L, 20L);
     
    chasechocolate likes this.
  5. Offline

    chasechocolate

    Thanks! You seem to know everything... :confused:
     
Thread Status:
Not open for further replies.

Share This Page