🚧 Create 8 placeholders

This commit is contained in:
Maxlego08 2024-02-29 18:14:48 +01:00
parent 8790dc4216
commit 4cc79eba64
10 changed files with 198 additions and 6 deletions

View File

@ -351,7 +351,7 @@ apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
When you convey a copy of a covered work, you may at your buttonOption
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
@ -570,7 +570,7 @@ address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
buttonOption of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
@ -637,7 +637,7 @@ the "copyright" line and a pointer to where the full notice is found.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your buttonOption) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of

View File

@ -1,5 +1,16 @@
# Unreleased
- Create placeholder: ``%zkoth_capture_max_seconds%``
- Create placeholder: ``%zkoth_capture_max_formats%``
- Create placeholder: ``%zkoth_score``
- Create placeholder: ``%zkoth_score_player_<position>``
- Create placeholder: ``%zkoth_score_points_<position>``
- Create placeholder: ``%zkoth_score_team_id_<position>``
- Create placeholder: ``%zkoth_score_team_name_<position>``
- Create placeholder: ``%zkoth_score_team_leader_<position>``
- Create koth option: ``blacklistTeamId``
- Change TeamKoth interface to use OfflinePlayer instance of Player
# 3.0.1
- Add SaberFaction and FactionUUID support

View File

