🚧 Add koth placeholder progressbar

This commit is contained in:
Maxlego08 2024-03-04 16:36:00 +01:00
parent d0ee464652
commit b6fd54bbb6
11 changed files with 110 additions and 58 deletions

View File

@ -2,6 +2,7 @@
- Fix NMS - Fix NMS
- Fix ``/koth stop`` - Fix ``/koth stop``
- Create placeholder: ``%zkoth_capture_progress_bar%``
# 3.0.2 # 3.0.2

View File

@ -6,12 +6,13 @@ import fr.maxlego08.koth.placeholder.LocalPlaceholder;
import fr.maxlego08.koth.placeholder.ReturnBiConsumer; import fr.maxlego08.koth.placeholder.ReturnBiConsumer;
import fr.maxlego08.koth.save.Config; import fr.maxlego08.koth.save.Config;
import fr.maxlego08.koth.zcore.utils.ReturnConsumer; import fr.maxlego08.koth.zcore.utils.ReturnConsumer;
import fr.maxlego08.koth.zcore.utils.ZUtils;
import fr.maxlego08.koth.zcore.utils.builder.TimerBuilder; import fr.maxlego08.koth.zcore.utils.builder.TimerBuilder;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Optional; import java.util.Optional;
public class KothPlaceholder { public class KothPlaceholder extends ZUtils {
private final KothManager kothManager; private final KothManager kothManager;
@ -33,13 +34,15 @@ public class KothPlaceholder {
this.register("center_y", koth -> String.valueOf(koth.getCenter().getBlockY())); this.register("center_y", koth -> String.valueOf(koth.getCenter().getBlockY()));
this.register("center_z", koth -> String.valueOf(koth.getCenter().getBlockZ())); 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_seconds", koth -> String.valueOf(koth.getRemainingSeconds()));
this.register("spawn_format", koth -> TimerBuilder.getStringTime(koth.getRemainingSeconds() == null ? koth.getCaptureSeconds() : koth.getRemainingSeconds().get())); this.register("spawn_format", koth -> TimerBuilder.getStringTime(koth.getRemainingSeconds()));
this.register("capture_format", koth -> String.valueOf(koth.getRemainingSeconds() == null ? koth.getCaptureSeconds() : koth.getRemainingSeconds().get())); this.register("capture_format", koth -> String.valueOf(koth.getRemainingSeconds()));
this.register("capture_seconds", koth -> TimerBuilder.getStringTime(koth.getRemainingSeconds() == null ? koth.getCaptureSeconds() : koth.getRemainingSeconds().get())); this.register("capture_seconds", koth -> TimerBuilder.getStringTime(koth.getRemainingSeconds()));
this.register("capture_max_seconds", koth -> String.valueOf(koth.getCaptureSeconds())); this.register("capture_max_seconds", koth -> String.valueOf(koth.getCaptureSeconds()));
this.register("capture_max_formats", koth -> TimerBuilder.getStringTime(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_player_", (position, koth) -> koth.getPlayer(position).getPlayerName());
this.registerPosition("score_points_", (position, koth) -> String.valueOf(koth.getPlayer(position).getPoints())); this.registerPosition("score_points_", (position, koth) -> String.valueOf(koth.getPlayer(position).getPoints()));
this.registerPosition("score_team_name_", (position, koth) -> koth.getPlayer(position).getTeamName()); this.registerPosition("score_team_name_", (position, koth) -> koth.getPlayer(position).getTeamName());

View File

@ -23,6 +23,7 @@ import fr.maxlego08.koth.scoreboard.ScoreBoardManager;
import fr.maxlego08.koth.zcore.enums.Message; import fr.maxlego08.koth.zcore.enums.Message;
import fr.maxlego08.koth.zcore.logger.Logger; import fr.maxlego08.koth.zcore.logger.Logger;
import fr.maxlego08.koth.zcore.utils.Cuboid; 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.ZUtils;
import fr.maxlego08.koth.zcore.utils.builder.TimerBuilder; import fr.maxlego08.koth.zcore.utils.builder.TimerBuilder;
import fr.maxlego08.koth.zcore.utils.interfaces.CollectionConsumer; 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 HologramConfig hologramConfig;
private final KothLootType kothLootType; private final KothLootType kothLootType;
private final List<String> blacklistTeamId; private final List<String> blacklistTeamId;
private final ProgressBar progressBar;
private List<ItemStack> itemStacks; private List<ItemStack> itemStacks;
private String name; private String name;
private int captureSeconds; private int captureSeconds;
@ -86,7 +88,7 @@ public class ZKoth extends ZUtils implements Koth {
private DiscordWebhookConfig discordWebhookConfig; private DiscordWebhookConfig discordWebhookConfig;
private List<PlayerResult> playerResults = new ArrayList<>(); private List<PlayerResult> playerResults = new ArrayList<>();
public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List<String> startCommands, List<String> endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard, int cooldownStart, int stopAfterSeconds, boolean enableStartCapMessage, boolean enableLooseCapMessage, boolean enableEverySecondsCapMessage, HologramConfig hologramConfig, List<ItemStack> itemStacks, KothLootType kothLootType, DiscordWebhookConfig discordWebhookConfig, int randomItemStacks, List<String> blacklistTeamId) { public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List<String> startCommands, List<String> endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard, int cooldownStart, int stopAfterSeconds, boolean enableStartCapMessage, boolean enableLooseCapMessage, boolean enableEverySecondsCapMessage, HologramConfig hologramConfig, List<ItemStack> itemStacks, KothLootType kothLootType, DiscordWebhookConfig discordWebhookConfig, int randomItemStacks, List<String> blacklistTeamId, ProgressBar progressBar) {
this.plugin = plugin; this.plugin = plugin;
this.fileName = fileName; this.fileName = fileName;
this.kothType = kothType; this.kothType = kothType;
@ -109,6 +111,7 @@ public class ZKoth extends ZUtils implements Koth {
this.discordWebhookConfig = discordWebhookConfig; this.discordWebhookConfig = discordWebhookConfig;
this.randomItemStacks = randomItemStacks; this.randomItemStacks = randomItemStacks;
this.blacklistTeamId = blacklistTeamId; this.blacklistTeamId = blacklistTeamId;
this.progressBar = progressBar;
} }
public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation) { 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.kothLootType = KothLootType.NONE;
this.randomItemStacks = 0; this.randomItemStacks = 0;
this.blacklistTeamId = new ArrayList<>(); this.blacklistTeamId = new ArrayList<>();
this.progressBar = new ProgressBar(10, '-', "&a", "&7");
} }
@Override @Override
@ -793,8 +797,8 @@ public class ZKoth extends ZUtils implements Koth {
} }
@Override @Override
public AtomicInteger getRemainingSeconds() { public int getRemainingSeconds() {
return this.remainingSeconds; return this.remainingSeconds == null ? this.captureSeconds : this.remainingSeconds.get();
} }
@Override @Override
@ -843,4 +847,8 @@ public class ZKoth extends ZUtils implements Koth {
}).sorted(Comparator.comparingInt(PlayerResult::getPoints).reversed()).collect(Collectors.toList()); }).sorted(Comparator.comparingInt(PlayerResult::getPoints).reversed()).collect(Collectors.toList());
} }
@Override
public ProgressBar getProgressBar() {
return this.progressBar;
}
} }

