SteamWar/BungeeCore
Archiviert
13
2

Add StatCommand #213

Manuell gemergt
YoyoNow hat 7 Commits von StatCommand nach master 2021-07-12 09:14:19 +02:00 zusammengeführt
2 geänderte Dateien mit 85 neuen und 28 gelöschten Zeilen
Nur Änderungen aus Commit f1f13da3d1 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -89,7 +89,7 @@ public class SubserverSystem {
* @return
* The new started subserver.
*/
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, int prepareSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
public static synchronized Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, int prepareSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
//Generate missing parameters
int port = freePort(FIRST_ARENA_PORT);
@ -179,7 +179,7 @@ public class SubserverSystem {
startArena(m, map, -1, checkSchemId, prepareSchemId, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null, false).sendPlayer(p);
}
private static void sendToBau(ProxiedPlayer p, UUID owner, String prototype, String worldFolder, String serverJar, String worldDir, String worldName, String xmx, String serverName){
private static synchronized void sendToBau(ProxiedPlayer p, UUID owner, String prototype, String worldFolder, String serverJar, String worldDir, String worldName, String xmx, String serverName){
if(bauRunning(p, owner))
return;
@ -239,15 +239,25 @@ public class SubserverSystem {
List<String> cmd = new ArrayList<>();
boolean jdk11 = serverJar.contains("1.15.2");
if(!steamwarStartAvailable() && lixfelStartAvailable()){
boolean fallback = false;
if (!steamwarStartAvailable()) {
cmd.add("ssh");
cmd.add("-L");
cmd.add(port + ":localhost:" + port);
cmd.add("lx");
if (remoteStartAvailable("lx")) {
cmd.add("lx");
} else if (remoteStartAvailable("az")) {
cmd.add("az");
} else {
fallback = true;
}
cmd.add("cd");
cmd.add(directory.getPath());
cmd.add(";");
}
if (fallback) {
cmd.clear();
}
if(jdk11)
cmd.add("/usr/lib/jvm/java-11-openjdk-amd64/bin/java");
@ -275,11 +285,11 @@ public class SubserverSystem {
}
private static boolean steamwarStartAvailable(){
return LoadEvaluation.getCPULoad() < 0.8 && LoadEvaluation.getRamPercentage() < 0.8;
return LoadEvaluation.getCPULoad() < 0.7 && LoadEvaluation.getRamPercentage() < 0.8;
}
private static boolean lixfelStartAvailable(){
return LoadEvaluation.getRemoteCPULoad("lx") < 0.8 && LoadEvaluation.getRemoteRamPercentage("lx") < 0.8;
private static boolean remoteStartAvailable(String remote) {
return LoadEvaluation.getRemoteCPULoad(remote) < 0.7 && LoadEvaluation.getRemoteRamPercentage(remote) < 0.8;
}
private static boolean bauRunning(ProxiedPlayer p, UUID owner){

Datei anzeigen

@ -41,6 +41,7 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class TablistManager extends BasicListener {
@ -81,24 +82,19 @@ public class TablistManager extends BasicListener {
private synchronized void updateCustomTablist(){
//Calculate server-player-map
playerMap.clear();
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
Server pserver = player.getServer();
if(pserver == null) //Happens temporarily
if (pserver == null) //Happens temporarily
continue;
ServerInfo server = pserver.getInfo();
String serverName = server.getName();
Subserver subserver = Subserver.getSubserver(server);
List<ProxiedPlayer> players;
if(subserver != null && subserver.getType() == Servertype.BAUSERVER){
players = playerMap.getOrDefault("Bau", new ArrayList<>());
players.add(player);
playerMap.putIfAbsent("Bau", players);
}else{
players = playerMap.getOrDefault(serverName, new ArrayList<>());
players.add(player);
playerMap.putIfAbsent(serverName, players);
if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
playerMap.computeIfAbsent("Bau", s -> new ArrayList<>()).add(player);
} else {
playerMap.computeIfAbsent(serverName, s -> new ArrayList<>()).add(player);
}
}
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){
int phase = (seconds % 16) / 4;
int phase = (seconds % 16) / 3;
switch(phase){
case 0:
return Message.parse("TABLIST_PHASE_0", player, ProxyServer.getInstance().getPlayers().size());
case 1:
return Message.parse("TABLIST_PHASE_1", player);
case 2:
case 1:
return Message.parse("TABLIST_PHASE_2", player);
case 3:
case 2:
default:
return Message.parse("TABLIST_PHASE_DEFAULT", player);
}
@ -157,13 +151,18 @@ public class TablistManager extends BasicListener {
}
private void refresh(){
ServerInfo currentServer = player.getServer().getInfo();
setHeader(calcHeader(player));
// 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);
if (size >= 5) {
refreshSlim(currentServer);
return;
}
try {
ServerInfo currentServer = player.getServer().getInfo();
setHeader(calcHeader(player));
setFooter("§e" + currentServer.getName() + " " + getPing() + "§8ms");
setSize(size, 20);
int i = 0;
for (String server : playerMap.navigableKeySet()) {
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) {
Subserver server = Subserver.getSubserver(p);
if(server != null){