Archiviert
1
0

Merge pull request 'Better Tablist footer' (#215) from BetterTablistFooter into master

Reviewed-on: SteamWar/BungeeCore#215
Reviewed-by: Zeanon <thezeanon@gmail.com>
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2021-06-25 07:19:49 +02:00
Commit 09214a0212

Datei anzeigen

@ -41,6 +41,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class TablistManager extends BasicListener { public class TablistManager extends BasicListener {
@ -90,15 +91,10 @@ public class TablistManager extends BasicListener {
String serverName = server.getName(); String serverName = server.getName();
Subserver subserver = Subserver.getSubserver(server); Subserver subserver = Subserver.getSubserver(server);
List<ProxiedPlayer> players;
if (subserver != null && subserver.getType() == Servertype.BAUSERVER) { if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
players = playerMap.getOrDefault("Bau", new ArrayList<>()); playerMap.computeIfAbsent("Bau", s -> new ArrayList<>()).add(player);
players.add(player);
playerMap.putIfAbsent("Bau", players);
} else { } else {
players = playerMap.getOrDefault(serverName, new ArrayList<>()); playerMap.computeIfAbsent(serverName, s -> new ArrayList<>()).add(player);
players.add(player);
playerMap.putIfAbsent(serverName, players);
} }
} }
playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName()))); playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName())));
@ -131,15 +127,13 @@ public class TablistManager extends BasicListener {
} }
private String calcHeader(ProxiedPlayer player){ private String calcHeader(ProxiedPlayer player){
int phase = (seconds % 16) / 4; int phase = (seconds % 16) / 3;
switch(phase){ switch(phase){
case 0: case 0:
return Message.parse("TABLIST_PHASE_0", player, ProxyServer.getInstance().getPlayers().size());
case 1:
return Message.parse("TABLIST_PHASE_1", player); return Message.parse("TABLIST_PHASE_1", player);
case 2: case 1:
return Message.parse("TABLIST_PHASE_2", player); return Message.parse("TABLIST_PHASE_2", player);
case 3: case 2:
default: default:
return Message.parse("TABLIST_PHASE_DEFAULT", player); return Message.parse("TABLIST_PHASE_DEFAULT", player);
} }
@ -157,13 +151,18 @@ public class TablistManager extends BasicListener {
} }
private void refresh(){ private void refresh(){
try {
ServerInfo currentServer = player.getServer().getInfo(); ServerInfo currentServer = player.getServer().getInfo();
setHeader(calcHeader(player)); setHeader(calcHeader(player));
setFooter("§e" + currentServer.getName() + " " + getPing() + "§8ms"); // TABLIST_FOOTER=§e{0} {1}§8ms §eSpieler§8: §7{2}
setFooter("§e" + currentServer.getName() + " " + getPing() + "§8ms §eSpieler§8: §7" + ProxyServer.getInstance().getPlayers().size());
setSize(size, 20); setSize(size, 20);
if (size >= 5) {
refreshSlim(currentServer);
return;
}
try {
int i = 0; int i = 0;
for (String server : playerMap.navigableKeySet()) { for (String server : playerMap.navigableKeySet()) {
if (i > 0){ if (i > 0){
@ -191,6 +190,54 @@ public class TablistManager extends BasicListener {
} }
} }
private void refreshSlim(ServerInfo currentServer) {
try {
int i = 0;
boolean spacer = true;
for (String server : playerMap.navigableKeySet()) {
if (i > 0 && spacer) {
setSlot(i%20, i/20, darkGray, "", 1000);
i++;
}
spacer = true;
List<ProxiedPlayer> players = playerMap.get(server)
.stream()
.filter(p -> p.getServer().getInfo() == currentServer || SteamwarUser.get(p).getUserGroup() != UserGroup.Member)
.collect(Collectors.toList());
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);
}
int increment = playerMap.get(server).size() - players.size();
if (players.isEmpty()) {
server += " §7(" + increment + ")";
spacer = false;
} else if (increment != 0) {
server += " §7(+" + increment + ")";
}
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++;
}
}
while (i < size*20){
setSlot(i%20, i/20, darkGray, "", 1000);
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 String getTablistName(ProxiedPlayer p, boolean sameServer) {
Subserver server = Subserver.getSubserver(p); Subserver server = Subserver.getSubserver(p);
if(server != null){ if(server != null){