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 87058ab..74d2372 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,7 +1,6 @@ package com.glyart.authmevelocity.proxy.config; import java.util.List; -import java.util.Objects; import java.util.Set; import com.moandjiezana.toml.Toml; @@ -15,16 +14,21 @@ public final class AuthMeConfig { private final EnsureAuthServer ensure; public AuthMeConfig(@NotNull Toml toml){ - this.authServers = Objects.requireNonNull(toml.getList("authServers"), "the list of auth servers is not available, please check your configuration for any failure"); - this.serverOnLogin = Objects.requireNonNull(toml.getTable("SendOnLogin"), "SendOnLogin options are not available, check your configuration").to(ServerOnLogin.class); - this.commands = Objects.requireNonNull(toml.getTable("Commands"), "Commands options are not available, check your configuration").to(Commands.class); - this.ensure = Objects.requireNonNull(toml.getTable("EnsureAuthServer"), "EnsureAuthServer options are not available, check your configuration").to(EnsureAuthServer.class); + this.authServers = toml.getList("authServers", List.of("auth1", "auth2")); + this.serverOnLogin = ConfigUtils.getOrElse(toml, "SendOnLogin", new ServerOnLogin(false, List.of("lobby1", "lobby2"))); + this.commands = ConfigUtils.getOrElse(toml, "Commands", new Commands(Set.of("login", "register", "l", "reg", "email", "captcha"),"&4You cannot execute commands if you are not logged in yet")); + this.ensure = ConfigUtils.getOrElse(toml, "EnsureAuthServer", new EnsureAuthServer(false, "&4You could not connect to a login server, please try again later")); } public static class ServerOnLogin { private boolean sendToServerOnLogin; private List teleportServers; + public ServerOnLogin(boolean sendToServerOnLogin, List teleportServers){ + this.sendToServerOnLogin = sendToServerOnLogin; + this.teleportServers = teleportServers; + } + public boolean sendToServer(){ return this.sendToServerOnLogin; } @@ -34,10 +38,15 @@ public final class AuthMeConfig { } } - public static class Commands{ + public static class Commands { private Set allowedCommands; private String blockedCommandMessage; + public Commands(Set allowedCommands, String blockedCommandMessage){ + this.allowedCommands = allowedCommands; + this.blockedCommandMessage = blockedCommandMessage; + } + public @NotNull Set getAllowedCommands(){ return this.allowedCommands; } @@ -51,6 +60,11 @@ public final class AuthMeConfig { private boolean ensureFirstServerIsAuthServer; private String disconnectMessage; + public EnsureAuthServer(boolean ensureFirstServerIsAuthServer, String disconnectMessage){ + this.ensureFirstServerIsAuthServer = ensureFirstServerIsAuthServer; + this.disconnectMessage = disconnectMessage; + } + public boolean ensureAuthServer(){ return this.ensureFirstServerIsAuthServer; } 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 5090022..f1d6120 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,16 +1,25 @@ package com.glyart.authmevelocity.proxy.config; +import com.moandjiezana.toml.Toml; import com.velocitypowered.api.proxy.Player; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; public final class ConfigUtils { - public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder().character('&').hexColors().build(); + public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() + .character('&').hexColors().hexCharacter('#').build(); + public static void sendBlockedMessage(Player player, AuthMeConfig config){ String blockedMessage = config.getCommandsConfig().getBlockedMessage(); if(!blockedMessage.isBlank()){ player.sendMessage(SERIALIZER.deserialize(blockedMessage)); } } + + @SuppressWarnings("unchecked") + static T getOrElse(Toml config, String key, T defaultValue){ + Toml configTable = config.getTable(key); + return configTable == null ? defaultValue : (T)configTable.to(defaultValue.getClass()); + } private ConfigUtils(){} }