🚧 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 ``/koth stop``
- Create placeholder: ``%zkoth_capture_progress_bar%``
# 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.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());

View File

@ -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<String> blacklistTeamId;
private final ProgressBar progressBar;
private List<ItemStack> itemStacks;
private String name;
private int captureSeconds;
@ -86,7 +88,7 @@ public class ZKoth extends ZUtils implements Koth {
private DiscordWebhookConfig discordWebhookConfig;
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.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;
}
}

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.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<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.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<Koth> {
private final Loader<Location> locationLoader = new LocationLoader();
private final Loader<ScoreboardConfiguration> scoreboardLoaderLoader = new ScoreboardLoader();
private final Loader<HologramConfig> hologramConfigLoader = new HologramLoader();
private final Loader<ProgressBar> progressBarLoader = new ProgressBarLoader();
public KothLoader(KothPlugin plugin) {
this.plugin = plugin;
@ -70,8 +72,10 @@ public class KothLoader extends ZUtils implements Loader<Koth> {
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,
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<Koth> {
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<String> items = koth.getItemStacks().stream().map(ItemStackUtils::serializeItemStack).collect(Collectors.toList());
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() {
if (Config.schedulerMillisecond == 1000) return;
if (isRunning)
return;
@ -217,7 +219,7 @@ public class ScoreBoardManager extends ZUtils {
*/
public void setLinesAndSchedule(CollectionConsumer<Player> lines) {
this.lines = lines;
// this.schedule();
this.schedule();
}
public KothScoreboard getScoreboard() {

View File

@ -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;
}
}

View File

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

View File

@ -126,4 +126,4 @@ defaultPlayerResult:
points: 0
teamName: "X"
teamId: "X"
teamLeader: "X"
teamLeader: "X"

View File

@ -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"
- "-1"
# Configuration for the Progress Bar. Use by placeholders
progressBar:
length: 20
symbol: "|"
completedColor: "#2fedc7"
notCompletedColor: "#8f8f8f"