Merge branch 'release/3.0.3'

This commit is contained in:
Maxlego08 2024-03-04 16:42:54 +01:00
commit 0af7594c06
16 changed files with 144 additions and 79 deletions

View File

@ -1,5 +1,14 @@
# Unreleased
# 3.0.3
- Fix NMS
- Fix ``/koth stop``
- Create placeholder: ``%zkoth_capture_progress_bar%``
- Create placeholder: ``%zkoth_progress_bar_score_points_<position>%``
- Create placeholder: ``%zkoth_progress_bar_score%``
- Change auto-completion for /koth stop
# 3.0.2
- Create placeholder: ``%zkoth_capture_max_seconds%``

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.maxlego08.koth</groupId>
<artifactId>zKoth</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.maxlego08.koth</groupId>
<artifactId>zKoth</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -320,4 +320,8 @@ public class KothManager extends ZUtils implements Savable {
message(sender, Message.COMMAND_CREATE, "%command%", command);
this.saveKoth(koth);
}
public List<String> getActiveNameKoths() {
return this.getEnableKoths().stream().map(Koth::getFileName).collect(Collectors.toList());
}
}

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,19 +34,24 @@ 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("progress_bar_score_points_", (position, koth) -> getProgressBar(koth.getPlayer(position).getPoints(), 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());
this.registerPosition("score_team_id_", (position, koth) -> koth.getPlayer(position).getTeamId());
this.registerPosition("score_team_leader_", (position, koth) -> koth.getPlayer(position).getTeamLeader());
this.register("score", (player, koth) -> String.valueOf(koth.getScore(player)));
this.register("progress_bar_score", (player, koth) -> getProgressBar(koth.getScore(player), koth.getCaptureSeconds(), koth.getProgressBar()));
this.register("player_name", koth -> koth.getCurrentPlayer() != null ? koth.getCurrentPlayer().getName() : Config.noPlayer);
this.register("team_name", koth -> koth.getCurrentPlayer() != null ? this.kothManager.getKothTeam().getTeamName(koth.getCurrentPlayer()) : Config.noFaction);

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
@ -291,7 +295,7 @@ public class ZKoth extends ZUtils implements Koth {
@Override
public void stop(CommandSender sender) {
if (this.kothStatus != KothStatus.START) {
if (this.kothStatus == KothStatus.STOP) {
message(sender, Message.EVENT_DISABLE);
return;
}
@ -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
@ -817,9 +821,7 @@ public class ZKoth extends ZUtils implements Koth {
public PlayerResult getPlayer(int position) {
this.sortScores();
System.out.println((this.playerResults.size() > position) + " -< " + this.playerResults.size() +" - " + position);
if (this.playerResults.size() > position) return Config.defaultPlayerResult;
System.out.println(this.playerResults.get(position - 1));
return this.playerResults.get(position - 1);
}
@ -845,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

@ -13,7 +13,7 @@ public class CommandKothStop extends VCommand {
this.setPermission(Permission.ZKOTH_STOP);
this.addSubCommand("stop");
this.setDescription(Message.DESCRIPTION_SPAWN);
this.addRequireArg("name", (a,b) -> plugin.getKothManager().getNameKoths());
this.addRequireArg("name", (a, b) -> plugin.getKothManager().getActiveNameKoths());
}
@Override

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,30 +2,24 @@ package fr.maxlego08.koth.zcore.utils;
public class ProgressBar {
private final int lenght;
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) {
public ProgressBar(int length, char symbol, String completedColor, String notCompletedColor) {
super();
this.lenght = lenght;
this.length = length;
this.symbol = symbol;
this.completedColor = completedColor;
this.notCompletedColor = notCompletedColor;
}
/**
* @return the lenght
* @return the length
*/
public int getLenght() {
return lenght;
public int getLength() {
return length;
}
/**

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

@ -42,8 +42,8 @@ public enum NmsVersion {
V_1_20(1200),
V_1_20_1(1201),
V_1_20_2(1202),
V_1_20_3(1204),
V_1_20_4(1203),
V_1_20_3(1203),
V_1_20_4(1204),
V_1_21(1210),
;

View File

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