From 23291a7732c2e186446586c091e758a528c9eddb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 17 Dec 2023 21:32:24 +0100 Subject: [PATCH 1/2] Update Tablist colors --- .../steamwar/bungeecore/tablist/Tablist.java | 18 ++++++++-- .../bungeecore/tablist/TablistBuild.java | 12 +++++-- .../bungeecore/tablist/TablistServer.java | 35 +++++++++---------- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index 4ac0208..24f2031 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -21,6 +21,8 @@ package de.steamwar.bungeecore.tablist; import de.steamwar.bungeecore.Storage; import de.steamwar.messages.ChatSender; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserPerm; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; @@ -212,13 +214,19 @@ public class Tablist extends MessageToMessageDecoder { break; case ADD_PLAYER: boolean playerNotOnTeamserver = !Storage.teamServers.containsValue(player.getServer().getInfo()); + SteamwarUser viewee = SteamwarUser.get(player.getUniqueId()); for (PlayerListItem.Item item : list.getItems()) { item.setPing(1); if (playerNotOnTeamserver) { item.setDisplayName(new TextComponent()); item.setListed(false); } else if (item.getDisplayName() == null) { - item.setDisplayName(TextComponent.fromLegacy("§7" + item.getUsername())); + String color = "§f"; + UserPerm.Prefix prefix = SteamwarUser.get(item.getUuid()).prefix(); + if (prefix != UserPerm.emptyPrefix || !TablistServer.hasTeamColor(viewee, item.getUuid())) { + color = prefix.getChatPrefix(); + } + item.setDisplayName(TextComponent.fromLegacy(color + item.getUsername())); } item.setPublicKey(null); if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3) @@ -264,6 +272,7 @@ public class Tablist extends MessageToMessageDecoder { } boolean playerNotOnTeamserver = !Storage.teamServers.containsValue(player.getServer().getInfo()); + SteamwarUser viewee = SteamwarUser.get(player.getUniqueId()); for(PlayerListItemUpdate.Action action : actions) { switch (action) { case ADD_PLAYER: @@ -273,7 +282,12 @@ public class Tablist extends MessageToMessageDecoder { item.setDisplayName(new TextComponent()); item.setListed(false); } else if (item.getDisplayName() == null) { - item.setDisplayName(TextComponent.fromLegacy("§7" + item.getUsername())); + String color = "§f"; + UserPerm.Prefix prefix = SteamwarUser.get(item.getUuid()).prefix(); + if (prefix != UserPerm.emptyPrefix || !TablistServer.hasTeamColor(viewee, item.getUuid())) { + color = prefix.getChatPrefix(); + } + item.setDisplayName(TextComponent.fromLegacy(color + item.getUsername())); } item.setPublicKey(null); if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3) diff --git a/src/de/steamwar/bungeecore/tablist/TablistBuild.java b/src/de/steamwar/bungeecore/tablist/TablistBuild.java index 4f7f2b6..64f554e 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistBuild.java +++ b/src/de/steamwar/bungeecore/tablist/TablistBuild.java @@ -22,6 +22,8 @@ package de.steamwar.bungeecore.tablist; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; import de.steamwar.messages.ChatSender; +import de.steamwar.sql.SteamwarUser; +import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -62,9 +64,15 @@ public class TablistBuild implements TablistPart { tablist.add(new Item(null, viewer.parseToLegacy("TABLIST_BAU"), TablistServer.LIGHT_GRAY)); } + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); for (ServerInfo info : servers) { - TablistServer.teamify(players.get(info), player) - .forEach(((server == info) ? direct : tablist)::add); + players.get(info).forEach(item -> { + if (TablistServer.hasTeamColor(steamwarUser, item.getUuid())) { + ProxiedPlayer p = BungeeCord.getInstance().getPlayer(item.getUuid()); + item = new Item(p, true); + } + (server == info ? direct : tablist).add(item); + }); } } } diff --git a/src/de/steamwar/bungeecore/tablist/TablistServer.java b/src/de/steamwar/bungeecore/tablist/TablistServer.java index 812588d..3896f34 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistServer.java +++ b/src/de/steamwar/bungeecore/tablist/TablistServer.java @@ -21,20 +21,16 @@ package de.steamwar.bungeecore.tablist; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; -import de.steamwar.sql.SteamwarUser; import de.steamwar.messages.ChatSender; import de.steamwar.network.packets.common.FightInfoPacket; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.protocol.Property; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; -import java.util.stream.Stream; public class TablistServer implements TablistPart { @@ -77,7 +73,14 @@ public class TablistServer implements TablistPart { items.add(new Item(null, "§7§l" + server.getName(), LIGHT_GRAY)); } - teamify(players, player).forEach(items::add); + SteamwarUser steamwarUser = viewer.user(); + for (Item item : players) { + if (hasTeamColor(steamwarUser, item.getUuid())) { + ProxiedPlayer p = BungeeCord.getInstance().getPlayer(item.getUuid()); + item = new Item(p, true); + } + items.add(item); + } } private void addPlayers(String prefix, List teamPlayers, Collection onlinePlayers){ @@ -88,16 +91,12 @@ public class TablistServer implements TablistPart { ).forEachOrdered(player -> players.add(new Item(player.getUniqueId(), prefix + player.getName(), Item.playerProperties(player)))); } - public static Stream teamify(List players, ProxiedPlayer player) { - int team = SteamwarUser.get(player.getUniqueId()).getTeam(); - if (team == 0) return players.stream(); - return players.stream().map(item -> { - ProxiedPlayer p = BungeeCord.getInstance().getPlayer(item.getUuid()); - if (p == null) return item; - Subserver subserver = Subserver.getSubserver(p.getServer().getInfo()); - if (subserver != null && subserver.getType() == Servertype.ARENA) return item; - if (SteamwarUser.get(p.getUniqueId()).getTeam() != team) return item; - return new Item(p, true); - }); + public static boolean hasTeamColor(SteamwarUser viewer, UUID viewee) { + if (viewer.getTeam() == 0) return false; + ProxiedPlayer p = BungeeCord.getInstance().getPlayer(viewee); + if (p == null) return false; + Subserver subserver = Subserver.getSubserver(p.getServer().getInfo()); + if (subserver != null && subserver.getType() == Servertype.ARENA) return false; + return SteamwarUser.get(p.getUniqueId()).getTeam() == viewer.getTeam(); } } From e1a0c4802f548a3066fc9a4216ca92e2396f3ec5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 17 Dec 2023 21:57:41 +0100 Subject: [PATCH 2/2] Fix NPE --- .../steamwar/bungeecore/tablist/Tablist.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index 24f2031..9559007 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -222,9 +222,14 @@ public class Tablist extends MessageToMessageDecoder { item.setListed(false); } else if (item.getDisplayName() == null) { String color = "§f"; - UserPerm.Prefix prefix = SteamwarUser.get(item.getUuid()).prefix(); - if (prefix != UserPerm.emptyPrefix || !TablistServer.hasTeamColor(viewee, item.getUuid())) { - color = prefix.getChatPrefix(); + SteamwarUser steamwarUser = SteamwarUser.get(item.getUuid()); + if (steamwarUser == null) { + color = "§7"; + } else { + UserPerm.Prefix prefix = steamwarUser.prefix(); + if (prefix != UserPerm.emptyPrefix || !TablistServer.hasTeamColor(viewee, item.getUuid())) { + color = prefix.getChatPrefix(); + } } item.setDisplayName(TextComponent.fromLegacy(color + item.getUsername())); } @@ -283,9 +288,14 @@ public class Tablist extends MessageToMessageDecoder { item.setListed(false); } else if (item.getDisplayName() == null) { String color = "§f"; - UserPerm.Prefix prefix = SteamwarUser.get(item.getUuid()).prefix(); - if (prefix != UserPerm.emptyPrefix || !TablistServer.hasTeamColor(viewee, item.getUuid())) { - color = prefix.getChatPrefix(); + SteamwarUser steamwarUser = SteamwarUser.get(item.getUuid()); + if (steamwarUser == null) { + color = "§7"; + } else { + UserPerm.Prefix prefix = steamwarUser.prefix(); + if (prefix != UserPerm.emptyPrefix || !TablistServer.hasTeamColor(viewee, item.getUuid())) { + color = prefix.getChatPrefix(); + } } item.setDisplayName(TextComponent.fromLegacy(color + item.getUsername())); }