convert time into seconds

Discussion in 'Plugin Development' started by RebzO1, Feb 20, 2014.

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

    RebzO1

    I wrote this just now and it works the way its supposed too...
    But at the end where /time is I want it to display minutes and seconds not just seconds (I think I explained that correctly)
    How would I go about this..

    Code:java
    1. // Start Timers
    2. // This focuses on the start countdown and game countdown also the /time command
    3. if (CommandLabel.equalsIgnoreCase("start") && sender instanceof Player){
    4. this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
    5. public void run(){
    6. if(number != -1){
    7. if(number != 0){
    8. Bukkit.broadcastMessage(ChatColor.AQUA + "" + number);
    9. number--;
    10. }else{
    11. Bukkit.broadcastMessage(ChatColor.AQUA + "Go! Go! Go!");
    12. number--;
    13. }
    14. }
    15. }
    16. }, 0L, 20L);
    17.  
    18. this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
    19. public void run(){
    20. if(time != -1){
    21. if(time != 0){
    22. time--;
    23. }else{
    24. Bukkit.broadcastMessage(ChatColor.AQUA + "Times Up!");
    25. time--;
    26. }
    27. }
    28. }
    29. }, 0L, 20L);
    30. return true;
    31. }
    32.  
    33. if (CommandLabel.equalsIgnoreCase("time") && sender instanceof Player){
    34. if(args.length == 0){
    35. Bukkit.broadcastMessage(ChatColor.AQUA + "Time left: " + ChatColor.GRAY + time + ChatColor.AQUA + " seconds.");
    36. return true;
    37. }
    38. }
    39. // End Timers


    Thanks in advance
     
  2. To get minutes and seconds do
    Code:
    int minutes = time / 60;
    int seconds = time % 60;
    
     
  3. Offline

    RebzO1

    BurnBlader
    ok now i want to kick my own ass at how simple that was....
    thank you, at least i learned something new..

    BurnBlader
    how would i go about teleporting all players to world spawn location at 'times up'

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  4. Make sure the world is loaded and do:
    Code:
    for(Player p : Bukkit.getOnlinePlayers()) {
               p.teleport(Bukkit.getWorld("spawn"), 0, 100, 0); // fill in the coordinates and world name
    }
    
     
  5. Offline

    RebzO1

    BurnBlader
    awesome im testing something else in same plugin and ill repost here if that worked for me, just by looking i don't see why it wouldnt
    ty for your help

    BurnBlader

    Code:java
    1. for(Player pl : Bukkit.getOnlinePlayers()) {
    2. pl.teleport(pl.getWorld().getSpawnLocation());
    3. }

    worked great ty

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

Share This Page