From 29049019f55282c74cfe5e32facfc64c3c40cba6 Mon Sep 17 00:00:00 2001 From: 4drian3d Date: Thu, 2 Jun 2022 00:46:49 +0000 Subject: [PATCH] misc: Improved code --- .../proxy/AuthMeVelocityPlugin.java | 6 +++--- .../proxy/listener/PluginMessageListener.java | 11 +++++++---- .../proxy/listener/ProxyListener.java | 18 ++++++++---------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthMeVelocityPlugin.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthMeVelocityPlugin.java index d62bd40..2f2c9fe 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthMeVelocityPlugin.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthMeVelocityPlugin.java @@ -21,12 +21,12 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; import java.util.HashSet; -import java.util.Objects; import java.util.Set; import java.util.UUID; public class AuthMeVelocityPlugin { - public static final ChannelIdentifier AUTHMEVELOCITY_CHANNEL = MinecraftChannelIdentifier.create("authmevelocity", "main"); + public static final ChannelIdentifier AUTHMEVELOCITY_CHANNEL + = MinecraftChannelIdentifier.create("authmevelocity", "main"); private final ProxyServer proxy; private final Logger logger; private final Path pluginDirectory; @@ -48,7 +48,7 @@ public class AuthMeVelocityPlugin { logger.warn("Failed to load config.toml. Shutting down."); return; } - AuthMeConfig config = Objects.requireNonNull(new AuthMeConfig(toml), "configuration cannot be null"); + AuthMeConfig config = new AuthMeConfig(toml); this.api = new AuthmeVelocityAPI(this, config); proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL); proxy.getEventManager().register(this, new ProxyListener(config, api, logger, proxy)); diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/PluginMessageListener.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/PluginMessageListener.java index c301661..fd4662b 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/PluginMessageListener.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/PluginMessageListener.java @@ -42,7 +42,10 @@ public class PluginMessageListener { @Subscribe public void onPluginMessage(final PluginMessageEvent event, Continuation continuation) { - if (!(event.getSource() instanceof ServerConnection) || !event.getIdentifier().equals(AuthMeVelocityPlugin.AUTHMEVELOCITY_CHANNEL)){ + if ( + !(event.getSource() instanceof ServerConnection) + || !event.getIdentifier().equals(AuthMeVelocityPlugin.AUTHMEVELOCITY_CHANNEL) + ) { continuation.resume(); return; } @@ -90,8 +93,8 @@ public class PluginMessageListener { proxy.getServer(randomServer).ifPresentOrElse(serverToSend -> proxy.getEventManager().fire(new PreSendOnLoginEvent(loggedPlayer, loginServer, serverToSend)).thenAcceptAsync(preSendEvent -> { if(preSendEvent.getResult().isAllowed()){ - loggedPlayer.createConnectionRequest(serverToSend).connectWithIndication().thenAcceptAsync(result -> { - if(!result.booleanValue()) { + loggedPlayer.createConnectionRequest(serverToSend).connect().thenAcceptAsync(result -> { + if(!result.isSuccessful()) { logger.info("Unable to connect the player {} to the server {}", loggedPlayer.getUsername(), serverToSend.getServerInfo().getName()); @@ -99,7 +102,7 @@ public class PluginMessageListener { }); } }) - , () -> logger.info("The server {} does not exist", randomServer)); + , () -> logger.warn("The server {} does not exist", randomServer)); } } } diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/ProxyListener.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/ProxyListener.java index 5e45988..f15b2aa 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/ProxyListener.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/ProxyListener.java @@ -82,11 +82,10 @@ public final class ProxyListener { @Subscribe public void onServerPreConnect(ServerPreConnectEvent event, Continuation continuation) { - if (!event.getResult().isAllowed() && api.isLogged(event.getPlayer())){ - continuation.resume(); - return; - } - if(!event.getResult().getServer().map(api::isAuthServer).orElse(false)){ + if ( + !event.getResult().isAllowed() && api.isLogged(event.getPlayer()) + || !event.getResult().getServer().map(api::isAuthServer).orElse(false) + ) { continuation.resume(); return; } @@ -116,11 +115,10 @@ public final class ProxyListener { @Subscribe(order = PostOrder.LATE) public void onInitialServer(PlayerChooseInitialServerEvent event, Continuation continuation){ - if(!config.getEnsureOptions().ensureAuthServer()){ - continuation.resume(); - return; - } - if(event.getInitialServer().map(api::isAuthServer).orElse(false)){ + if( + !config.getEnsureOptions().ensureAuthServer() + || event.getInitialServer().map(api::isAuthServer).orElse(false) + ) { continuation.resume(); return; }