geforkt von SteamWar/BungeeCore
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:
Commit
7debcf1782
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
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.io.File;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.function.Predicate;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DevCommand extends BasicCommand {
|
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() {
|
public DevCommand() {
|
||||||
super("dev", "");
|
super("dev", "");
|
||||||
@ -42,56 +44,74 @@ public class DevCommand extends BasicCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if (!(sender instanceof ProxiedPlayer)) {
|
if (!(sender instanceof ProxiedPlayer))
|
||||||
return;
|
return;
|
||||||
}
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
String[] devServer = DevServerDir.list();
|
|
||||||
if (devServer == null || devServer.length == 0) {
|
updateDevServers();
|
||||||
|
if(devServers.isEmpty()) {
|
||||||
Message.send("DEV_NO_SERVER", sender);
|
Message.send("DEV_NO_SERVER", sender);
|
||||||
} else if (devServer.length == 1) {
|
} else if (devServers.size() == 1) {
|
||||||
String[] server = devServer[0].split("\\.");
|
player.connect(devServers.values().stream().findAny().get());
|
||||||
sendToServer((ProxiedPlayer) sender, server[0], Integer.parseInt(server[1]));
|
} 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 {
|
} else {
|
||||||
if (args.length == 0) {
|
ServerInfo info = devServers.get(args[0].toLowerCase());
|
||||||
send(devServer, (ProxiedPlayer) sender, s -> s.equalsIgnoreCase(sender.getName()), () -> Message.send("DEV_UNKNOWN_SERVER", sender));
|
if (info == null) {
|
||||||
} else {
|
Message.send("DEV_NO_SERVER", player);
|
||||||
send(devServer, (ProxiedPlayer) sender, args[0]::equalsIgnoreCase, () -> Message.send("DEV_NO_SERVER", sender));
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void send(String[] devServer, ProxiedPlayer sender, Predicate<String> test, Runnable error) {
|
player.connect(info);
|
||||||
for (String s : devServer) {
|
|
||||||
String[] server = s.split("\\.");
|
|
||||||
if (test.test(server[0])) {
|
|
||||||
sendToServer(sender, server[0], Integer.parseInt(server[1]));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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
|
@Override
|
||||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
if (!(sender instanceof ProxiedPlayer)) {
|
if (!(sender instanceof ProxiedPlayer) || args.length > 1) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
String[] devSever = DevServerDir.list();
|
|
||||||
if (devSever == null) {
|
updateDevServers();
|
||||||
return Collections.emptyList();
|
return devServers.keySet().stream().filter(s -> {
|
||||||
}
|
|
||||||
if (args.length > 1) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
return Arrays.stream(devSever).map(s -> s.split("\\.")).map(s -> s[0]).filter(s -> {
|
|
||||||
if (args.length == 0) return true;
|
if (args.length == 0) return true;
|
||||||
return s.startsWith(args[0]);
|
return s.startsWith(args[0].toLowerCase());
|
||||||
}).collect(Collectors.toList());
|
}).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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,9 +81,7 @@ public class TablistManager extends BasicListener {
|
|||||||
throw new SecurityException("Could not load icons", e);
|
throw new SecurityException("Could not load icons", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()){
|
ProxyServer.getInstance().getPlayers().forEach(p -> tablists.put(p, new Tablist(p)));
|
||||||
tablists.put(p, new Tablist(p));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void updateTablist(){
|
private synchronized void updateTablist(){
|
||||||
@ -161,6 +159,9 @@ public class TablistManager extends BasicListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setSlot(Icon icon, String name, int ping){
|
private void setSlot(Icon icon, String name, int ping){
|
||||||
|
if(pos / 20 >= getColumns())
|
||||||
|
return;
|
||||||
|
|
||||||
setSlot(pos % 20, pos / 20, icon, name, ping);
|
setSlot(pos % 20, pos / 20, icon, name, ping);
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
@ -191,17 +192,14 @@ public class TablistManager extends BasicListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
int size = subTablists.stream().map(TablistPart::size).reduce(Integer::sum).orElse(0);
|
return slimSize(null);
|
||||||
if(withHeaders)
|
|
||||||
size += Math.min(subTablists.size() - 1, 0);
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int slimSize(ProxiedPlayer viewer) {
|
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)
|
if(withHeaders)
|
||||||
size += Math.min(subTablists.size() - 1, 0);
|
size += subTablists.size() + Math.min(subTablists.size() - 1, 0);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,10 +210,10 @@ public class TablistManager extends BasicListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Tablist viewer, boolean slim) {
|
public void print(Tablist viewer, boolean slim) {
|
||||||
subTablists.forEach(tablist -> {
|
subTablists.forEach(tPart -> {
|
||||||
if(withHeaders)
|
if(withHeaders)
|
||||||
viewer.setSlot(gray, "§7§l" + tablist.name(), 1000);
|
viewer.setSlot(gray, "§7§l" + tPart.name(), 1000);
|
||||||
tablist.print(viewer, slim);
|
tPart.print(viewer, slim);
|
||||||
if(withHeaders)
|
if(withHeaders)
|
||||||
viewer.setSlot(darkGray, "", 1000);
|
viewer.setSlot(darkGray, "", 1000);
|
||||||
});
|
});
|
||||||
@ -256,13 +254,14 @@ public class TablistManager extends BasicListener {
|
|||||||
private TablistServer(ServerInfo info) {
|
private TablistServer(ServerInfo info) {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
subserver = Subserver.getSubserver(info);
|
subserver = Subserver.getSubserver(info);
|
||||||
for(ProxiedPlayer player : info.getPlayers()){
|
info.getPlayers().forEach(player -> players.add(new TablistPlayer(player, SteamwarUser.get(player.getUniqueId()).getUserGroup().getColorCode() + player.getName())));
|
||||||
players.add(new TablistPlayer(player, SteamwarUser.get(player.getUniqueId()).getUserGroup().getColorCode() + player.getName()));
|
|
||||||
}
|
|
||||||
players.sort((tp1, tp2) -> tp1.player.getName().compareToIgnoreCase(tp2.player.getName()));
|
players.sort((tp1, tp2) -> tp1.player.getName().compareToIgnoreCase(tp2.player.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean displaySlim(ProxiedPlayer viewer, ProxiedPlayer player){
|
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)
|
if(subserver != null && subserver.getType() == Servertype.ARENA && info.getPlayers().size() == 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -275,7 +274,7 @@ public class TablistManager extends BasicListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return 1 + players.size();
|
return players.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -283,10 +282,7 @@ public class TablistManager extends BasicListener {
|
|||||||
if(viewer.getServer().getInfo() == info)
|
if(viewer.getServer().getInfo() == info)
|
||||||
return size();
|
return size();
|
||||||
|
|
||||||
int size = 1;
|
return players.stream().mapToInt(player -> displaySlim(viewer, player.player) ? 1 : 0).sum();
|
||||||
for(TablistPlayer player : players)
|
|
||||||
size += displaySlim(viewer, player.player) ? 1 : 0;
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -300,10 +296,12 @@ public class TablistManager extends BasicListener {
|
|||||||
|
|
||||||
SteamwarUser user = SteamwarUser.get(viewer.player.getUniqueId());
|
SteamwarUser user = SteamwarUser.get(viewer.player.getUniqueId());
|
||||||
for(TablistPlayer player : players){
|
for(TablistPlayer player : players){
|
||||||
if(sameServer || (user.getTeam() != 0 && user.getTeam() == SteamwarUser.get(player.player.getUniqueId()).getTeam()))
|
if(slim && !displaySlim(viewer.player, player.player))
|
||||||
viewer.setSlot(BungeeTabListPlusAPI.getIconFromPlayer(player.player), player.defaultName.startsWith("§7") ? "§f" + player.player.getName() : player.defaultName, 1);
|
continue;
|
||||||
else if(!slim || displaySlim(viewer.player, player.player))
|
|
||||||
viewer.setSlot(BungeeTabListPlusAPI.getIconFromPlayer(player.player), player.defaultName, 500);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren