From 2303f9b709202003a51766b12ad049ba8210328e Mon Sep 17 00:00:00 2001 From: 4drian3d Date: Mon, 22 Nov 2021 13:00:45 -0500 Subject: [PATCH] Implement allowedCommands configuration - Forward more events to proxy - Now all commands that are executed if the player is not logged in and is not on a login server will be blocked. If the player is on a login server and executes a command that is not allowed, it will be blocked. - Removed server argument from events If a specific server is required, it can be obtained from the player. - Add isAuthServer and isInAuthServer methods to API --- .../proxy/AuthMeVelocityPlugin.java | 4 +- .../proxy/AuthmeVelocityAPI.java | 31 +++++ .../proxy/config/AuthMeConfig.java | 34 +++++- .../proxy/config/ConfigUtils.java | 17 +++ .../proxy/event/ProxyLoginEvent.java | 3 +- .../proxy/event/ProxyLogoutEvent.java | 7 ++ .../proxy/event/ProxyRegisterEvent.java | 7 ++ .../proxy/listener/FastLoginListener.java | 6 +- .../proxy/listener/PluginMessageListener.java | 92 +++++++++++++++ .../proxy/listener/ProxyListener.java | 110 ++++-------------- .../spigot/AuthMeVelocityPlugin.java | 9 +- .../authmevelocity/spigot/MessageType.java | 5 + .../spigot/listeners/AuthMeListener.java | 15 ++- 13 files changed, 237 insertions(+), 103 deletions(-) create mode 100644 proxy/src/main/java/com/glyart/authmevelocity/proxy/config/ConfigUtils.java create mode 100644 proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyLogoutEvent.java create mode 100644 proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyRegisterEvent.java create mode 100644 proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/PluginMessageListener.java create mode 100644 spigot/src/main/java/com/glyart/authmevelocity/spigot/MessageType.java 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 c4f886b..8c8b80b 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthMeVelocityPlugin.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthMeVelocityPlugin.java @@ -2,6 +2,7 @@ package com.glyart.authmevelocity.proxy; import com.glyart.authmevelocity.proxy.config.AuthMeConfig; import com.glyart.authmevelocity.proxy.listener.FastLoginListener; +import com.glyart.authmevelocity.proxy.listener.PluginMessageListener; import com.glyart.authmevelocity.proxy.listener.ProxyListener; import com.google.inject.Inject; import com.velocitypowered.api.event.Subscribe; @@ -42,7 +43,8 @@ public class AuthMeVelocityPlugin { proxy.getChannelRegistrar().register( MinecraftChannelIdentifier.create("authmevelocity", "main")); - proxy.getEventManager().register(this, new ProxyListener(proxy, logger, config)); + proxy.getEventManager().register(this, new ProxyListener(config)); + proxy.getEventManager().register(this, new PluginMessageListener(proxy, logger, config)); proxy.getPluginManager().getPlugin("fastlogin").ifPresent(fastlogin -> proxy.getEventManager().register(this, new FastLoginListener(proxy))); diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthmeVelocityAPI.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthmeVelocityAPI.java index 329d4ba..fd697e9 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthmeVelocityAPI.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthmeVelocityAPI.java @@ -3,7 +3,10 @@ package com.glyart.authmevelocity.proxy; import java.util.UUID; import java.util.function.Predicate; +import com.glyart.authmevelocity.proxy.config.AuthMeConfig; import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ServerConnection; +import com.velocitypowered.api.proxy.server.RegisteredServer; import org.jetbrains.annotations.NotNull; @@ -52,5 +55,33 @@ public class AuthmeVelocityAPI { .forEach(player -> AuthMeVelocityPlugin.loggedPlayers.remove(player.getUniqueId())); } + /** + * Check if the player is on a login server + * @param player the player + * @return if the player is on a login server + */ + public static boolean isInAuthServer(@NotNull Player player){ + var connection = player.getCurrentServer(); + return connection.isPresent() && isAuthServer(connection.get()); + } + + /** + * Check if a server is intended to be a logging server + * @param server the server + * @return if the server is a login server + */ + public static boolean isAuthServer(@NotNull RegisteredServer server){ + return AuthMeConfig.getConfig().getAuthServers().contains(server.getServerInfo().getName()); + } + + /** + * Checks if a connection is made from a login server + * @param connection the connection + * @return if the connection is made from a login server + */ + public static boolean isAuthServer(@NotNull ServerConnection connection){ + return AuthMeConfig.getConfig().getAuthServers().contains(connection.getServerInfo().getName()); + } + private AuthmeVelocityAPI(){} } diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/AuthMeConfig.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/AuthMeConfig.java index be1c8b0..2edabdf 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/AuthMeConfig.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/AuthMeConfig.java @@ -17,7 +17,7 @@ public class AuthMeConfig { AuthmeVelocity Proxy Original Developer: xQuickGlare - Actual Developer: 4drian3d + Current Developer: 4drian3d """; private static final HoconConfigurationLoader.Builder configBuilder = HoconConfigurationLoader.builder() .defaultOptions(opts -> opts @@ -49,12 +49,18 @@ public class AuthMeConfig { "auth2" ); + private Commands commands = new Commands(); + private ServerOnLogin send = new ServerOnLogin(); public Set getAuthServers(){ return this.authservers; } + public Commands getCommandsConfig(){ + return this.commands; + } + public ServerOnLogin getToServerOptions(){ return this.send; } @@ -81,6 +87,32 @@ public class AuthMeConfig { return this.teleportServers; } } + + @ConfigSerializable + public static class Commands{ + @Comment("Sets the commands that users who have not yet logged in can execute") + private Set allowedCommands = Set.of( + "login", + "register", + "l", + "reg", + "email", + "captcha" + ); + + @Comment(""" + Sets the message to send in case a non-logged-in player executes an unauthorized command + To deactivate the message, leave it empty""") + private String blockedCommandMessage = "&4You cannot execute commands if you are not logged in yet."; + + public Set getAllowedCommands(){ + return this.allowedCommands; + } + + public String getBlockedMessage() { + return this.blockedCommandMessage; + } + } private static Config config; public static Config getConfig(){ return config; diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/ConfigUtils.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/ConfigUtils.java new file mode 100644 index 0000000..a27e993 --- /dev/null +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/ConfigUtils.java @@ -0,0 +1,17 @@ +package com.glyart.authmevelocity.proxy.config; + +import com.velocitypowered.api.proxy.Player; + +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public class ConfigUtils { + public static void sendBlockedMessage(Player player){ + var config = AuthMeConfig.getConfig(); + String blockedMessage = config.getCommandsConfig().getBlockedMessage(); + if(!blockedMessage.isBlank()){ + player.sendMessage( + LegacyComponentSerializer.legacyAmpersand().deserialize( + blockedMessage)); + } + } +} diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyLoginEvent.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyLoginEvent.java index 7af8556..8533a39 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyLoginEvent.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyLoginEvent.java @@ -1,11 +1,10 @@ package com.glyart.authmevelocity.proxy.event; import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.proxy.server.RegisteredServer; import org.jetbrains.annotations.NotNull; /** * Event executed in case the player is successfully logged in */ -public record ProxyLoginEvent(@NotNull Player player, @NotNull RegisteredServer server) {} +public record ProxyLoginEvent(@NotNull Player player) {} diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyLogoutEvent.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyLogoutEvent.java new file mode 100644 index 0000000..416671b --- /dev/null +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyLogoutEvent.java @@ -0,0 +1,7 @@ +package com.glyart.authmevelocity.proxy.event; + +import com.velocitypowered.api.proxy.Player; + +import org.jetbrains.annotations.NotNull; + +public record ProxyLogoutEvent(@NotNull Player player) {} diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyRegisterEvent.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyRegisterEvent.java new file mode 100644 index 0000000..20c2e43 --- /dev/null +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/event/ProxyRegisterEvent.java @@ -0,0 +1,7 @@ +package com.glyart.authmevelocity.proxy.event; + +import com.velocitypowered.api.proxy.Player; + +import org.jetbrains.annotations.NotNull; + +public record ProxyRegisterEvent(@NotNull Player player){} diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/FastLoginListener.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/FastLoginListener.java index ef03a1a..4360252 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/FastLoginListener.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/FastLoginListener.java @@ -1,11 +1,8 @@ package com.glyart.authmevelocity.proxy.listener; -import java.util.Optional; - import com.github.games647.fastlogin.velocity.event.VelocityFastLoginAutoLoginEvent; import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI; import com.velocitypowered.api.event.Subscribe; -import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; public class FastLoginListener { @@ -15,7 +12,6 @@ public class FastLoginListener { } @Subscribe public void onAutoLogin(VelocityFastLoginAutoLoginEvent event){ - Optional autoLoginPlayer = server.getPlayer(event.getProfile().getName()); - autoLoginPlayer.ifPresent(AuthmeVelocityAPI::addPlayer); + server.getPlayer(event.getProfile().getName()).ifPresent(AuthmeVelocityAPI::addPlayer); } } 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 new file mode 100644 index 0000000..0695e01 --- /dev/null +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/PluginMessageListener.java @@ -0,0 +1,92 @@ +package com.glyart.authmevelocity.proxy.listener; + +import java.util.List; +import java.util.Random; + +import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI; +import com.glyart.authmevelocity.proxy.config.AuthMeConfig; +import com.glyart.authmevelocity.proxy.event.PreSendOnLoginEvent; +import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent; +import com.glyart.authmevelocity.proxy.event.ProxyLogoutEvent; +import com.glyart.authmevelocity.proxy.event.ProxyRegisterEvent; +import com.google.common.io.ByteArrayDataInput; +import com.velocitypowered.api.event.Continuation; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.ServerConnection; +import com.velocitypowered.api.proxy.server.RegisteredServer; + +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; + +public class PluginMessageListener { + private final ProxyServer proxy; + private final Logger logger; + private final Random rm; + private AuthMeConfig.Config config; + + public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig.Config config) { + this.proxy = proxy; + this.logger = logger; + this.rm = new Random(); + this.config = config; + } + + @Subscribe + public void onPluginMessage(final PluginMessageEvent event, Continuation continuation) { + if (!(event.getSource() instanceof ServerConnection connection) || !event.getIdentifier().getId().equals("authmevelocity:main")){ + continuation.resume(); + return; + } + + event.setResult(PluginMessageEvent.ForwardResult.handled()); + + ByteArrayDataInput input = event.dataAsDataStream(); + final String sChannel = input.readUTF(); + final Player loggedPlayer = connection.getPlayer(); + switch(sChannel){ + case "LOGIN" -> { + if (AuthmeVelocityAPI.addPlayer(loggedPlayer)){ + createServerConnectionRequest(loggedPlayer, config, proxy, logger, connection); + } + continuation.resume(); + } + case "LOGOUT" -> { + if(AuthmeVelocityAPI.removePlayer(loggedPlayer)){ + proxy.getEventManager().fireAndForget(new ProxyLogoutEvent(loggedPlayer)); + } + continuation.resume(); + } + case "REGISTER" -> { + proxy.getEventManager().fireAndForget(new ProxyRegisterEvent(loggedPlayer)); + continuation.resume(); + } + + default -> continuation.resume(); + } + } + + private void createServerConnectionRequest(Player loggedPlayer, AuthMeConfig.Config config, ProxyServer proxy, Logger logger, ServerConnection connection){ + final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElse(connection).getServer(); + proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer)); + if(config.getToServerOptions().sendToServer()){ + final List serverList = config.getToServerOptions().getTeleportServers(); + final String randomServer = serverList.get(rm.nextInt(serverList.size())); + proxy.getServer(randomServer).ifPresentOrElse(serverToSend -> + proxy.getEventManager().fire(new PreSendOnLoginEvent(loggedPlayer, loginServer, serverToSend)).thenAcceptAsync(preSendEvent -> { + if(preSendEvent.getResult().isAllowed()){ + loggedPlayer.createConnectionRequest(serverToSend).connect().thenAcceptAsync(result -> { + if(!result.isSuccessful()) { + logger.info("Unable to connect the player {} to the server {}", + loggedPlayer.getUsername(), + serverToSend.getServerInfo().getName()); + } + }); + } + }) + , () -> logger.info("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 735e42d..8694eaf 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 @@ -2,89 +2,25 @@ package com.glyart.authmevelocity.proxy.listener; import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI; import com.glyart.authmevelocity.proxy.config.AuthMeConfig; -import com.glyart.authmevelocity.proxy.event.PreSendOnLoginEvent; -import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent; -import com.google.common.io.ByteArrayDataInput; -import com.velocitypowered.api.event.Continuation; +import com.glyart.authmevelocity.proxy.config.ConfigUtils; import com.velocitypowered.api.event.EventTask; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.connection.DisconnectEvent; -import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.ServerPreConnectEvent; import com.velocitypowered.api.event.player.TabCompleteEvent; import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.proxy.ProxyServer; -import com.velocitypowered.api.proxy.ServerConnection; -import com.velocitypowered.api.proxy.server.RegisteredServer; import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; - -import java.util.List; -import java.util.Optional; -import java.util.Random; public class ProxyListener { - private final ProxyServer proxy; - private final Logger logger; - private final Random rm; private AuthMeConfig.Config config; - public ProxyListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig.Config config) { - this.proxy = proxy; - this.logger = logger; - this.rm = new Random(); + public ProxyListener(@NotNull AuthMeConfig.Config config) { this.config = config; } - @Subscribe - public void onPluginMessage(final PluginMessageEvent event, Continuation continuation) { - if (!(event.getSource() instanceof ServerConnection connection) || !event.getIdentifier().getId().equals("authmevelocity:main")){ - continuation.resume(); - return; - } - - ByteArrayDataInput input = event.dataAsDataStream(); - final String sChannel = input.readUTF(); - if (!sChannel.equals("LOGIN")) { - continuation.resume(); - return; - } - - event.setResult(PluginMessageEvent.ForwardResult.handled()); - //TODO: Test this - final Player loggedPlayer = connection.getPlayer(); - if (AuthmeVelocityAPI.addPlayer(loggedPlayer)){ - createServerConnectionRequest(loggedPlayer, config, proxy, logger, connection); - continuation.resume(); - } - } - - private void createServerConnectionRequest(Player loggedPlayer, AuthMeConfig.Config config, ProxyServer proxy, Logger logger, ServerConnection connection){ - final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElse(connection).getServer(); - proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer, loginServer)); - if(config.getToServerOptions().sendToServer()){ - final List serverList = config.getToServerOptions().getTeleportServers(); - final String randomServer = serverList.get(rm.nextInt(serverList.size())); - Optional optionalServer = proxy.getServer(randomServer); - optionalServer.ifPresentOrElse(serverToSend -> - proxy.getEventManager().fire(new PreSendOnLoginEvent(loggedPlayer, loginServer, serverToSend)).thenAcceptAsync(preSendEvent -> { - if(preSendEvent.getResult().isAllowed()){ - loggedPlayer.createConnectionRequest(serverToSend).connect().thenAcceptAsync(result -> { - if(!result.isSuccessful()) { - logger.info("Unable to connect the player {} to the server {}", - loggedPlayer.getUsername(), - serverToSend.getServerInfo().getName()); - } - }); - } - }) - , () -> logger.info("The server {} does not exist", randomServer)); - } - } - @Subscribe public void onDisconnect(final DisconnectEvent event) { AuthmeVelocityAPI.removePlayer(event.getPlayer()); @@ -95,42 +31,38 @@ public class ProxyListener { if (!(event.getCommandSource() instanceof Player player) || AuthmeVelocityAPI.isLogged(player)) return; - Optional server = player.getCurrentServer(); - - if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName())) { - event.setResult(CommandExecuteEvent.CommandResult.forwardToServer()); + if(AuthmeVelocityAPI.isInAuthServer(player)){ + var commandconfig = config.getCommandsConfig(); + String command = event.getCommand(); + if(command.contains(" ")){ + command = command.split(" ")[0]; + } + if(!commandconfig.getAllowedCommands().contains(command)){ + ConfigUtils.sendBlockedMessage(player); + event.setResult(CommandExecuteEvent.CommandResult.denied()); + } } else { + ConfigUtils.sendBlockedMessage(player); event.setResult(CommandExecuteEvent.CommandResult.denied()); } } @Subscribe - public void onPlayerChat(final PlayerChatEvent event, Continuation continuation) { - final Player player = event.getPlayer(); - if (AuthmeVelocityAPI.isLogged(player)) { - continuation.resume(); - return; + public void onPlayerChat(final PlayerChatEvent event) { + if (!AuthmeVelocityAPI.isLogged(event.getPlayer())) { + event.setResult(PlayerChatEvent.ChatResult.denied()); } - - Optional server = player.getCurrentServer(); - if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName())) { - continuation.resume(); - return; - } - - event.setResult(PlayerChatEvent.ChatResult.denied()); } @Subscribe public void onServerPreConnect(ServerPreConnectEvent event) { if (AuthmeVelocityAPI.isLogged(event.getPlayer())) return; - Optional server = event.getResult().getServer(); - if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName())) { - return; - } - - event.setResult(ServerPreConnectEvent.ServerResult.denied()); + event.getResult().getServer().ifPresent(server -> { + if(!AuthmeVelocityAPI.isAuthServer(server)){ + event.setResult(ServerPreConnectEvent.ServerResult.denied()); + } + }); } @Subscribe diff --git a/spigot/src/main/java/com/glyart/authmevelocity/spigot/AuthMeVelocityPlugin.java b/spigot/src/main/java/com/glyart/authmevelocity/spigot/AuthMeVelocityPlugin.java index 965028c..325413a 100644 --- a/spigot/src/main/java/com/glyart/authmevelocity/spigot/AuthMeVelocityPlugin.java +++ b/spigot/src/main/java/com/glyart/authmevelocity/spigot/AuthMeVelocityPlugin.java @@ -8,18 +8,19 @@ import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; public class AuthMeVelocityPlugin extends JavaPlugin { + private static final String CHANNEL = "authmevelocity:main"; @Override public void onEnable() { - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "authmevelocity:main"); + this.getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL); this.getServer().getPluginManager().registerEvents(new AuthMeListener(this), this); this.getLogger().info("AuthMeVelocity enabled."); } - public void sendLoginToProxy(@NotNull final Player player) { + public void sendMessageToProxy(@NotNull final Player player, MessageType type) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("LOGIN"); + out.writeUTF(type.toString()); - player.sendPluginMessage(this, "authmevelocity:main", out.toByteArray()); + player.sendPluginMessage(this, CHANNEL, out.toByteArray()); } } diff --git a/spigot/src/main/java/com/glyart/authmevelocity/spigot/MessageType.java b/spigot/src/main/java/com/glyart/authmevelocity/spigot/MessageType.java new file mode 100644 index 0000000..46455ee --- /dev/null +++ b/spigot/src/main/java/com/glyart/authmevelocity/spigot/MessageType.java @@ -0,0 +1,5 @@ +package com.glyart.authmevelocity.spigot; + +public enum MessageType { + LOGIN, REGISTER, LOGOUT +} diff --git a/spigot/src/main/java/com/glyart/authmevelocity/spigot/listeners/AuthMeListener.java b/spigot/src/main/java/com/glyart/authmevelocity/spigot/listeners/AuthMeListener.java index 170b209..afe54f3 100644 --- a/spigot/src/main/java/com/glyart/authmevelocity/spigot/listeners/AuthMeListener.java +++ b/spigot/src/main/java/com/glyart/authmevelocity/spigot/listeners/AuthMeListener.java @@ -1,9 +1,12 @@ package com.glyart.authmevelocity.spigot.listeners; import com.glyart.authmevelocity.spigot.AuthMeVelocityPlugin; +import com.glyart.authmevelocity.spigot.MessageType; import com.glyart.authmevelocity.spigot.events.PreSendLoginEvent; import fr.xephi.authme.events.LoginEvent; +import fr.xephi.authme.events.LogoutEvent; +import fr.xephi.authme.events.RegisterEvent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -23,7 +26,17 @@ public class AuthMeListener implements Listener { PreSendLoginEvent preSendLoginEvent = new PreSendLoginEvent(player); Bukkit.getPluginManager().callEvent(preSendLoginEvent); if(!preSendLoginEvent.isCancelled()){ - plugin.sendLoginToProxy(player); + plugin.sendMessageToProxy(player, MessageType.LOGIN); } } + + @EventHandler + public void onRegister(RegisterEvent event){ + plugin.sendMessageToProxy(event.getPlayer(), MessageType.REGISTER); + } + + @EventHandler + public void onLogout(LogoutEvent event){ + plugin.sendMessageToProxy(event.getPlayer(), MessageType.LOGOUT); + } }