Add ability to control online players along with max players
This commit is contained in:
parent
32ae495c1f
commit
69a40e58e7
@ -48,6 +48,10 @@ public class ServerListConfig {
|
||||
@Setting("server-preview")
|
||||
private ServerPreview serverPreview = new ServerPreview();
|
||||
|
||||
@Getter
|
||||
@Setting("online-player-count")
|
||||
private OnlinePlayerCount onlinePlayerCount = new OnlinePlayerCount();
|
||||
|
||||
@ConfigSerializable
|
||||
public static class PlayerCount {
|
||||
|
||||
@ -92,4 +96,27 @@ public class ServerListConfig {
|
||||
PLAYERS;
|
||||
}
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public static class OnlinePlayerCount {
|
||||
|
||||
@Getter
|
||||
@Setting(value = "action", comment = " # The online player count has three different actions:\r\n" + " # \r\n"
|
||||
+ " # STATIC - online players will always be the value of `online-player-count`\r\n"
|
||||
+ " # PING - online player count shows the sum of all backend servers' online player counts. Cached every 5 minutes\r\n"
|
||||
+ " # CURRENT - online players matches number of players connected to the proxy\r\n" + " #\r\n"
|
||||
+ " # `online-player-count` is only used with the STATIC action")
|
||||
|
||||
private OnlinePlayerCountAction action = OnlinePlayerCountAction.CURRENT;
|
||||
|
||||
@Getter
|
||||
@Setting("online-player-count")
|
||||
private int onlinePlayerCount = 32;
|
||||
|
||||
public static enum OnlinePlayerCountAction {
|
||||
STATIC,
|
||||
PING,
|
||||
CURRENT;
|
||||
}
|
||||
}
|
||||
}
|
@ -50,12 +50,23 @@ public class ServerListHandler {
|
||||
Builder builder = ServerPing.builder();
|
||||
|
||||
builder.version(original.getVersion());
|
||||
builder.onlinePlayers(playerCount);
|
||||
|
||||
original.getFavicon().ifPresent(builder::favicon);
|
||||
|
||||
builder.description(config.getMotd());
|
||||
|
||||
switch (config.getOnlinePlayerCount().getAction()) {
|
||||
case STATIC:
|
||||
builder.onlinePlayers(playerCount);
|
||||
break;
|
||||
case PING:
|
||||
builder.onlinePlayers(module.getOnlinePlayerPing());
|
||||
break;
|
||||
case CURRENT:
|
||||
builder.onlinePlayers(module.getNeutron().getProxy().getPlayerCount());
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.getPlayerCount().getAction()) {
|
||||
case CURRENT:
|
||||
builder.maximumPlayers(playerCount);
|
||||
|
@ -47,6 +47,8 @@ public class ServerListModule extends Module {
|
||||
private ServerListHandler handler;
|
||||
@Getter
|
||||
private int maxPlayerPing;
|
||||
@Getter
|
||||
private int onlinePlayerPing;
|
||||
|
||||
@Override
|
||||
public StateResult init() {
|
||||
@ -90,6 +92,7 @@ public class ServerListModule extends Module {
|
||||
public class PingTask implements Runnable {
|
||||
|
||||
int buffer = 0;
|
||||
int onlineBuffer = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -100,6 +103,7 @@ public class ServerListModule extends Module {
|
||||
|
||||
if (players.isPresent()) {
|
||||
buffer += players.get().getMax();
|
||||
onlineBuffer += players.get().getOnline();
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException exception) {
|
||||
/* Catch silently */
|
||||
@ -108,7 +112,9 @@ public class ServerListModule extends Module {
|
||||
}
|
||||
|
||||
maxPlayerPing = buffer;
|
||||
onlinePlayerPing = onlineBuffer;
|
||||
buffer = 0;
|
||||
onlineBuffer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user