diff --git a/pom.xml b/pom.xml index 29ecfe5..f128018 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.glyart.authmevelocity parent pom - 2.1.1 + 2.2.0 11 diff --git a/proxy/pom.xml b/proxy/pom.xml index 5a121f4..d0e5674 100644 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@ -5,7 +5,7 @@ parent com.glyart.authmevelocity - 2.1.1 + 2.2.0 4.0.0 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 4473912..a4ddc1e 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthMeVelocityPlugin.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthMeVelocityPlugin.java @@ -1,11 +1,13 @@ package com.glyart.authmevelocity.proxy; +import com.glyart.authmevelocity.proxy.commands.AuthmeCommand; 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.moandjiezana.toml.Toml; +import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.plugin.annotation.DataDirectory; @@ -13,14 +15,18 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import net.kyori.adventure.text.minimessage.MiniMessage; + import org.slf4j.Logger; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.UUID; @@ -32,7 +38,9 @@ public class AuthMeVelocityPlugin { private final Logger logger; private final Path pluginDirectory; private AuthmeVelocityAPI api; + private AuthMeConfig config; + private final List listeners = new ArrayList<>(3); protected final Set loggedPlayers = Collections.synchronizedSet(new HashSet<>()); @Inject @@ -44,30 +52,20 @@ public AuthMeVelocityPlugin(ProxyServer proxy, Logger logger, @DataDirectory Pat @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { - Toml toml = this.loadConfig(pluginDirectory); - if (toml == null) { + if (!this.reload()) { logger.warn("Failed to load config.toml. Shutting down."); return; } - 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)); - proxy.getEventManager().register(this, new PluginMessageListener(proxy, logger, config, api)); - if (proxy.getPluginManager().isLoaded("fastlogin")) { - proxy.getEventManager().register(this, new FastLoginListener(proxy, api)); - } + proxy.getChannelRegistrar().register(AUTHMEVELOCITY_CHANNEL); if (proxy.getPluginManager().isLoaded("miniplaceholders")) { AuthmePlaceholders.getExpansion(this).register(); } - logger.info("-- AuthMeVelocity enabled --"); - logger.info("AuthServers: {}", config.getAuthServers()); - if (config.getToServerOptions().sendToServer()) { - logger.info("LobbyServers: {}", config.getToServerOptions().getTeleportServers()); - } + AuthmeCommand.register(this, proxy.getCommandManager()); + + this.sendInfoMessage(); } protected ProxyServer getProxy(){ @@ -93,9 +91,46 @@ private Toml loadConfig(Path path){ return new Toml().read(Files.newInputStream(configPath)); } catch (IOException ex) { - logger.info("An error ocurred on configuration initialization", ex); + logger.error("An error ocurred on configuration initialization", ex); + return null; + } catch(IllegalStateException ex) { + logger.error("Invalid configuration provided", ex); return null; } - + } + + public boolean reload() { + Toml toml = this.loadConfig(pluginDirectory); + if (toml == null) { + return false; + } + + this.config = new AuthMeConfig(toml); + this.api = new AuthmeVelocityAPI(this, config); + + listeners.forEach(listener -> proxy.getEventManager().unregisterListener(this, listener)); + listeners.clear(); + + listeners.add(new ProxyListener(config, api, logger, proxy)); + listeners.add(new PluginMessageListener(proxy, logger, config, api)); + + if (proxy.getPluginManager().isLoaded("fastlogin")) { + listeners.add(new FastLoginListener(proxy, api)); + } + + listeners.forEach(listener -> proxy.getEventManager().register(this, listener)); + return true; + } + + public void sendInfoMessage() { + CommandSource source = proxy.getConsoleCommandSource(); + source.sendMessage(MiniMessage.miniMessage().deserialize( + " --- AuthMeVelocity ---")); + source.sendMessage(MiniMessage.miniMessage().deserialize( + "AuthServers: " + config.getAuthServers())); + if (config.getToServerOptions().sendToServer()) { + source.sendMessage(MiniMessage.miniMessage().deserialize( + "LobbyServers: " + config.getToServerOptions().getTeleportServers())); + } } } diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/commands/AuthmeCommand.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/commands/AuthmeCommand.java new file mode 100644 index 0000000..676225a --- /dev/null +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/commands/AuthmeCommand.java @@ -0,0 +1,44 @@ +package com.glyart.authmevelocity.proxy.commands; + +import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.tree.LiteralCommandNode; +import com.velocitypowered.api.command.BrigadierCommand; +import com.velocitypowered.api.command.CommandManager; +import com.velocitypowered.api.command.CommandMeta; +import com.velocitypowered.api.command.CommandSource; + +import net.kyori.adventure.text.minimessage.MiniMessage; + +public class AuthmeCommand { + private AuthmeCommand() {} + + public static void register(AuthMeVelocityPlugin plugin, CommandManager manager) { + LiteralCommandNode command = LiteralArgumentBuilder.literal("authmevelocity") + .requires(src -> src.hasPermission("authmevelocity.commands")) + .then(LiteralArgumentBuilder.literal("reload") + .executes(cmd -> { + CommandSource source = cmd.getSource(); + if (plugin.reload()) { + plugin.sendInfoMessage(); + source.sendMessage(MiniMessage.miniMessage().deserialize( + "AuthmeVelocity has been successfully reloaded")); + } else { + source.sendMessage(MiniMessage.miniMessage().deserialize( + "There was an error while reloading the configuration. Check the server console")); + } + return Command.SINGLE_SUCCESS; + }) + ).build(); + + BrigadierCommand brigadier = new BrigadierCommand(command); + CommandMeta meta = manager.metaBuilder(brigadier) + .plugin(plugin) + .aliases("vauthme", "authmev") + .build(); + + manager.register(meta, brigadier); + + } +} diff --git a/spigot/pom.xml b/spigot/pom.xml index 117aa15..6779597 100644 --- a/spigot/pom.xml +++ b/spigot/pom.xml @@ -5,7 +5,7 @@ parent com.glyart.authmevelocity - 2.1.1 + 2.2.0 4.0.0