From 8668feb8d02ba7159159a2b6cff3b2fc95f9dfda Mon Sep 17 00:00:00 2001 From: 4drian3d Date: Fri, 18 Mar 2022 16:55:57 +0000 Subject: [PATCH] Removed LegacySerializer - Use a supplier instead of create a new object on config load --- .../proxy/config/AuthMeConfig.java | 6 +++--- .../proxy/config/ConfigUtils.java | 19 +++++-------------- .../proxy/listener/ProxyListener.java | 4 +--- 3 files changed, 9 insertions(+), 20 deletions(-) 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 01eb39a..8fe902d 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 @@ -15,9 +15,9 @@ public final class AuthMeConfig { public AuthMeConfig(@NotNull Toml toml){ 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"),"You cannot execute commands if you are not logged in yet")); - this.ensure = ConfigUtils.getOrElse(toml, "EnsureAuthServer", new EnsureAuthServer(false, "You could not connect to a login server, please try again later")); + 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"),"You cannot execute commands if you are not logged in yet")); + this.ensure = ConfigUtils.getOrElse(toml, "EnsureAuthServer", () -> new EnsureAuthServer(false, "You could not connect to a login server, please try again later")); } public static class ServerOnLogin { 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 d9b8afd..f3f887d 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,35 +1,26 @@ package com.glyart.authmevelocity.proxy.config; +import java.util.function.Supplier; + import com.moandjiezana.toml.Toml; import com.velocitypowered.api.proxy.Player; import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; public final class ConfigUtils { - /** - * Legacy Serializer - * @deprecated use {@link ConfigUtils#MINIMESSAGE} - */ - @Deprecated(forRemoval = true) - public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() - .character('&').hexColors().hexCharacter('#').build(); public static final MiniMessage MINIMESSAGE = MiniMessage.miniMessage(); public static void sendBlockedMessage(Player player, AuthMeConfig config){ String blockedMessage = config.getCommandsConfig().getBlockedMessage(); if(!blockedMessage.isBlank()){ - player.sendMessage(blockedMessage.indexOf('&') != -1 - ? SERIALIZER.deserialize(blockedMessage) - : MINIMESSAGE.deserialize(blockedMessage) - ); + player.sendMessage(MINIMESSAGE.deserialize(blockedMessage)); } } @SuppressWarnings("unchecked") - static T getOrElse(Toml config, String key, T defaultValue){ + static T getOrElse(Toml config, String key, Supplier defaultValue){ Toml configTable = config.getTable(key); - return configTable == null ? defaultValue : (T)configTable.to(defaultValue.getClass()); + return configTable == null ? defaultValue.get() : (T)configTable.to(defaultValue.getClass()); } private ConfigUtils(){} } 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 32b5b72..858cf25 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 @@ -116,9 +116,7 @@ public final class ProxyListener { continuation.resume(); logger.error("Cannot send the player {} to an auth server", event.getPlayer().getUsername()); String disconnectMessage = config.getEnsureOptions().getDisconnectMessage(); - event.getPlayer().disconnect(disconnectMessage.indexOf('&') != -1 - ? ConfigUtils.SERIALIZER.deserialize(config.getEnsureOptions().getDisconnectMessage()) - : ConfigUtils.MINIMESSAGE.deserialize(disconnectMessage)); + event.getPlayer().disconnect(ConfigUtils.MINIMESSAGE.deserialize(disconnectMessage)); return; } event.setInitialServer(server);