Removed LegacySerializer
- Use a supplier instead of create a new object on config load
This commit is contained in:
parent
b2e55e0bae
commit
8668feb8d0
@ -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"),"<red>You cannot execute commands if you are not logged in yet"));
|
||||
this.ensure = ConfigUtils.getOrElse(toml, "EnsureAuthServer", new EnsureAuthServer(false, "<red>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"),"<red>You cannot execute commands if you are not logged in yet"));
|
||||
this.ensure = ConfigUtils.getOrElse(toml, "EnsureAuthServer", () -> new EnsureAuthServer(false, "<red>You could not connect to a login server, please try again later"));
|
||||
}
|
||||
|
||||
public static class ServerOnLogin {
|
||||
|
@ -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>T getOrElse(Toml config, String key, T defaultValue){
|
||||
static <T>T getOrElse(Toml config, String key, Supplier<T> 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(){}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user