2.0.1 | Added MiniMessage support in messages

This commit is contained in:
4drian3d 2022-03-03 15:46:20 -05:00
parent b083f8129e
commit d6e0666e0d
7 changed files with 24 additions and 11 deletions

View File

@ -7,7 +7,7 @@
<groupId>com.glyart.authmevelocity</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>2.0.0</version>
<version>2.0.1</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.glyart.authmevelocity</groupId>
<version>2.0.0</version>
<version>2.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -31,7 +31,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.1.1</version>
<version>3.1.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -16,8 +16,8 @@ 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"),"&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"));
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 {

View File

@ -3,21 +3,31 @@ package com.glyart.authmevelocity.proxy.config;
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(SERIALIZER.deserialize(blockedMessage));
player.sendMessage(blockedMessage.indexOf('&') != -1
? SERIALIZER.deserialize(blockedMessage)
: MINIMESSAGE.deserialize(blockedMessage)
);
}
}
@SuppressWarnings("unchecked")
static <T extends Object>T getOrElse(Toml config, String key, T defaultValue){
static <T>T getOrElse(Toml config, String key, T defaultValue){
Toml configTable = config.getTable(key);
return configTable == null ? defaultValue : (T)configTable.to(defaultValue.getClass());
}

View File

@ -89,8 +89,8 @@ public class PluginMessageListener {
proxy.getServer(randomServer).ifPresentOrElse(serverToSend ->
proxy.getEventManager().fire(new PreSendOnLoginEvent(loggedPlayer, loginServer, serverToSend)).thenAcceptAsync(preSendEvent -> {
if(preSendEvent.getResult().isAllowed()){
loggedPlayer.createConnectionRequest(serverToSend).connect().thenAcceptAsync(result -> {
if(!result.isSuccessful()) {
loggedPlayer.createConnectionRequest(serverToSend).connectWithIndication().thenAcceptAsync(result -> {
if(!result.booleanValue()) {
logger.info("Unable to connect the player {} to the server {}",
loggedPlayer.getUsername(),
serverToSend.getServerInfo().getName());

View File

@ -115,7 +115,10 @@ public final class ProxyListener {
if(server == null) {
continuation.resume();
logger.error("Cannot send the player {} to an auth server", event.getPlayer().getUsername());
event.getPlayer().disconnect(ConfigUtils.SERIALIZER.deserialize(config.getEnsureOptions().getDisconnectMessage()));
String disconnectMessage = config.getEnsureOptions().getDisconnectMessage();
event.getPlayer().disconnect(disconnectMessage.indexOf('&') != -1
? ConfigUtils.SERIALIZER.deserialize(config.getEnsureOptions().getDisconnectMessage())
: ConfigUtils.MINIMESSAGE.deserialize(disconnectMessage));
return;
}
event.setInitialServer(server);

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.glyart.authmevelocity</groupId>
<version>2.0.0</version>
<version>2.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>