misc: Improved code
This commit is contained in:
parent
2c2e6f1bad
commit
29049019f5
@ -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));
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user