Boss bar and timer together?

Discussion in 'Plugin Development' started by Ty Cleere, Apr 27, 2014.

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

    Ty Cleere

    I am trying to use a dragon bar to show a timer. But it doesnt count down like i am thinking it should. And also how am i able to get it to show like "15 minutes 32 seconds"

    Here is my code and a picture.

    Code:java
    1. if (commandLabel.equalsIgnoreCase("uhctimer")) {
    2. if (!sender.hasPermission("uhc.timer")) {
    3. sender.sendMessage(ChatColor.DARK_RED
    4. + "YOU DONT HAVE PERMISSION TO DO THIS!");
    5. return true;
    6. }
    7. BarAPI.setMessage("Time left:" + countdown, 5400);
    8.  
    9. player.sendMessage(ChatColor.RED
    10. + "You have started the uhc timer!");
    11.  
    12. Bukkit.getServer()
    13. .getScheduler()
    14. .scheduleSyncRepeatingTask(
    15. Bukkit.getPluginManager().getPlugin(
    16. "UHC-Essentials"), new Runnable() {
    17. public void run() {
    18.  
    19. if (countdown == 20) {
    20. Bukkit.broadcastMessage("§3[FreezeTag] §6Game starting in §b"
    21. + countdown + " §6seconds");
    22. }
    23. if (countdown == 10) {
    24. Bukkit.broadcastMessage("§3[FreezeTag] §6Game starting in §b"
    25. + countdown + " §6seconds");
    26. }
    27. if (countdown <= 5 && countdown > 0) {
    28. Bukkit.broadcastMessage("§3[FreezeTag] §6Game starting in §b"
    29. + countdown + " §6seconds");
    30. }
    31. if (countdown <= 5) {
    32. for (Player p : Bukkit
    33. .getOnlinePlayers()) {
    34. p.playSound(p.getLocation(),
    35. Sound.NOTE_STICKS, 1, 0);
    36. }
    37. }
    38. countdown--;
    39. if (countdown < 0) {
    40. plugin.getServer()
    41. .getScheduler()
    42. .cancelTasks(
    43. Bukkit.getPluginManager()
    44. .getPlugin(
    45. "Uhc-Essentials"));
    46. for (Player p : Bukkit
    47. .getOnlinePlayers()) {
    48. p.playSound(p.getLocation(),
    49. Sound.ORB_PICKUP, 1, 0);
    50. }
    51. }
    52.  
    53. }
    54. }, 0, 20);
    55.  
    56. }


    2014-04-27_10.27.36.png
     
  2. Offline

    Gater12

    Ty Cleere
    You need to keep setting the bar message in the timer, not outside.

    Divide time by 60 to get minutes and use the modulo operation to get the seconds.
    Code:java
    1. int m = time / 60;
    2. int s = time % 60;
     
    Ty Cleere likes this.
  3. Offline

    Ty Cleere

    Gater12 Ok Thanks!!!

    Alright guys one more thing i need help with. I got it to display the right stuff but it isnt counting down. When i just use the int countdown it works fine but with i use the int m and s it doenst work. here is code and a pic

    Code:java
    1. @EventHandler
    2. public void startBar(final Player[] players) {
    3. Bukkit.getScheduler().scheduleSyncRepeatingTask(
    4. Bukkit.getPluginManager().getPlugin("UHC-Essentials"),
    5. new Runnable() {
    6.  
    7. @Override
    8. public void run() {
    9. BarAPI.setMessage("Time left: " + m + " minutes " + s + " seconds", 5400);
    10.  
    11. if (countdown == 89) {
    12. Bukkit.broadcastMessage("§3[FreezeTag] §6Game starting in §b"
    13. + countdown + " §6seconds");
    14. }
    15. if (countdown == 10) {
    16. Bukkit.broadcastMessage("§3[FreezeTag] §6Game starting in §b"
    17. + countdown + " §6seconds");
    18. }
    19. if (countdown <= 5 && countdown > 0) {
    20. Bukkit.broadcastMessage("§3[FreezeTag] §6Game starting in §b"
    21. + countdown + " §6seconds");
    22. }
    23. if (countdown <= 5) {
    24. for (Player p : Bukkit.getOnlinePlayers()) {
    25. p.playSound(p.getLocation(), Sound.NOTE_STICKS,
    26. 1, 0);
    27. }
    28. }
    29. countdown--;
    30. if (countdown < 0) {
    31. Bukkit.getPluginManager()
    32. .getPlugin("UHC-Essentials").getServer()
    33. .getScheduler().cancelAllTasks();
    34. for (Player p : Bukkit.getOnlinePlayers()) {
    35. p.playSound(p.getLocation(),
    36. Sound.ENDERDRAGON_GROWL, 1, 0);
    37. }
    38. }
    39.  
    40. }
    41.  
    42. }, 0L, 20L);
    43. }


    View attachment 19328

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

Share This Page