@ -3,9 +3,11 @@ package fr.maxlego08.koth;
import fr.maxlego08.koth.api.Koth;
import fr.maxlego08.koth.api.KothStatus;
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.builder.TimerBuilder;
import org.bukkit.entity.Player;
import java.util.Optional;
@ -35,6 +37,15 @@ public class KothPlaceholder {
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("capture_max_seconds", koth -> String.valueOf(koth.getCaptureSeconds()));
this.register("capture_max_formats", koth -> TimerBuilder.getStringTime(koth.getCaptureSeconds()));
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("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);
@ -61,6 +72,21 @@ public class KothPlaceholder {
placeholder.register(key, (a, b) -> onFirstKoth(consumer));
}
private void register(String key, ReturnBiConsumer<Player, Koth, String> consumer) {
LocalPlaceholder placeholder = LocalPlaceholder.getInstance();
placeholder.register(key, (a, b) -> onFirstKoth(a, consumer));
}
private void registerS(String key, ReturnBiConsumer<String, Koth, String> consumer) {
LocalPlaceholder placeholder = LocalPlaceholder.getInstance();
placeholder.register(key, (a, b) -> onFirstKoth(b, consumer));
}
private void registerPosition(String key, ReturnBiConsumer<Integer, Koth, String> consumer) {
LocalPlaceholder placeholder = LocalPlaceholder.getInstance();
placeholder.register(key, (a, b) -> onFirstKothPosition(b, consumer));
}
public String onFirstKoth(ReturnConsumer<Koth> consumer) {
Optional<Koth> optional = this.kothManager.getActiveKoths().stream().findFirst();
if (optional.isPresent()) {
@ -68,4 +94,29 @@ public class KothPlaceholder {
} else return Config.noKoth;
}
public String onFirstKoth(Player player, ReturnBiConsumer<Player, Koth, String> consumer) {
Optional<Koth> optional = this.kothManager.getActiveKoths().stream().findFirst();
if (optional.isPresent()) {
return consumer.accept(player, optional.get());
} else return Config.noKoth;
}
public String onFirstKoth(String argument, ReturnBiConsumer<String, Koth, String> consumer) {
Optional<Koth> optional = this.kothManager.getActiveKoths().stream().findFirst();
if (optional.isPresent()) {
return consumer.accept(argument, optional.get());
} else return Config.noKoth;
}
public String onFirstKothPosition(String argument, ReturnBiConsumer<Integer, Koth, String> consumer) {
Optional<Koth> optional = this.kothManager.getActiveKoths().stream().findFirst();
if (optional.isPresent()) {
try {
return consumer.accept(Integer.parseInt(argument), optional.get());
} catch (Exception exception) {
return consumer.accept(-1, optional.get());
}
} else return Config.noKoth;
}
}

View File

@ -15,6 +15,7 @@ import fr.maxlego08.koth.api.events.KothStartEvent;
import fr.maxlego08.koth.api.events.KothStopEvent;
import fr.maxlego08.koth.api.events.KothWinEvent;
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.hook.teams.NoneHook;
import fr.maxlego08.koth.save.Config;
@ -29,6 +30,7 @@ import fr.mrmicky.fastboard.FastBoard;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
@ -40,6 +42,7 @@ import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -66,6 +69,7 @@ public class ZKoth extends ZUtils implements Koth {
private final boolean enableEverySecondsCapMessage;
private final HologramConfig hologramConfig;
private final KothLootType kothLootType;
private final List<String> blacklistTeamId;
private List<ItemStack> itemStacks;
private String name;
private int captureSeconds;
@ -80,8 +84,9 @@ public class ZKoth extends ZUtils implements Koth {
private TimerTask timerTask;
private TimerTask timerTaskStop;
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) {
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) {
this.plugin = plugin;
this.fileName = fileName;
this.kothType = kothType;
@ -103,6 +108,7 @@ public class ZKoth extends ZUtils implements Koth {
this.kothLootType = kothLootType;
this.discordWebhookConfig = discordWebhookConfig;
this.randomItemStacks = randomItemStacks;
this.blacklistTeamId = blacklistTeamId;
}
public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation) {
@ -125,6 +131,7 @@ public class ZKoth extends ZUtils implements Koth {
this.itemStacks = new ArrayList<>();
this.kothLootType = KothLootType.NONE;
this.randomItemStacks = 0;
this.blacklistTeamId = new ArrayList<>();
}
@Override
@ -415,6 +422,9 @@ public class ZKoth extends ZUtils implements Koth {
if (this.kothStatus != KothStatus.START) return;
this.kothTeam = kothTeam;
if (this.blacklistTeamId.contains(this.kothTeam.getTeamId(player))) return;
Cuboid cuboid = this.getCuboid();
if (this.currentPlayer == null && cuboid.contains(player.getLocation())) {
@ -553,6 +563,7 @@ public class ZKoth extends ZUtils implements Koth {
case SCORE:
// case TIMER:
this.playersValues.put(this.currentPlayer.getUniqueId(), this.getValue(this.currentPlayer) + 1);
this.playerResults.clear(); // Clear cache
break;
}
}
@ -796,4 +807,42 @@ public class ZKoth extends ZUtils implements Koth {
this.plugin.getKothHologram().update(this);
this.plugin.getScoreBoardManager().update();
}
@Override
public int getScore(Player player) {
return this.playersValues.getOrDefault(player.getUniqueId(), 0);
}
@Override
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);
}
@Override
public List<String> getBlacklistTeamId() {
return this.blacklistTeamId;
}
private void sortScores() {
// If the list is not empty, then there is already a cache.
if (!this.playerResults.isEmpty()) return;
this.playerResults = this.playersValues.entrySet().stream().map(entry -> {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(entry.getKey());
int points = entry.getValue();
String teamName = this.kothTeam.getTeamName(offlinePlayer);
String teamLeader = this.kothTeam.getLeaderName(offlinePlayer);
String teamId = this.kothTeam.getTeamId(offlinePlayer);
return new PlayerResult(offlinePlayer.getName(), points, teamName, teamId, teamLeader);
}).sorted(Comparator.comparingInt(PlayerResult::getPoints).reversed()).collect(Collectors.toList());
}
}

View File

@ -2,6 +2,7 @@ package fr.maxlego08.koth.api;
import fr.maxlego08.koth.api.discord.DiscordWebhookConfig;
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.interfaces.CollectionConsumer;
@ -290,5 +291,11 @@ public interface Koth {
* Updates the display elements associated with the KOTH game, such as scoreboards or holograms, based on the current game state.
*/
void updateDisplay();
int getScore(Player player);
PlayerResult getPlayer(int position);
List<String> getBlacklistTeamId();
}

View File

@ -0,0 +1,38 @@
package fr.maxlego08.koth.api.utils;
public class PlayerResult {
private final String playerName;
private final int points;
private final String teamName;
private final String teamId;
private final String teamLeader;
public PlayerResult(String playerName, int points, String teamName, String teamId, String teamLeader) {
this.playerName = playerName;
this.points = points;
this.teamName = teamName;
this.teamId = teamId;
this.teamLeader = teamLeader;
}
public String getPlayerName() {
return playerName;
}
public int getPoints() {
return points;
}
public String getTeamName() {
return teamName;
}
public String getTeamId() {
return teamId;
}
public String getTeamLeader() {
return teamLeader;
}
}

View File

@ -68,8 +68,10 @@ public class KothLoader extends ZUtils implements Loader<Koth> {
List<ItemStack> itemStacks = configuration.getStringList("loot.items").stream().map(ItemStackUtils::deserializeItemStack).collect(Collectors.toList());
int randomItemStacks = configuration.getInt("loot.random", 0);
List<String> blacklistTeamId = configuration.getStringList("blacklistTeamId");
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);
startScoreboard, cooldownStart, stopAfterSeconds, enableStartCapMessage, enableLooseCapMessage, enableEverySecondsCapMessage, hologramConfig, itemStacks, kothLootType, discordWebhookConfig, randomItemStacks, blacklistTeamId);
}
@Override

