diff --git a/proxy/pom.xml b/proxy/pom.xml
index c3f32ac..98c2386 100644
--- a/proxy/pom.xml
+++ b/proxy/pom.xml
@@ -34,11 +34,6 @@
3.1.1
provided
-
- org.spongepowered
- configurate-hocon
- 4.1.2
-
com.github.games647
fastlogin.velocity
@@ -54,42 +49,6 @@
maven-jar-plugin
3.2.2
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.3.1-SNAPSHOT
-
-
- package
-
- shade
-
-
- false
- true
-
-
- org.spongepowered
- com.glyart.authmevelocity.libs.configurate
-
-
-
-
-
-
-
-
- *:*
-
- META-INF/maven/
- META-INF/*.MF
-
-
-
-
-
-
-
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 77964d5..9133f8e 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,11 @@
package com.glyart.authmevelocity.proxy;
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
-import com.glyart.authmevelocity.proxy.config.AuthMeConfig.Config;
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.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
@@ -14,6 +14,9 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
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.Collections;
import java.util.HashSet;
@@ -25,8 +28,7 @@ public class AuthMeVelocityPlugin {
private final ProxyServer proxy;
private final Logger logger;
private final Path pluginDirectory;
- private final AuthmeVelocityAPI api;
- Config config = null;
+ private AuthmeVelocityAPI api;
protected final Set loggedPlayers = Collections.synchronizedSet(new HashSet<>());
@@ -35,13 +37,17 @@ public class AuthMeVelocityPlugin {
this.proxy = proxy;
this.logger = logger;
this.pluginDirectory = dataDirectory;
- this.api = new AuthmeVelocityAPI(this);
}
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
- this.config = Objects.requireNonNull(new AuthMeConfig().loadConfig(pluginDirectory, logger), "configuration cannot be null");
-
+ Toml toml = this.loadConfig(pluginDirectory, logger);
+ if(toml == null){
+ logger.warn("Failed to load config.toml. Shutting down.");
+ return;
+ }
+ AuthMeConfig config = Objects.requireNonNull(new AuthMeConfig(toml), "configuration cannot be null");
+ this.api = new AuthmeVelocityAPI(this, config);
proxy.getChannelRegistrar().register(MinecraftChannelIdentifier.create("authmevelocity", "main"));
proxy.getEventManager().register(this, new ProxyListener(config, api));
proxy.getEventManager().register(this, new PluginMessageListener(proxy, logger, config, api));
@@ -64,4 +70,25 @@ public class AuthMeVelocityPlugin {
public AuthmeVelocityAPI getAPI(){
return this.api;
}
+
+ private Toml loadConfig(Path path, Logger logger){
+ if(!Files.exists(path)){
+ try {
+ Files.createDirectory(path);
+ } catch(IOException e){
+ logger.info("An error ocurred on configuration initialization: {}", e.getMessage());
+ return null;
+ }
+ }
+ Path configPath = path.resolve("config.toml");
+ if(!Files.exists(configPath)){
+ try(InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.toml")){
+ Files.copy(in, configPath);
+ } catch(IOException e){
+ logger.info("An error ocurred on configuration initialization: {}", e.getMessage());
+ return null;
+ }
+ }
+ return new Toml().read(configPath.toFile());
+ }
}
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 759dabd..73f79c2 100644
--- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthmeVelocityAPI.java
+++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/AuthmeVelocityAPI.java
@@ -4,6 +4,7 @@ import java.util.Optional;
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;
@@ -15,8 +16,10 @@ import org.jetbrains.annotations.NotNull;
*/
public final class AuthmeVelocityAPI {
private final AuthMeVelocityPlugin plugin;
- AuthmeVelocityAPI(AuthMeVelocityPlugin plugin){
+ private final AuthMeConfig config;
+ AuthmeVelocityAPI(AuthMeVelocityPlugin plugin, AuthMeConfig config){
this.plugin = plugin;
+ this.config = config;
}
/**
* Check if the player is logged in or not
@@ -72,7 +75,7 @@ public final class AuthmeVelocityAPI {
* @return if the server is a login server
*/
public boolean isAuthServer(@NotNull RegisteredServer server){
- return plugin.config.getAuthServers().contains(server.getServerInfo().getName());
+ return config.getAuthServers().contains(server.getServerInfo().getName());
}
/**
@@ -81,6 +84,6 @@ public final class AuthmeVelocityAPI {
* @return if the connection is made from a login server
*/
public boolean isAuthServer(@NotNull ServerConnection connection){
- return plugin.config.getAuthServers().contains(connection.getServerInfo().getName());
+ return config.getAuthServers().contains(connection.getServerInfo().getName());
}
}
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 33563e3..5d712e5 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
@@ -1,76 +1,24 @@
package com.glyart.authmevelocity.proxy.config;
-import java.nio.file.Path;
import java.util.List;
-import java.util.Objects;
import java.util.Set;
-import org.jetbrains.annotations.NotNull;
-import org.slf4j.Logger;
-import org.spongepowered.configurate.CommentedConfigurationNode;
-import org.spongepowered.configurate.ConfigurateException;
-import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
-import org.spongepowered.configurate.objectmapping.ConfigSerializable;
-import org.spongepowered.configurate.objectmapping.meta.Comment;
+import com.moandjiezana.toml.Toml;
-public class AuthMeConfig {
- public Config loadConfig(@NotNull Path path, @NotNull Logger logger){
- Path configPath = Objects.requireNonNull(path).resolve("config.conf");
- final HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
- .defaultOptions(opts -> opts
- .shouldCopyDefaults(true)
- .header("AuthmeVelocity Proxy\n\nOriginal Developer: xQuickGlare\nCurrent Developer: 4drian3d")
- )
- .path(configPath)
- .build();
+public final class AuthMeConfig {
+ private final List authServers;
+ private final ServerOnLogin serverOnLogin;
+ private final Commands commands;
- try {
- final CommentedConfigurationNode node = loader.load();
- config = node.get(Config.class);
- node.set(Config.class, config);
- loader.save(node);
- return config;
- } catch (ConfigurateException exception){
- logger.error("Could not load configuration: {}", exception.getMessage());
- return null;
- }
+ public AuthMeConfig(Toml toml){
+ this.authServers = toml.getList("authServers");
+ this.serverOnLogin = toml.getTable("SendOnLogin").to(ServerOnLogin.class);
+ this.commands = toml.getTable("Commands").to(Commands.class);
}
- @ConfigSerializable
- public static class Config {
-
- @Comment("List of login/registration servers")
- private Set authservers = Set.of(
- "auth1",
- "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;
- }
- }
- @ConfigSerializable
public static class ServerOnLogin {
- @Comment("Send logged in players to another server?")
- private boolean sendToServerOnLogin = false;
-
- @Comment("List of servers to send\nOne of these servers will be chosen at random")
- private List teleportServers = List.of(
- "lobby1",
- "lobby2"
- );
+ private boolean sendToServerOnLogin;
+ private List teleportServers;
public boolean sendToServer(){
return this.sendToServerOnLogin;
@@ -81,20 +29,9 @@ public class AuthMeConfig {
}
}
- @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\nTo deactivate the message, leave it empty")
- private String blockedCommandMessage = "&4You cannot execute commands if you are not logged in yet";
+ private Set allowedCommands;
+ private String blockedCommandMessage;
public Set getAllowedCommands(){
return this.allowedCommands;
@@ -104,8 +41,16 @@ public class AuthMeConfig {
return this.blockedCommandMessage;
}
}
- private Config config = null;
- public Config getConfig(){
- return config;
+
+ public Commands getCommandsConfig(){
+ return this.commands;
+ }
+
+ public ServerOnLogin getToServerOptions(){
+ return this.serverOnLogin;
+ }
+
+ public List getAuthServers(){
+ return this.authServers;
}
}
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
index 4bd960a..919ca40 100644
--- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/ConfigUtils.java
+++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/config/ConfigUtils.java
@@ -1,12 +1,11 @@
package com.glyart.authmevelocity.proxy.config;
-import com.glyart.authmevelocity.proxy.config.AuthMeConfig.Config;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
-public class ConfigUtils {
- public static void sendBlockedMessage(Player player, Config config){
+public final class ConfigUtils {
+ public static void sendBlockedMessage(Player player, AuthMeConfig config){
String blockedMessage = config.getCommandsConfig().getBlockedMessage();
if(!blockedMessage.isBlank()){
player.sendMessage(
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 d515808..9761e2c 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
@@ -25,10 +25,10 @@ public class PluginMessageListener {
private final ProxyServer proxy;
private final Logger logger;
private final Random rm;
- private final AuthMeConfig.Config config;
+ private final AuthMeConfig config;
private final AuthmeVelocityAPI api;
- public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig.Config config, AuthmeVelocityAPI api) {
+ public PluginMessageListener(@NotNull ProxyServer proxy, @NotNull Logger logger, @NotNull AuthMeConfig config, AuthmeVelocityAPI api) {
this.proxy = proxy;
this.logger = logger;
this.rm = new Random();
@@ -52,7 +52,7 @@ public class PluginMessageListener {
switch(sChannel){
case "LOGIN" :
if (api.addPlayer(loggedPlayer)){
- createServerConnectionRequest(loggedPlayer, config, proxy, logger, connection);
+ createServerConnectionRequest(loggedPlayer, proxy, logger, connection);
}
continuation.resume();
break;
@@ -71,7 +71,7 @@ public class PluginMessageListener {
}
}
- private void createServerConnectionRequest(Player loggedPlayer, AuthMeConfig.Config config, ProxyServer proxy, Logger logger, ServerConnection connection){
+ private void createServerConnectionRequest(Player loggedPlayer, ProxyServer proxy, Logger logger, ServerConnection connection){
final RegisteredServer loginServer = loggedPlayer.getCurrentServer().orElse(connection).getServer();
proxy.getEventManager().fireAndForget(new ProxyLoginEvent(loggedPlayer));
if(config.getToServerOptions().sendToServer()){
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 44dcab4..778d3e8 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
@@ -16,11 +16,11 @@ import com.velocitypowered.api.proxy.Player;
import org.jetbrains.annotations.NotNull;
-public class ProxyListener {
- private AuthMeConfig.Config config;
+public final class ProxyListener {
+ private final AuthMeConfig config;
private final AuthmeVelocityAPI api;
- public ProxyListener(@NotNull AuthMeConfig.Config config, AuthmeVelocityAPI api) {
+ public ProxyListener(@NotNull AuthMeConfig config, AuthmeVelocityAPI api) {
this.config = config;
this.api = api;
}
diff --git a/proxy/src/main/resources/config.toml b/proxy/src/main/resources/config.toml
new file mode 100644
index 0000000..6b4556c
--- /dev/null
+++ b/proxy/src/main/resources/config.toml
@@ -0,0 +1,22 @@
+# AuthmeVelocity Proxy
+# Original Developer: xQuickGlare
+# Actual Developer: 4drian3d
+
+# List of login/registration servers
+authServers = ["auth1", "auth2"]
+
+[SendOnLogin]
+ # Send logged in players to another server?
+ sendToServerOnLogin = false
+
+ # List of servers to send
+ # One of these servers will be chosen at random
+ teleportServers = ["lobby1", "lobby2"]
+
+[Commands]
+ # Sets the commands that users who have not yet logged in can execute
+ allowedCommands = ["login", "register", "l", "reg", "email", "captcha"]
+
+ # Sets the message to send in case a non-logged-in player executes an unauthorized command
+ # To deactivate the message, leave it empty
+ blockedCommandMessage = "&4You cannot execute commands if you are not logged in yet"
\ No newline at end of file