From 97b9bcd87ac9f43f411ad9311ec1a60c45ae6079 Mon Sep 17 00:00:00 2001 From: Adrian3d04 Date: Sat, 13 Aug 2022 21:12:23 +0000 Subject: [PATCH] misc(velocity): Implement Advanced config section --- .../configuration/ProxyConfiguration.java | 51 +++++++++++-------- .../velocity/AuthMeVelocityPlugin.java | 2 +- .../velocity/listener/ConnectListener.java | 2 +- .../listener/PluginMessageListener.java | 2 +- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ProxyConfiguration.java b/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ProxyConfiguration.java index ce50144..6220e08 100644 --- a/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ProxyConfiguration.java +++ b/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ProxyConfiguration.java @@ -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 authServers = List.of("auth1", "auth2"); public List 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,11 +44,11 @@ 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() { return this.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; + } + } + } diff --git a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/AuthMeVelocityPlugin.java b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/AuthMeVelocityPlugin.java index 73455d6..fc0de1c 100644 --- a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/AuthMeVelocityPlugin.java +++ b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/AuthMeVelocityPlugin.java @@ -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); } } diff --git a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ConnectListener.java b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ConnectListener.java index 861b4ea..6eef772 100644 --- a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ConnectListener.java +++ b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ConnectListener.java @@ -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()); diff --git a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/PluginMessageListener.java index aa0f5d0..6c031e7 100644 --- a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/PluginMessageListener.java +++ b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/PluginMessageListener.java @@ -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) {