View File

@ -5,6 +5,7 @@ import fr.maxlego08.koth.api.utils.HologramConfig;
import fr.maxlego08.koth.api.utils.PlayerResult; import fr.maxlego08.koth.api.utils.PlayerResult;
import fr.maxlego08.koth.api.utils.ScoreboardConfiguration; import fr.maxlego08.koth.api.utils.ScoreboardConfiguration;
import fr.maxlego08.koth.zcore.utils.Cuboid; import fr.maxlego08.koth.zcore.utils.Cuboid;
import fr.maxlego08.koth.zcore.utils.ProgressBar;
import fr.maxlego08.koth.zcore.utils.interfaces.CollectionConsumer; import fr.maxlego08.koth.zcore.utils.interfaces.CollectionConsumer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -278,7 +279,7 @@ public interface Koth {
* *
* @return An {@code AtomicInteger} with the remaining seconds. * @return An {@code AtomicInteger} with the remaining seconds.
*/ */
AtomicInteger getRemainingSeconds(); int getRemainingSeconds();
/** /**
* Gets the current player who is capturing the KOTH. * Gets the current player who is capturing the KOTH.
@ -297,5 +298,7 @@ public interface Koth {
PlayerResult getPlayer(int position); PlayerResult getPlayer(int position);
List<String> getBlacklistTeamId(); List<String> getBlacklistTeamId();
ProgressBar getProgressBar();
} }

View File

@ -8,6 +8,7 @@ import fr.maxlego08.koth.api.KothType;
import fr.maxlego08.koth.api.discord.DiscordWebhookConfig; import fr.maxlego08.koth.api.discord.DiscordWebhookConfig;
import fr.maxlego08.koth.api.utils.HologramConfig; import fr.maxlego08.koth.api.utils.HologramConfig;
import fr.maxlego08.koth.api.utils.ScoreboardConfiguration; 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.ZUtils;
import fr.maxlego08.koth.zcore.utils.loader.Loader; import fr.maxlego08.koth.zcore.utils.loader.Loader;
import fr.maxlego08.koth.zcore.utils.nms.ItemStackUtils; import fr.maxlego08.koth.zcore.utils.nms.ItemStackUtils;
@ -25,6 +26,7 @@ public class KothLoader extends ZUtils implements Loader<Koth> {
private final Loader<Location> locationLoader = new LocationLoader(); private final Loader<Location> locationLoader = new LocationLoader();
private final Loader<ScoreboardConfiguration> scoreboardLoaderLoader = new ScoreboardLoader(); private final Loader<ScoreboardConfiguration> scoreboardLoaderLoader = new ScoreboardLoader();
private final Loader<HologramConfig> hologramConfigLoader = new HologramLoader(); private final Loader<HologramConfig> hologramConfigLoader = new HologramLoader();
private final Loader<ProgressBar> progressBarLoader = new ProgressBarLoader();
public KothLoader(KothPlugin plugin) { public KothLoader(KothPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -70,8 +72,10 @@ public class KothLoader extends ZUtils implements Loader<Koth> {
List<String> blacklistTeamId = configuration.getStringList("blacklistTeamId"); List<String> 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, 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 @Override
@ -92,11 +96,11 @@ public class KothLoader extends ZUtils implements Loader<Koth> {
scoreboardLoaderLoader.save(koth.getCooldownScoreboard(), configuration, "scoreboard.cooldown."); scoreboardLoaderLoader.save(koth.getCooldownScoreboard(), configuration, "scoreboard.cooldown.");
scoreboardLoaderLoader.save(koth.getStartScoreboard(), configuration, "scoreboard.start."); scoreboardLoaderLoader.save(koth.getStartScoreboard(), configuration, "scoreboard.start.");
hologramConfigLoader.save(koth.getHologramConfig(), configuration, "hologram."); hologramConfigLoader.save(koth.getHologramConfig(), configuration, "hologram.");
progressBarLoader.save(koth.getProgressBar(), configuration, "progressBar.");
configuration.set("loot.type", koth.getLootType().name()); configuration.set("loot.type", koth.getLootType().name());
configuration.set("loot.random", koth.getRandomItemStack()); configuration.set("loot.random", koth.getRandomItemStack());
List<String> items = koth.getItemStacks().stream().map(ItemStackUtils::serializeItemStack).collect(Collectors.toList()); List<String> items = koth.getItemStacks().stream().map(ItemStackUtils::serializeItemStack).collect(Collectors.toList());
configuration.set("loot.items", items); configuration.set("loot.items", items);
} }
} }

View File

@ -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<ProgressBar> {
@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());
}
}

View File

@ -32,6 +32,8 @@ public class ScoreBoardManager extends ZUtils {
*/ */
public void schedule() { public void schedule() {
if (Config.schedulerMillisecond == 1000) return;
if (isRunning) if (isRunning)
return; return;
@ -217,7 +219,7 @@ public class ScoreBoardManager extends ZUtils {
*/ */
public void setLinesAndSchedule(CollectionConsumer<Player> lines) { public void setLinesAndSchedule(CollectionConsumer<Player> lines) {
this.lines = lines; this.lines = lines;
// this.schedule(); this.schedule();
} }
public KothScoreboard getScoreboard() { public KothScoreboard getScoreboard() {

View File

@ -2,51 +2,45 @@ package fr.maxlego08.koth.zcore.utils;
public class ProgressBar { public class ProgressBar {
private final int lenght; private final int length;
private final char symbol; private final char symbol;
private final String completedColor; private final String completedColor;
private final String notCompletedColor; private final String notCompletedColor;
/** public ProgressBar(int length, char symbol, String completedColor, String notCompletedColor) {
* @param lenght super();
* @param symbol this.length = length;
* @param completedColor this.symbol = symbol;
* @param notCompletedColor this.completedColor = completedColor;
*/ this.notCompletedColor = notCompletedColor;
public ProgressBar(int lenght, char symbol, String completedColor, String notCompletedColor) { }
super();
this.lenght = lenght;
this.symbol = symbol;
this.completedColor = completedColor;
this.notCompletedColor = notCompletedColor;
}
/** /**
* @return the lenght * @return the length
*/ */
public int getLenght() { public int getLength() {
return lenght; return length;
} }
/** /**
* @return the symbol * @return the symbol
*/ */
public char getSymbol() { public char getSymbol() {
return symbol; return symbol;
} }
/** /**
* @return the completedColor * @return the completedColor
*/ */
public String getCompletedColor() { public String getCompletedColor() {
return completedColor; return completedColor;
} }
/** /**
* @return the notCompletedColor * @return the notCompletedColor
*/ */
public String getNotCompletedColor() { public String getNotCompletedColor() {
return notCompletedColor; return notCompletedColor;
} }
} }

View File

@ -1149,8 +1149,8 @@ public abstract class ZUtils extends MessageUtils {
float percent = (float) current / max; float percent = (float) current / max;
int progressBars = (int) (totalBars * percent); int progressBars = (int) (totalBars * percent);
return Strings.repeat(completedColor + symbol, progressBars) return color(Strings.repeat(completedColor + symbol, progressBars)
+ Strings.repeat(notCompletedColor + symbol, totalBars - progressBars); + Strings.repeat(notCompletedColor + symbol, totalBars - progressBars));
} }
/** /**
@ -1162,7 +1162,7 @@ public abstract class ZUtils extends MessageUtils {
* @return string * @return string
*/ */
public String getProgressBar(int current, int max, ProgressBar progressBar) { 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()); progressBar.getCompletedColor(), progressBar.getNotCompletedColor());
} }

View File

@ -150,3 +150,10 @@ loot:
blacklistTeamId: blacklistTeamId:
- "0" - "0"
- "-1" - "-1"
# Configuration for the Progress Bar. Use by placeholders
progressBar:
length: 20
symbol: "|"
completedColor: "#2fedc7"
notCompletedColor: "#8f8f8f"