View File

@ -1,6 +1,7 @@
package fr.maxlego08.koth.save;
import fr.maxlego08.koth.KothPlugin;
import fr.maxlego08.koth.api.utils.PlayerResult;
import fr.maxlego08.koth.zcore.utils.storage.Persist;
import fr.maxlego08.koth.zcore.utils.storage.Savable;
import org.bukkit.configuration.file.YamlConfiguration;
@ -21,6 +22,8 @@ public class Config {
public static String noKoth = "X";
public static int removeChestSec = 120;
public static PlayerResult defaultPlayerResult = new PlayerResult("X", 0, "X", "X", "X");
/**
* static Singleton instance.
*/
@ -63,6 +66,14 @@ public class Config {
noFaction = configuration.getString("noKoth", "X");
schedulerMillisecond = configuration.getLong("schedulerMillisecond", 1000);
removeChestSec = configuration.getInt("removeChestSec", 120);
defaultPlayerResult = new PlayerResult(
configuration.getString("defaultPlayerResult.playerName", "X"),
configuration.getInt("defaultPlayerResult.points", 0),
configuration.getString("defaultPlayerResult.teamName", "X"),
configuration.getString("defaultPlayerResult.teamId", "X"),
configuration.getString("defaultPlayerResult.teamLeader", "X")
);
}
}

View File

@ -38,6 +38,15 @@
# %zkoth_spawn_format% - Current koth spawn seconds formatted
# %zkoth_capture_seconds% - Current koth capture seconds
# %zkoth_capture_format% - Current koth capture seconds formatted
# %zkoth_capture_max_seconds% - Current koth max capture seconds
# %zkoth_capture_max_formats% - Current koth max capture seconds formatted
# %zkoth_score% - Score of player
# %zkoth_score_player_<position>% - Player name at position
# %zkoth_score_points_<position>% - Points at position
# %zkoth_score_team_name_<position>% - Team name at position
# %zkoth_score_team_id_<position>% - Team id at position
# %zkoth_score_team_leader_<position>% - Team leader name at position
# %zkoth_score_player_<position>% - Player name at position
# %zkoth_player_name% - Current koth capture player name
# %zkoth_team_name% - Current koth capture player team name
# %zkoth_team_id% - Current koth capture player team id
@ -109,4 +118,12 @@ noKoth: 'X'
schedulerMillisecond: 1000
removeChestSec: 120
removeChestSec: 120
# Value that will be used for score placeholders if the position does not exist.
defaultPlayerResult:
playerName: "X"
points: 0
teamName: "X"
teamId: "X"
teamLeader: "X"

View File

@ -144,3 +144,9 @@ loot:
type: NONE
# Use /koth loot <koth name>
items: []
# 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"