/*
 * Written from 2015-2020 by Daniel Saukel
 *
 * To the extent possible under law, the author(s) have dedicated all
 * copyright and related and neighboring rights to this software
 * to the public domain worldwide.
 *
 * This software is distributed without any warranty.
 *
 * You should have received a copy of the CC0 Public Domain Dedication
 * along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
 */
package de.erethon.commons.misc;

import de.erethon.commons.chat.MessageUtil;
import de.erethon.commons.javaplugin.DREPlugin;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

/**
 * An action bar based progress bar.
 *
 * @author Daniel Saukel
 */
public class ProgressBar extends BukkitRunnable {

    public static final String BAR = "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";

    protected Set<UUID> players = new HashSet<>();
    protected int seconds;
    protected int secondsLeft;

    public ProgressBar(Collection<Player> players, int seconds) {
        for (Player player : players) {
            this.players.add(player.getUniqueId());
        }
        this.seconds = seconds;
        this.secondsLeft = seconds;
    }

    public ProgressBar(Player player, int seconds) {
        this.players.add(player.getUniqueId());
        this.seconds = seconds;
        this.secondsLeft = seconds;
    }

    /**
     * @param player the player to add
     */
    public void addPlayer(Player player) {
        players.add(player.getUniqueId());
    }

    /**
     * @param player the player to remove
     */
    public void removePlayer(Player player) {
        players.remove(player.getUniqueId());
    }

    @Override
    public void run() {
        int i = (int) Math.round(((double) secondsLeft / (double) seconds) * 10);
        StringBuilder bar = new StringBuilder(BAR);
        bar.insert(10 - i, ChatColor.DARK_RED.toString());
        for (UUID uuid : players) {
            Player player = Bukkit.getPlayer(uuid);
            if (player != null && player.isOnline()) {
                MessageUtil.sendActionBarMessage(player, ChatColor.GREEN.toString() + bar.toString());
            }
        }

        if (secondsLeft == 0) {
            cancel();
        } else {
            secondsLeft--;
        }
    }

    /* Statics */
    public static String getBar(int tenths) {
        StringBuilder bar = new StringBuilder(BAR);
        bar.insert(tenths, ChatColor.DARK_RED.toString());
        return ChatColor.GREEN.toString() + bar.toString();
    }

    public static String getBar(double percentage) {
        return getBar((int) Math.round(percentage) / 10);
    }

    /**
     * Send the progress bar to a player.
     *
     * @param player  the player to send the bar to
     * @param seconds the seconds until the progress bar is finished
     * @return the started task
     */
    public static BukkitTask sendProgressBar(Player player, int seconds) {
        return new ProgressBar(player, seconds).runTaskTimer(DREPlugin.getInstance(), 0L, 20L);
    }

    /**
     * Send the progress bar to multiple players
     *
     * @param players the players to send the bar to
     * @param seconds the seconds until the progress bar is finished
     * @return the started task
     */
    public static BukkitTask sendProgressBar(Set<Player> players, int seconds) {
        return new ProgressBar(players, seconds).runTaskTimer(DREPlugin.getInstance(), 0L, 20L);
    }

}

@@ -530,47 +530,27 @@
 ort 
-de.erethon.commons.javaplugin.DREPlugin
+java.util.ArrayList
 ;%0Aim
@@ -597,36 +597,11 @@
 til.
-HashSet;%0Aimport java.util.Se
+Lis
 t;%0Ai
@@ -710,16 +710,49 @@
 Player;%0A
+import org.bukkit.plugin.Plugin;%0A
 import o
@@ -840,16 +840,13 @@
  * A
-n action
+ boss
  bar
@@ -1061,18 +1061,17 @@
   pr
-otected Se
+ivate Lis
 t%3CUU
@@ -1092,14 +1092,16 @@
 new 
-HashSe
+ArrayLis
 t%3C%3E(
@@ -1101,39 +1101,37 @@
 List%3C%3E();%0A    pr
-otec
+iva
 te
-d
  int seconds;%0A  
@@ -1138,15 +1138,13 @@
   pr
-otec
+iva
 te
-d
  int
@@ -2412,24 +2412,48 @@
 eft == 0) %7B%0A
+            onFinish();%0A
             
@@ -2533,750 +2533,113 @@
   /*
- Statics */%0A    public static String getBar(int tenths) %7B%0A        StringBuilder bar = new StringBuilder(BAR);%0A        bar.insert(tenths, ChatColor.DARK_RED.toString());%0A        return ChatColor.GREEN.toString() + bar.toString();%0A    %7D%0A%0A    public static String getBar(double percentage) %7B%0A        return getBar((int) Math.round(percentage) / 10);%0A    %7D%0A%0A    /**%0A     * Send the progress bar to a player.%0A     *%0A     * @param player  the player to send the bar to%0A     * @param seconds the seconds until the progress bar is finished%0A     * @return the started task%0A     */%0A    public static BukkitTask sendProgressBar(Player player, int seconds) %7B%0A        return new ProgressBar(player, seconds).runTaskTimer(DREPlugin.getInstance(), 0L, 20L);
+*%0A     * Method to override to set actions when no seconds are left.%0A     */%0A    public void onFinish() %7B
 %0A   
@@ -2661,16 +2661,17 @@
   * Send
+s
  the pro
@@ -2687,24 +2687,16 @@
  to 
-multiple
+a
  player
-s
 %0A   
@@ -2719,113 +2719,32 @@
 m pl
-ayers
+ugin
  the pl
-ayers to send the bar to%0A     * @param seconds the seconds until the progress bar is finished
+ugin instance
 %0A   
@@ -2764,16 +2764,24 @@
 he s
-tarted t
+cheduled BukkitT
 ask%0A
@@ -2799,23 +2799,16 @@
  public 
-static 
 BukkitTa
@@ -2818,105 +2818,41 @@
 send
-ProgressBar(Set%3CPlayer%3E players, int seconds) %7B%0A        return new ProgressBar(players, seconds).
+(Plugin plugin) %7B%0A        return 
 runT
@@ -2864,31 +2864,14 @@
 mer(
-DREP
+p
 lugin
-.getInstance()
 , 0L

Add DXL progress bar