Need alternative to Threads.sleep

Discussion in 'Plugin Development' started by jtc883, Feb 18, 2012.

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

    jtc883

    i'm trying to make a countdown to spawning and ender dragon. i have the counter working and the spawning but my problem is that the countdown doesn't show for me until it is at 0 and the dragon spawns. everyone else in the server sees it normally. Any one have suggestions? Is it something I coded wrong or, I dont even know. Code below of the spawning event.
    Code:java
    1.  
    2.  
    3. if (cmd.getName().equalsIgnoreCase("dragon"))
    4. if(cs.isOp()){
    5. counter = 10;
    6. do{
    7. Bukkit.getServer().broadcastMessage(ChatColor.DARK_GRAY + "Ender Dragon Fight Begins in " + ChatColor.LIGHT_PURPLE + counter);
    8. counter = counter - 1;
    9. try {
    10. Thread.sleep(1000);
    11. } catch (InterruptedException e) {
    12. e.printStackTrace();
    13. }
    14. }while(counter >= 1);
    15. Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "SLAY THE ENDER DRAGON!!!");
    16. player.getWorld().spawnCreature(player.getLocation(), CreatureType.ENDER_DRAGON);
    17. } else
    18. player.sendMessage(ChatColor.AQUA + "Sorry You Must Be an OP to use that Command");
    19.  
    20.  
    21. return true;
     
  2. Offline

    Sagacious_Zed Bukkit Docs

  3. Offline

    jtc883

    ok so i under stand the whole - code below

    but i dont know how much my code needs to go inside to still get the countdown to work and then spawn.

    Sorry I'm such a noob

    Code:java
    1.  
    2.  
    3. [SIZE=14px][COLOR=#000000]myPlugin.getServer().getScheduler().scheduleSyncDelayedTask(myPlugin, new Runnable() {
    4.  
    5. public void run() {
    6. getServer().broadcastMessage("This message is broadcast by the main thread");
    7. }
    8. }, 60L);[/COLOR][/SIZE]
     
Thread Status:
Not open for further replies.

Share This Page