mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
fix: rework nametag application
This commit is contained in:
2 files changed
+20
-7
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package com.github.alathra.AlathranWars.commands;
|
||||
|
||||
import com.github.alathra.AlathranWars.AlathranWars;
|
||||
import com.github.alathra.AlathranWars.hooks.NameColorHandler;
|
||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
@@ -12,6 +13,7 @@ import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -24,7 +26,8 @@ public class AdminCommands {
|
||||
.withSubcommands(
|
||||
commandItem(),
|
||||
commandWar(),
|
||||
commandSiege()
|
||||
commandSiege(),
|
||||
commandNames()
|
||||
)
|
||||
.executes((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
@@ -114,4 +117,11 @@ public class AdminCommands {
|
||||
SiegeCommands.commandList()
|
||||
);
|
||||
}
|
||||
|
||||
private CommandAPICommand commandNames() {
|
||||
return new CommandAPICommand("updatenames")
|
||||
.executesPlayer((player, commandArguments) -> {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> NameColorHandler.getInstance().calculatePlayerColors(p));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import java.util.*;
|
||||
|
||||
public class NameColorHandler {
|
||||
private static NameColorHandler instance;
|
||||
private Set<Player> playerHasChanges = new HashSet<>(); // A list containing all players with active changes due to war
|
||||
private Map<Player, String> playerColor = new HashMap<>();
|
||||
private Map<Player, String> playerInitial = new HashMap<>();
|
||||
|
||||
@@ -29,7 +28,6 @@ public class NameColorHandler {
|
||||
|
||||
public void calculatePlayerColors(Player p) {
|
||||
if (!WarController.getInstance().isPlayerInAnyWars(p)) {
|
||||
playerHasChanges.remove(p);
|
||||
playerColor.remove(p);
|
||||
playerInitial.remove(p);
|
||||
return;
|
||||
@@ -40,19 +38,24 @@ public class NameColorHandler {
|
||||
if (war.isEmpty())
|
||||
return;
|
||||
|
||||
final boolean isSide1 = war.get().getPlayerSide(p).equals(war.get().getSide1());
|
||||
final boolean isPlayerSurrendered = war.get().getSide1().isPlayerSurrendered(p) || war.get().getSide2().isPlayerSurrendered(p);
|
||||
|
||||
if (isSide1) {
|
||||
if (isPlayerSurrendered)
|
||||
return;
|
||||
|
||||
final boolean isSideOne = war.get().getSide1().isPlayerOnSide(p);
|
||||
|
||||
if (isSideOne) {
|
||||
playerColor.put(p, "<red>");
|
||||
} else {
|
||||
playerColor.put(p, "<blue>");
|
||||
}
|
||||
playerInitial.put(p, war.get().getPlayerSide(p).getName().substring(0, 1).toUpperCase());
|
||||
playerHasChanges.add(p);
|
||||
}
|
||||
|
||||
public boolean isPlayerUsingModifiedName(Player p) {
|
||||
return playerHasChanges.contains(p);
|
||||
calculatePlayerColors(p);
|
||||
return WarController.getInstance().isPlayerInAnyWars(p);
|
||||
}
|
||||
|
||||
public String getPlayerTabNameColor(Player p) {
|
||||
|
||||
Reference in new issue
Block a user