diff --git a/changelog.md b/changelog.md index 194f9a0..36670ec 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ - Fix NMS - Fix ``/koth stop`` +- Create placeholder: ``%zkoth_capture_progress_bar%`` # 3.0.2 diff --git a/src/fr/maxlego08/koth/KothPlaceholder.java b/src/fr/maxlego08/koth/KothPlaceholder.java index d498c87..7f629bc 100644 --- a/src/fr/maxlego08/koth/KothPlaceholder.java +++ b/src/fr/maxlego08/koth/KothPlaceholder.java @@ -6,12 +6,13 @@ import fr.maxlego08.koth.placeholder.LocalPlaceholder; import fr.maxlego08.koth.placeholder.ReturnBiConsumer; import fr.maxlego08.koth.save.Config; import fr.maxlego08.koth.zcore.utils.ReturnConsumer; +import fr.maxlego08.koth.zcore.utils.ZUtils; import fr.maxlego08.koth.zcore.utils.builder.TimerBuilder; import org.bukkit.entity.Player; import java.util.Optional; -public class KothPlaceholder { +public class KothPlaceholder extends ZUtils { private final KothManager kothManager; @@ -33,13 +34,15 @@ public class KothPlaceholder { this.register("center_y", koth -> String.valueOf(koth.getCenter().getBlockY())); this.register("center_z", koth -> String.valueOf(koth.getCenter().getBlockZ())); - this.register("spawn_seconds", koth -> String.valueOf(koth.getRemainingSeconds() == null ? koth.getCaptureSeconds() : koth.getRemainingSeconds().get())); - this.register("spawn_format", koth -> TimerBuilder.getStringTime(koth.getRemainingSeconds() == null ? koth.getCaptureSeconds() : koth.getRemainingSeconds().get())); - this.register("capture_format", koth -> String.valueOf(koth.getRemainingSeconds() == null ? koth.getCaptureSeconds() : koth.getRemainingSeconds().get())); - this.register("capture_seconds", koth -> TimerBuilder.getStringTime(koth.getRemainingSeconds() == null ? koth.getCaptureSeconds() : koth.getRemainingSeconds().get())); + this.register("spawn_seconds", koth -> String.valueOf(koth.getRemainingSeconds())); + this.register("spawn_format", koth -> TimerBuilder.getStringTime(koth.getRemainingSeconds())); + this.register("capture_format", koth -> String.valueOf(koth.getRemainingSeconds())); + this.register("capture_seconds", koth -> TimerBuilder.getStringTime(koth.getRemainingSeconds())); this.register("capture_max_seconds", koth -> String.valueOf(koth.getCaptureSeconds())); this.register("capture_max_formats", koth -> TimerBuilder.getStringTime(koth.getCaptureSeconds())); + this.register("capture_progress_bar", koth -> getProgressBar(koth.getCaptureSeconds() - koth.getRemainingSeconds(), koth.getCaptureSeconds(), koth.getProgressBar())); + this.registerPosition("score_player_", (position, koth) -> koth.getPlayer(position).getPlayerName()); this.registerPosition("score_points_", (position, koth) -> String.valueOf(koth.getPlayer(position).getPoints())); this.registerPosition("score_team_name_", (position, koth) -> koth.getPlayer(position).getTeamName()); diff --git a/src/fr/maxlego08/koth/ZKoth.java b/src/fr/maxlego08/koth/ZKoth.java index 4fd6f93..bfa8941 100644 --- a/src/fr/maxlego08/koth/ZKoth.java +++ b/src/fr/maxlego08/koth/ZKoth.java @@ -23,6 +23,7 @@ import fr.maxlego08.koth.scoreboard.ScoreBoardManager; import fr.maxlego08.koth.zcore.enums.Message; import fr.maxlego08.koth.zcore.logger.Logger; import fr.maxlego08.koth.zcore.utils.Cuboid; +import fr.maxlego08.koth.zcore.utils.ProgressBar; import fr.maxlego08.koth.zcore.utils.ZUtils; import fr.maxlego08.koth.zcore.utils.builder.TimerBuilder; import fr.maxlego08.koth.zcore.utils.interfaces.CollectionConsumer; @@ -70,6 +71,7 @@ public class ZKoth extends ZUtils implements Koth { private final HologramConfig hologramConfig; private final KothLootType kothLootType; private final List blacklistTeamId; + private final ProgressBar progressBar; private List itemStacks; private String name; private int captureSeconds; @@ -86,7 +88,7 @@ public class ZKoth extends ZUtils implements Koth { private DiscordWebhookConfig discordWebhookConfig; private List playerResults = new ArrayList<>(); - public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List startCommands, List endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard, int cooldownStart, int stopAfterSeconds, boolean enableStartCapMessage, boolean enableLooseCapMessage, boolean enableEverySecondsCapMessage, HologramConfig hologramConfig, List itemStacks, KothLootType kothLootType, DiscordWebhookConfig discordWebhookConfig, int randomItemStacks, List blacklistTeamId) { + public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List startCommands, List endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard, int cooldownStart, int stopAfterSeconds, boolean enableStartCapMessage, boolean enableLooseCapMessage, boolean enableEverySecondsCapMessage, HologramConfig hologramConfig, List itemStacks, KothLootType kothLootType, DiscordWebhookConfig discordWebhookConfig, int randomItemStacks, List blacklistTeamId, ProgressBar progressBar) { this.plugin = plugin; this.fileName = fileName; this.kothType = kothType; @@ -109,6 +111,7 @@ public class ZKoth extends ZUtils implements Koth { this.discordWebhookConfig = discordWebhookConfig; this.randomItemStacks = randomItemStacks; this.blacklistTeamId = blacklistTeamId; + this.progressBar = progressBar; } public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation) { @@ -132,6 +135,7 @@ public class ZKoth extends ZUtils implements Koth { this.kothLootType = KothLootType.NONE; this.randomItemStacks = 0; this.blacklistTeamId = new ArrayList<>(); + this.progressBar = new ProgressBar(10, '-', "&a", "&7"); } @Override @@ -793,8 +797,8 @@ public class ZKoth extends ZUtils implements Koth { } @Override - public AtomicInteger getRemainingSeconds() { - return this.remainingSeconds; + public int getRemainingSeconds() { + return this.remainingSeconds == null ? this.captureSeconds : this.remainingSeconds.get(); } @Override @@ -843,4 +847,8 @@ public class ZKoth extends ZUtils implements Koth { }).sorted(Comparator.comparingInt(PlayerResult::getPoints).reversed()).collect(Collectors.toList()); } + @Override + public ProgressBar getProgressBar() { + return this.progressBar; + } } diff --git a/src/fr/maxlego08/koth/api/Koth.java b/src/fr/maxlego08/koth/api/Koth.java index ed354a5..1d004cc 100644 --- a/src/fr/maxlego08/koth/api/Koth.java +++ b/src/fr/maxlego08/koth/api/Koth.java @@ -5,6 +5,7 @@ import fr.maxlego08.koth.api.utils.HologramConfig; import fr.maxlego08.koth.api.utils.PlayerResult; import fr.maxlego08.koth.api.utils.ScoreboardConfiguration; import fr.maxlego08.koth.zcore.utils.Cuboid; +import fr.maxlego08.koth.zcore.utils.ProgressBar; import fr.maxlego08.koth.zcore.utils.interfaces.CollectionConsumer; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -278,7 +279,7 @@ public interface Koth { * * @return An {@code AtomicInteger} with the remaining seconds. */ - AtomicInteger getRemainingSeconds(); + int getRemainingSeconds(); /** * Gets the current player who is capturing the KOTH. @@ -297,5 +298,7 @@ public interface Koth { PlayerResult getPlayer(int position); List getBlacklistTeamId(); + + ProgressBar getProgressBar(); } diff --git a/src/fr/maxlego08/koth/loader/KothLoader.java b/src/fr/maxlego08/koth/loader/KothLoader.java index fad9683..39c917d 100644 --- a/src/fr/maxlego08/koth/loader/KothLoader.java +++ b/src/fr/maxlego08/koth/loader/KothLoader.java @@ -8,6 +8,7 @@ import fr.maxlego08.koth.api.KothType; import fr.maxlego08.koth.api.discord.DiscordWebhookConfig; import fr.maxlego08.koth.api.utils.HologramConfig; import fr.maxlego08.koth.api.utils.ScoreboardConfiguration; +import fr.maxlego08.koth.zcore.utils.ProgressBar; import fr.maxlego08.koth.zcore.utils.ZUtils; import fr.maxlego08.koth.zcore.utils.loader.Loader; import fr.maxlego08.koth.zcore.utils.nms.ItemStackUtils; @@ -25,6 +26,7 @@ public class KothLoader extends ZUtils implements Loader { private final Loader locationLoader = new LocationLoader(); private final Loader scoreboardLoaderLoader = new ScoreboardLoader(); private final Loader hologramConfigLoader = new HologramLoader(); + private final Loader progressBarLoader = new ProgressBarLoader(); public KothLoader(KothPlugin plugin) { this.plugin = plugin; @@ -70,8 +72,10 @@ public class KothLoader extends ZUtils implements Loader { List blacklistTeamId = configuration.getStringList("blacklistTeamId"); + ProgressBar progressBar = progressBarLoader.load(configuration, "progressBar.", file); + return new ZKoth(this.plugin, fileName, kothType, name, captureSeconds, minLocation, maxLocation, startCommands, endCommands, cooldownScoreboard, - startScoreboard, cooldownStart, stopAfterSeconds, enableStartCapMessage, enableLooseCapMessage, enableEverySecondsCapMessage, hologramConfig, itemStacks, kothLootType, discordWebhookConfig, randomItemStacks, blacklistTeamId); + startScoreboard, cooldownStart, stopAfterSeconds, enableStartCapMessage, enableLooseCapMessage, enableEverySecondsCapMessage, hologramConfig, itemStacks, kothLootType, discordWebhookConfig, randomItemStacks, blacklistTeamId, progressBar); } @Override @@ -92,11 +96,11 @@ public class KothLoader extends ZUtils implements Loader { scoreboardLoaderLoader.save(koth.getCooldownScoreboard(), configuration, "scoreboard.cooldown."); scoreboardLoaderLoader.save(koth.getStartScoreboard(), configuration, "scoreboard.start."); hologramConfigLoader.save(koth.getHologramConfig(), configuration, "hologram."); + progressBarLoader.save(koth.getProgressBar(), configuration, "progressBar."); configuration.set("loot.type", koth.getLootType().name()); configuration.set("loot.random", koth.getRandomItemStack()); List items = koth.getItemStacks().stream().map(ItemStackUtils::serializeItemStack).collect(Collectors.toList()); configuration.set("loot.items", items); - } } diff --git a/src/fr/maxlego08/koth/loader/ProgressBarLoader.java b/src/fr/maxlego08/koth/loader/ProgressBarLoader.java new file mode 100644 index 0000000..64ebfcf --- /dev/null +++ b/src/fr/maxlego08/koth/loader/ProgressBarLoader.java @@ -0,0 +1,30 @@ +package fr.maxlego08.koth.loader; + +import fr.maxlego08.koth.zcore.utils.ProgressBar; +import fr.maxlego08.koth.zcore.utils.ZUtils; +import fr.maxlego08.koth.zcore.utils.loader.Loader; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; + +public class ProgressBarLoader extends ZUtils implements Loader { + + @Override + public ProgressBar load(YamlConfiguration configuration, String path, File file) { + + int length = configuration.getInt(path + "length", 10); + char symbol = configuration.getString(path + "symbol", "-").charAt(0); + String completedColor = configuration.getString(path + "completedColor", "&a"); + String notCompletedColor = configuration.getString(path + "notCompletedColor", "&7"); + + return new ProgressBar(length, symbol, completedColor, notCompletedColor); + } + + @Override + public void save(ProgressBar progressBar, YamlConfiguration configuration, String path) { + configuration.set(path + "length", progressBar.getLength()); + configuration.set(path + "symbol", progressBar.getSymbol()); + configuration.set(path + "completedColor", progressBar.getCompletedColor()); + configuration.set(path + "notCompletedColor", progressBar.getNotCompletedColor()); + } +} diff --git a/src/fr/maxlego08/koth/scoreboard/ScoreBoardManager.java b/src/fr/maxlego08/koth/scoreboard/ScoreBoardManager.java index fe316d6..34d1feb 100644 --- a/src/fr/maxlego08/koth/scoreboard/ScoreBoardManager.java +++ b/src/fr/maxlego08/koth/scoreboard/ScoreBoardManager.java @@ -32,6 +32,8 @@ public class ScoreBoardManager extends ZUtils { */ public void schedule() { + if (Config.schedulerMillisecond == 1000) return; + if (isRunning) return; @@ -217,7 +219,7 @@ public class ScoreBoardManager extends ZUtils { */ public void setLinesAndSchedule(CollectionConsumer lines) { this.lines = lines; - // this.schedule(); + this.schedule(); } public KothScoreboard getScoreboard() { diff --git a/src/fr/maxlego08/koth/zcore/utils/ProgressBar.java b/src/fr/maxlego08/koth/zcore/utils/ProgressBar.java index 3549189..9ca166a 100644 --- a/src/fr/maxlego08/koth/zcore/utils/ProgressBar.java +++ b/src/fr/maxlego08/koth/zcore/utils/ProgressBar.java @@ -2,51 +2,45 @@ package fr.maxlego08.koth.zcore.utils; public class ProgressBar { - private final int lenght; - private final char symbol; - private final String completedColor; - private final String notCompletedColor; + private final int length; + private final char symbol; + private final String completedColor; + private final String notCompletedColor; - /** - * @param lenght - * @param symbol - * @param completedColor - * @param notCompletedColor - */ - public ProgressBar(int lenght, char symbol, String completedColor, String notCompletedColor) { - super(); - this.lenght = lenght; - this.symbol = symbol; - this.completedColor = completedColor; - this.notCompletedColor = notCompletedColor; - } + public ProgressBar(int length, char symbol, String completedColor, String notCompletedColor) { + super(); + this.length = length; + this.symbol = symbol; + this.completedColor = completedColor; + this.notCompletedColor = notCompletedColor; + } - /** - * @return the lenght - */ - public int getLenght() { - return lenght; - } + /** + * @return the length + */ + public int getLength() { + return length; + } - /** - * @return the symbol - */ - public char getSymbol() { - return symbol; - } + /** + * @return the symbol + */ + public char getSymbol() { + return symbol; + } - /** - * @return the completedColor - */ - public String getCompletedColor() { - return completedColor; - } + /** + * @return the completedColor + */ + public String getCompletedColor() { + return completedColor; + } - /** - * @return the notCompletedColor - */ - public String getNotCompletedColor() { - return notCompletedColor; - } + /** + * @return the notCompletedColor + */ + public String getNotCompletedColor() { + return notCompletedColor; + } } diff --git a/src/fr/maxlego08/koth/zcore/utils/ZUtils.java b/src/fr/maxlego08/koth/zcore/utils/ZUtils.java index 14dac41..c54a1f7 100644 --- a/src/fr/maxlego08/koth/zcore/utils/ZUtils.java +++ b/src/fr/maxlego08/koth/zcore/utils/ZUtils.java @@ -1149,8 +1149,8 @@ public abstract class ZUtils extends MessageUtils { float percent = (float) current / max; int progressBars = (int) (totalBars * percent); - return Strings.repeat(completedColor + symbol, progressBars) - + Strings.repeat(notCompletedColor + symbol, totalBars - progressBars); + return color(Strings.repeat(completedColor + symbol, progressBars) + + Strings.repeat(notCompletedColor + symbol, totalBars - progressBars)); } /** @@ -1162,7 +1162,7 @@ public abstract class ZUtils extends MessageUtils { * @return string */ public String getProgressBar(int current, int max, ProgressBar progressBar) { - return this.getProgressBar(current, max, progressBar.getLenght(), progressBar.getSymbol(), + return this.getProgressBar(current, max, progressBar.getLength(), progressBar.getSymbol(), progressBar.getCompletedColor(), progressBar.getNotCompletedColor()); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 601d4d7..c4844ff 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -126,4 +126,4 @@ defaultPlayerResult: points: 0 teamName: "X" teamId: "X" - teamLeader: "X" \ No newline at end of file + teamLeader: "X" diff --git a/src/main/resources/koth-example.yml b/src/main/resources/koth-example.yml index 252e094..a70a470 100644 --- a/src/main/resources/koth-example.yml +++ b/src/main/resources/koth-example.yml @@ -149,4 +149,11 @@ loot: # Allows blacklist of team IDs so that it does not participate in koth, in this example, teams with ID 0 and -1 are blacklist blacklistTeamId: - "0" - - "-1" \ No newline at end of file + - "-1" + +# Configuration for the Progress Bar. Use by placeholders +progressBar: + length: 20 + symbol: "|" + completedColor: "#2fedc7" + notCompletedColor: "#8f8f8f" \ No newline at end of file