forked from Swofty-Developments/HypixelSkyBlock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalanceConfigurations.java
More file actions
88 lines (75 loc) · 3.68 KB
/
BalanceConfigurations.java
File metadata and controls
88 lines (75 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package net.swofty.velocity.gamemanager;
import com.velocitypowered.api.proxy.Player;
import net.swofty.commons.ServerType;
import net.swofty.velocity.gamemanager.balanceconfigurations.IslandCheck;
import net.swofty.velocity.gamemanager.balanceconfigurations.LowestPlayerCount;
import net.swofty.velocity.testflow.TestFlowManager;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BalanceConfigurations {
public static HashMap<ServerType, List<BalanceConfiguration>> configurations = new HashMap<>(Map.of(
ServerType.SKYBLOCK_HUB, List.of(
new LowestPlayerCount()
),
ServerType.PROTOTYPE_LOBBY, List.of(
new LowestPlayerCount()
),
ServerType.SKYBLOCK_DUNGEON_HUB, List.of(
new LowestPlayerCount()
),
ServerType.SKYBLOCK_THE_FARMING_ISLANDS, List.of(
new LowestPlayerCount()
),
ServerType.SKYBLOCK_ISLAND, List.of(
new IslandCheck(),
new LowestPlayerCount()
))
);
public static @Nullable GameManager.GameServer getServerFor(Player player, ServerType type) {
if (TestFlowManager.isPlayerInTestFlow(player.getUsername())) {
player.sendPlainMessage("§eYou are currently in a network-isolated test flow, load balancing will be restricted to test flow servers!");
player.sendPlainMessage("§8Executing test flow " + TestFlowManager.getTestFlowForPlayer(player.getUsername()).getName() + "...");
}
try {
for (BalanceConfiguration configuration : configurations.get(type)) {
List<GameManager.GameServer> serversToConsider = GameManager.getFromType(type);
if (TestFlowManager.isPlayerInTestFlow(player.getUsername())) {
serversToConsider.removeIf(server -> {
boolean remove = server.maxPlayers() <= server.registeredServer().getPlayersConnected().size();
if (!TestFlowManager.isServerInTestFlow(server.internalID())) {
remove = true;
}
TestFlowManager.ProxyTestFlowInstance testFlowInstance = TestFlowManager.getFromServerUUID(
server.internalID()
);
if (!testFlowInstance.hasPlayer(player.getUsername())) {
remove = true;
}
return remove;
});
} else {
serversToConsider.removeIf(server -> {
boolean remove = server.maxPlayers() <= server.registeredServer().getPlayersConnected().size();
if (TestFlowManager.isServerInTestFlow(server.internalID())) {
remove = true;
}
return remove;
});
}
GameManager.GameServer server = configuration.getServer(player, serversToConsider);
if (server != null) {
if (TestFlowManager.isPlayerInTestFlow(player.getUsername())) {
player.sendPlainMessage("§8Done overriding the server manager for your test flow.");
}
return server;
}
}
return null;
} catch (Exception e) {
System.out.println("Error in trying to balance type " + type.name() + " for player " + player.getUsername());
throw e;
}
}
}