using PlayerRoles;
using LabApi.Features;
using LabApi.Features.Wrappers;
namespace VisibleSpectators;
///
/// Utility for formatting player display names and color mapping.
///
public static class PlayerDisplayUtil
{
private static readonly Dictionary ColorMap = new()
{
{ "DEFAULT", "FFFFFF" },
{ "PUMPKIN", "EE7600" },
{ "ARMY_GREEN", "4B5320" },
{ "MINT", "98FB98" },
{ "NICKEL", "727472" },
{ "CARMINE", "960018" },
{ "EMERALD", "50C878" },
{ "GREEN", "228B22" },
{ "LIME", "BFFF00" },
{ "POLICE_BLUE", "002DB3" },
{ "ORANGE", "FF9966" },
{ "SILVER_BLUE", "666699" },
{ "BLUE_GREEN", "4DFFB8" },
{ "MAGENTA", "FF0090" },
{ "YELLOW", "FAFF86" },
{ "TOMATO", "FF6448" },
{ "DEEP_PINK", "FF1493" },
{ "AQUA", "00FFFF" },
{ "CYAN", "00B7EB" },
{ "CRIMSON", "DC143C" },
{ "LIGHT_GREEN", "32CD32" },
{ "SILVER", "A0A0A0" },
{ "BROWN", "944710" },
{ "RED", "C50000" },
{ "PINK", "FF96DE" },
{ "LIGHT_RED", "FD8272" },
{ "PURPLE", "8137CE" },
{ "BLUE", "005EBC" },
{ "TEAL", "008080" },
{ "GOLD", "EFC01A" }
};
///
/// Returns a formatted display string for a player, with color.
///
public static string PlayerToDisplay(Player player)
{
if (player is not { IsReady: true }) return string.Empty;
const string defaultColor = "FFFFFF";
try
{
var groupColor = player.GroupColor;
if (string.IsNullOrEmpty(groupColor))
return $"{player.DisplayName}";
return ColorMap.TryGetValue(groupColor.ToUpper(), out var color)
? $"{player.DisplayName}"
: $"{player.DisplayName}";
}
catch
{
return $"{player.DisplayName}";
}
}
///
/// Returns true if the player is not Overwatch.
///
public static bool IsNotOverwatch(Player player)
{
return player != null && player.Role != RoleTypeId.Overwatch;
}
}