diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index 6a1d965..fd386a9 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -27,6 +27,7 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.Team; import de.steamwar.bungeecore.sql.UserGroup; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -173,17 +174,10 @@ public class TablistManager extends BasicListener { server = Message.parse("TABLIST_BAU", player); setSlot(i%20, i/20, gray, "§7§l" + server, 1000); i++; - for (ProxiedPlayer p : playerMap.get(server)){ - boolean sameServer = currentServer == p.getServer().getInfo(); - setSlot(i % 20, i / 20, BungeeTabListPlusAPI.getIconFromPlayer(p), getTablistName(p, sameServer), (sameServer ? 1 : 500)); - i++; - } + i = update(currentServer, playerMap.get(server), i); } - while (i < size*20){ - setSlot(i%20, i/20, darkGray, "", 1000); - i++; - } + finish(i); }catch(IndexOutOfBoundsException | NullPointerException e){ //Ignore IndexOutOfBoundsException //Ignore NPE, happens sometimes (only 1s long) when somebody is joining, server switching or disconnecting @@ -200,17 +194,23 @@ public class TablistManager extends BasicListener { i++; } spacer = true; + Team team = getTeam(player); List players = playerMap.get(server) .stream() - .filter(p -> p.getServer().getInfo() == currentServer || SteamwarUser.get(p).getUserGroup() != UserGroup.Member) + .filter(p -> p.getServer().getInfo() == currentServer || SteamwarUser.get(p).getUserGroup() != UserGroup.Member || (team != null && team == getTeam(p))) .collect(Collectors.toList()); + + Subserver subserver = Subserver.getSubserver(player); if (server.equals("Bau")) { - Subserver subserver = Subserver.getSubserver(player); if (subserver != null && subserver.getType() == Servertype.BAUSERVER) { players = playerMap.get(server); } server = Message.parse("TABLIST_BAU", player); } + if (subserver != null && subserver.getType() == Servertype.ARENA && playerMap.get(server).size() == 1) { + players = playerMap.get(server); + } + int increment = playerMap.get(server).size() - players.size(); if (players.isEmpty()) { server += " §7(" + increment + ")"; @@ -221,24 +221,40 @@ public class TablistManager extends BasicListener { setSlot(i%20, i/20, gray, "§7§l" + server, 1000); i++; - for (ProxiedPlayer p : players){ - boolean sameServer = currentServer == p.getServer().getInfo(); - setSlot(i % 20, i / 20, BungeeTabListPlusAPI.getIconFromPlayer(p), getTablistName(p, sameServer), (sameServer ? 1 : 500)); - i++; - } + i = update(currentServer, players, i); } - while (i < size*20){ - setSlot(i%20, i/20, darkGray, "", 1000); - i++; - } + // Shrink Down + setSize(Math.min((i + 19) / 20, 4), 20); + finish(i); }catch(IndexOutOfBoundsException | NullPointerException e){ //Ignore IndexOutOfBoundsException //Ignore NPE, happens sometimes (only 1s long) when somebody is joining, server switching or disconnecting } } - private String getTablistName(ProxiedPlayer p, boolean sameServer) { + private int update(ServerInfo currentServer, List players, int i) { + for (ProxiedPlayer p : players){ + boolean sameServer = currentServer == p.getServer().getInfo(); + setSlot(i % 20, i / 20, BungeeTabListPlusAPI.getIconFromPlayer(p), getTablistName(p), (sameServer ? 1 : 500)); + i++; + } + return i; + } + + private void finish(int i) { + while (i < size*20){ + setSlot(i%20, i/20, darkGray, "", 1000); + i++; + } + } + + private Team getTeam(ProxiedPlayer p) { + Team team = Team.get(SteamwarUser.get(p).getTeam()); + return team.getTeamId() <= 0 ? null : team; + } + + private String getTablistName(ProxiedPlayer p) { Subserver server = Subserver.getSubserver(p); if(server != null){ String tablistName = server.getTablistNames().get(p); @@ -249,13 +265,14 @@ public class TablistManager extends BasicListener { StringBuilder st = new StringBuilder(); UserGroup group = SteamwarUser.get(p).getUserGroup(); - //else st.append("§7"); - if(group == UserGroup.Member && sameServer) - st.append("§f"); - else + if (group == UserGroup.Member) { + Team team = getTeam(player); + if (team != null && team == getTeam(p)) st.append("§f"); + else st.append("§7"); + } else { st.append(group.getColorCode()); + } - // if (!sameServer) st.append("§o"); return st.append(p.getName()).toString(); } }