1.15.2 Countdown bossbar

Discussion in 'Spigot Plugin Development' started by PixliePlaysYT, Feb 8, 2020.

  1. Hey! I want to make a timer, and also a bossbar that changes it progress with a countdown. For example it goes down the less time the countdown has. And i only want to show the bossbar to certain players located in a ArrayList<>();
    Can anyone help me?
  2. Here's a pretty simple example. Please don't just blindly copy this and understand what is going on here.
    Code (Java):

    private BukkitTask task;
    BossBar bossBar = Bukkit.createBossBar("countdown", BarColor.YELLOW, BarStyle.SEGMENTED_10);
    if (task == null) {
        this.task = new BukkitRunnable() {
            int seconds = 10;
                public void run() {
                   if ((seconds -= 1) == 0) {
                    } else {
                        bossBar.setProgress(seconds / 10D);
            }.runTaskTimer(<plugin instance>, 0, 20);
    #2 Schottky, Feb 8, 2020
    Last edited: Feb 8, 2020
    • Agree Agree x 2
    • Useful Useful x 1
  3. Thank you very much, but i have one question for myself, what exactly is the 10D? is the D double or what?
  4. Yes.
  5. bar.setProgress(duration / flyTime);
    This is the line in my HoneyFly plugin. the bar takes a value of 0.0..1.0 so you divide the time left by the full time and you end up with an appropriate value. In Schottky's example the 'full time' was 10 seconds thats why he divided by 10D. In my plugin flyTime is a float.
  6. And how can i get the remaining time? Like in minutes?
    Like: Time left: 9:38
  7. TimeLeftInSeconds / 60 = minutes
    TimeLeftInSeconds % 60 = seconds