misc(velocity): Implement Advanced config section

This commit is contained in:
Adrian3d04 2022-08-13 21:12:23 +00:00
parent 6775b8080e
commit 97b9bcd87a
4 changed files with 32 additions and 25 deletions

View File

@ -9,18 +9,6 @@ import java.util.List;
@ConfigSerializable
public class ProxyConfiguration {
@Comment("Enable debug mode")
private boolean debug = false;
public boolean debug() {
return this.debug;
}
@Comment("")
private int randomAttempts = 5;
public int randomAttempts() {
return this.randomAttempts;
}
@Comment("List of login/registration servers")
private List<String> authServers = List.of("auth1", "auth2");
public List<String> authServers() {
@ -42,6 +30,11 @@ public class ProxyConfiguration {
return this.ensureAuthServer;
}
private Advanced advanced = new Advanced();
public Advanced advanced() {
return this.advanced;
}
@ConfigSerializable
public static class EnsureAuthServer {
@Comment("Ensure that the first server to which players connect is an auth server")
@ -51,10 +44,10 @@ public class ProxyConfiguration {
}
@Comment("""
SendMode
TO_FIRST |
TO_EMPTIEST_SERVE |
RANDOM |
Selection Mode of the player's initial server
TO_FIRST | Send to the first valid server configured
TO_EMPTIEST_SERVER | Send to the server with the lowest number of players
RANDOM | Send to a random server
""")
private SendMode sendMode = SendMode.RANDOM;
public SendMode sendMode() {
@ -79,12 +72,11 @@ public class ProxyConfiguration {
return this.teleportServers;
}
// TODO: Improve comments
@Comment("""
SendMode
TO_FIRST |
TO_EMPTIEST_SERVE |
RANDOM |
Selection Mode of the server to which the player will be sent
TO_FIRST | Send to the first valid server configured
TO_EMPTIEST_SERVER | Send to the server with the lowest number of players
RANDOM | Send to a random server
""")
private SendMode sendMode = SendMode.RANDOM;
public SendMode sendMode() {
@ -110,6 +102,21 @@ public class ProxyConfiguration {
}
}
@ConfigSerializable
public static class Advanced {
@Comment("Enable debug mode")
private boolean debug = false;
public boolean debug() {
return this.debug;
}
@Comment("Attempts to get a valid server in SendMode Random")
private int randomAttempts = 5;
public int randomAttempts() {
return this.randomAttempts;
}
}
}

View File

@ -171,7 +171,7 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
}
public void logDebug(String msg) {
if (config.get().debug()) {
if (config.get().advanced().debug()) {
logger.info("[DEBUG] {}", msg);
}
}

View File

@ -46,7 +46,7 @@ public class ConnectListener {
}
var config = plugin.config().get();
var server = AuthmeUtils.serverToSend(
config.ensureAuthServer().sendMode(), proxy, config.authServers(), config.randomAttempts());
config.ensureAuthServer().sendMode(), proxy, config.authServers(), config.advanced().randomAttempts());
// Velocity takes over in case the initial server is not present
event.setInitialServer(server.object());

View File

@ -107,7 +107,7 @@ public class PluginMessageListener {
var config = plugin.config().get();
var toSend = AuthmeUtils.serverToSend(
config.sendOnLogin().sendMode(), proxy, config.authServers(), config.randomAttempts());
config.sendOnLogin().sendMode(), proxy, config.authServers(), config.advanced().randomAttempts());
if (toSend.isEmpty()) {
if (toSend.string() != null) {