Archiviert
1
0

Merge pull request 'Fix tablist issues' (#261) from tablist into master

Reviewed-on: SteamWar/BungeeCore#261
Reviewed-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Lixfel 2021-10-12 11:44:42 +02:00
Commit 7debcf1782
2 geänderte Dateien mit 82 neuen und 64 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
@ -27,14 +28,15 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.File;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Predicate;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class DevCommand extends BasicCommand {
private final File DevServerDir = new File("/configs/DevServer");
private final File devServerDir = new File("/configs/DevServer");
private final Map<String, ServerInfo> devServers = new HashMap<>();
public DevCommand() {
super("dev", "");
@ -42,56 +44,74 @@ public class DevCommand extends BasicCommand {
@Override
public void execute(CommandSender sender, String[] args) {
if (!(sender instanceof ProxiedPlayer)) {
if (!(sender instanceof ProxiedPlayer))
return;
}
String[] devServer = DevServerDir.list();
if (devServer == null || devServer.length == 0) {
ProxiedPlayer player = (ProxiedPlayer) sender;
updateDevServers();
if(devServers.isEmpty()) {
Message.send("DEV_NO_SERVER", sender);
} else if (devServer.length == 1) {
String[] server = devServer[0].split("\\.");
sendToServer((ProxiedPlayer) sender, server[0], Integer.parseInt(server[1]));
} else if (devServers.size() == 1) {
player.connect(devServers.values().stream().findAny().get());
} else if (args.length == 0) {
ServerInfo info = devServers.get(player.getName().toLowerCase());
if (info == null) {
Message.send("DEV_UNKNOWN_SERVER", player);
return;
}
player.connect(info);
} else {
if (args.length == 0) {
send(devServer, (ProxiedPlayer) sender, s -> s.equalsIgnoreCase(sender.getName()), () -> Message.send("DEV_UNKNOWN_SERVER", sender));
} else {
send(devServer, (ProxiedPlayer) sender, args[0]::equalsIgnoreCase, () -> Message.send("DEV_NO_SERVER", sender));
ServerInfo info = devServers.get(args[0].toLowerCase());
if (info == null) {
Message.send("DEV_NO_SERVER", player);
return;
}
}
}
private void send(String[] devServer, ProxiedPlayer sender, Predicate<String> test, Runnable error) {
for (String s : devServer) {
String[] server = s.split("\\.");
if (test.test(server[0])) {
sendToServer(sender, server[0], Integer.parseInt(server[1]));
break;
}
player.connect(info);
}
error.run();
}
private void sendToServer(ProxiedPlayer proxiedPlayer, String name, int port) {
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
ServerInfo serverInfo = ProxyServer.getInstance().constructServerInfo("Dev-" + name, address, "SteamWar.de - Subserver", false);
proxiedPlayer.connect(serverInfo);
}
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
if (!(sender instanceof ProxiedPlayer)) {
if (!(sender instanceof ProxiedPlayer) || args.length > 1) {
return Collections.emptyList();
}
String[] devSever = DevServerDir.list();
if (devSever == null) {
return Collections.emptyList();
}
if (args.length > 1) {
return Collections.emptyList();
}
return Arrays.stream(devSever).map(s -> s.split("\\.")).map(s -> s[0]).filter(s -> {
updateDevServers();
return devServers.keySet().stream().filter(s -> {
if (args.length == 0) return true;
return s.startsWith(args[0]);
return s.startsWith(args[0].toLowerCase());
}).collect(Collectors.toList());
}
private void updateDevServers() {
String[] serverFiles = devServerDir.list();
Map<String, Integer> devServerFiles = new HashMap<>();
if(serverFiles != null) {
for(String serverFile : serverFiles) {
String[] server = serverFile.split("\\.");
devServerFiles.put(server[0], Integer.parseInt(server[1]));
}
}
devServers.entrySet().removeIf(entry -> {
if(!devServerFiles.containsKey(entry.getKey())) {
ProxyServer.getInstance().getServers().remove(entry.getValue().getName());
return true;
}
return false;
});
devServerFiles.forEach((key, value) -> {
if (devServers.containsKey(key))
return;
SteamwarUser user = SteamwarUser.get(key);
ServerInfo info = ProxyServer.getInstance().constructServerInfo("Dev " + user.getUserName(), new InetSocketAddress("127.0.0.1", value), "SteamWar.de - Subserver", false);
ProxyServer.getInstance().getServers().put(info.getName(), info);
devServers.put(user.getUserName().toLowerCase(), info);
});
}
}

Datei anzeigen

@ -81,9 +81,7 @@ public class TablistManager extends BasicListener {
throw new SecurityException("Could not load icons", e);
}
for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()){
tablists.put(p, new Tablist(p));
}
ProxyServer.getInstance().getPlayers().forEach(p -> tablists.put(p, new Tablist(p)));
}
private synchronized void updateTablist(){
@ -161,6 +159,9 @@ public class TablistManager extends BasicListener {
}
private void setSlot(Icon icon, String name, int ping){
if(pos / 20 >= getColumns())
return;
setSlot(pos % 20, pos / 20, icon, name, ping);
pos++;
}
@ -191,17 +192,14 @@ public class TablistManager extends BasicListener {
@Override
public int size() {
int size = subTablists.stream().map(TablistPart::size).reduce(Integer::sum).orElse(0);
if(withHeaders)
size += Math.min(subTablists.size() - 1, 0);
return size;
return slimSize(null);
}
@Override
public int slimSize(ProxiedPlayer viewer) {
int size = subTablists.stream().map(tablist -> tablist.slimSize(viewer)).reduce(Integer::sum).orElse(0);
int size = subTablists.stream().mapToInt(tPart -> viewer == null ? tPart.size() : tPart.slimSize(viewer)).sum();
if(withHeaders)
size += Math.min(subTablists.size() - 1, 0);
size += subTablists.size() + Math.min(subTablists.size() - 1, 0);
return size;
}
@ -212,10 +210,10 @@ public class TablistManager extends BasicListener {
@Override
public void print(Tablist viewer, boolean slim) {
subTablists.forEach(tablist -> {
subTablists.forEach(tPart -> {
if(withHeaders)
viewer.setSlot(gray, "§7§l" + tablist.name(), 1000);
tablist.print(viewer, slim);
viewer.setSlot(gray, "§7§l" + tPart.name(), 1000);
tPart.print(viewer, slim);
if(withHeaders)
viewer.setSlot(darkGray, "", 1000);
});
@ -256,13 +254,14 @@ public class TablistManager extends BasicListener {
private TablistServer(ServerInfo info) {
this.info = info;
subserver = Subserver.getSubserver(info);
for(ProxiedPlayer player : info.getPlayers()){
players.add(new TablistPlayer(player, SteamwarUser.get(player.getUniqueId()).getUserGroup().getColorCode() + player.getName()));
}
info.getPlayers().forEach(player -> players.add(new TablistPlayer(player, SteamwarUser.get(player.getUniqueId()).getUserGroup().getColorCode() + player.getName())));
players.sort((tp1, tp2) -> tp1.player.getName().compareToIgnoreCase(tp2.player.getName()));
}
private boolean displaySlim(ProxiedPlayer viewer, ProxiedPlayer player){
if(viewer.getServer().getInfo() == info)
return true;
if(subserver != null && subserver.getType() == Servertype.ARENA && info.getPlayers().size() == 1)
return true;
@ -275,7 +274,7 @@ public class TablistManager extends BasicListener {
@Override
public int size() {
return 1 + players.size();
return players.size();
}
@Override
@ -283,10 +282,7 @@ public class TablistManager extends BasicListener {
if(viewer.getServer().getInfo() == info)
return size();
int size = 1;
for(TablistPlayer player : players)
size += displaySlim(viewer, player.player) ? 1 : 0;
return size;
return players.stream().mapToInt(player -> displaySlim(viewer, player.player) ? 1 : 0).sum();
}
@Override
@ -300,10 +296,12 @@ public class TablistManager extends BasicListener {
SteamwarUser user = SteamwarUser.get(viewer.player.getUniqueId());
for(TablistPlayer player : players){
if(sameServer || (user.getTeam() != 0 && user.getTeam() == SteamwarUser.get(player.player.getUniqueId()).getTeam()))
viewer.setSlot(BungeeTabListPlusAPI.getIconFromPlayer(player.player), player.defaultName.startsWith("§7") ? "§f" + player.player.getName() : player.defaultName, 1);
else if(!slim || displaySlim(viewer.player, player.player))
viewer.setSlot(BungeeTabListPlusAPI.getIconFromPlayer(player.player), player.defaultName, 500);
if(slim && !displaySlim(viewer.player, player.player))
continue;
int ping = sameServer ? 1 : 500;
String name = player.defaultName.startsWith("§7") && user.getTeam() != 0 && user.getTeam() == SteamwarUser.get(player.player.getUniqueId()).getTeam() ? "§f" + player.player.getName() : player.defaultName;
viewer.setSlot(BungeeTabListPlusAPI.getIconFromPlayer(player.player), name, ping);
}
}
}