Made a method HubBalancer#removeServer since the code was duplicated.
This commit is contained in:
parent
d66416cec7
commit
b50aa92f76
@ -49,17 +49,24 @@ public class HubBalancer implements Runnable, Listener {
|
|||||||
JedisCommandHandler.getInstance().addListener(jedisCommand -> {
|
JedisCommandHandler.getInstance().addListener(jedisCommand -> {
|
||||||
if (jedisCommand instanceof ServerRestartCommand) {
|
if (jedisCommand instanceof ServerRestartCommand) {
|
||||||
ServerRestartCommand serverRestartCommand = (ServerRestartCommand) jedisCommand;
|
ServerRestartCommand serverRestartCommand = (ServerRestartCommand) jedisCommand;
|
||||||
|
removeServer(serverRestartCommand.getServerId());
|
||||||
ServerInfo serverInfo = proxy.getProxy().getServerInfo(serverRestartCommand.getServerId());
|
ServerInfo serverInfo = proxy.getProxy().getServerInfo(serverRestartCommand.getServerId());
|
||||||
if (serverInfo == null)
|
if (serverInfo == null) {
|
||||||
return;
|
System.out.println("ServerInfo is null");
|
||||||
for (ProxiedPlayer player : proxy.getProxy().getPlayers()) {
|
//We do this check due sometimes players stay in a server which is deleted. But were send to it before it was deleted.
|
||||||
if (player.getServer().getInfo().equals(serverInfo)) {
|
for (ProxiedPlayer player : proxy.getProxy().getPlayers()) {
|
||||||
if (hubs.isEmpty() || hubs.size() == 1)
|
if (player.getServer() == null || player.getServer().getInfo().getName().equals(serverRestartCommand.getServerId()))
|
||||||
kickPlayer(player, NO_AVAILABLE_HUB);
|
kickPlayer(player, NO_AVAILABLE_HUB);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
for (ProxiedPlayer player : proxy.getProxy().getPlayers()) {
|
||||||
|
if (player.getServer().getInfo().equals(serverInfo)) {
|
||||||
|
if (hubs.isEmpty() || hubs.size() <= 1)
|
||||||
|
kickPlayer(player, NO_AVAILABLE_HUB);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (hubs.containsValue(serverInfo))
|
|
||||||
hubs.remove(serverRestartCommand.getServerId());
|
|
||||||
}
|
}
|
||||||
if (jedisCommand instanceof ServerStateChangeCommand) {
|
if (jedisCommand instanceof ServerStateChangeCommand) {
|
||||||
ServerStateChangeCommand serverStateChangeCommand = (ServerStateChangeCommand) jedisCommand;
|
ServerStateChangeCommand serverStateChangeCommand = (ServerStateChangeCommand) jedisCommand;
|
||||||
@ -69,17 +76,7 @@ public class HubBalancer implements Runnable, Listener {
|
|||||||
if (!serverStateChangeCommand.getNewState().isShuttingDownState())
|
if (!serverStateChangeCommand.getNewState().isShuttingDownState())
|
||||||
return;
|
return;
|
||||||
MinecraftServer server = serverStateChangeCommand.getServer();
|
MinecraftServer server = serverStateChangeCommand.getServer();
|
||||||
proxy.getProxy().getServers().entrySet().removeIf(entry -> {
|
removeServer(server.getId());
|
||||||
String key = entry.getKey();
|
|
||||||
if (!key.equals(server.getId()))
|
|
||||||
return false;
|
|
||||||
if (key.equals(group.getName()))
|
|
||||||
return false;
|
|
||||||
if (entry.getValue().getMotd().equals("STATIC"))
|
|
||||||
return false;
|
|
||||||
hubs.remove(server.getId());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -225,4 +222,18 @@ public class HubBalancer implements Runnable, Listener {
|
|||||||
"&b" + reason + "\n" +
|
"&b" + reason + "\n" +
|
||||||
"&7")));
|
"&7")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeServer(String serverId) {
|
||||||
|
proxy.getProxy().getServers().entrySet().removeIf(entry -> {
|
||||||
|
String key = entry.getKey();
|
||||||
|
if (!key.equals(serverId))
|
||||||
|
return false;
|
||||||
|
if (key.equals(group.getName()))
|
||||||
|
return false;
|
||||||
|
if (entry.getValue().getMotd().equals("STATIC"))
|
||||||
|
return false;
|
||||||
|
hubs.remove(serverId);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user