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> <groupId>com.glyart.authmevelocity</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>2.0.0</version> <version>2.0.1</version>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>

View File

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

View File

@ -16,8 +16,8 @@ public final class AuthMeConfig {
public AuthMeConfig(@NotNull Toml toml){ public AuthMeConfig(@NotNull Toml toml){
this.authServers = toml.getList("authServers", List.of("auth1", "auth2")); this.authServers = toml.getList("authServers", List.of("auth1", "auth2"));
this.serverOnLogin = ConfigUtils.getOrElse(toml, "SendOnLogin", new ServerOnLogin(false, List.of("lobby1", "lobby2"))); 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.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, "&4You could not connect to a login server, please try again later")); 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 { public static class ServerOnLogin {

View File

@ -3,21 +3,31 @@ package com.glyart.authmevelocity.proxy.config;
import com.moandjiezana.toml.Toml; import com.moandjiezana.toml.Toml;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
public final class ConfigUtils { public final class ConfigUtils {
/**
* Legacy Serializer
* @deprecated use {@link ConfigUtils#MINIMESSAGE}
*/
@Deprecated(forRemoval = true)
public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder()
.character('&').hexColors().hexCharacter('#').build(); .character('&').hexColors().hexCharacter('#').build();
public static final MiniMessage MINIMESSAGE = MiniMessage.miniMessage();
public static void sendBlockedMessage(Player player, AuthMeConfig config){ public static void sendBlockedMessage(Player player, AuthMeConfig config){
String blockedMessage = config.getCommandsConfig().getBlockedMessage(); String blockedMessage = config.getCommandsConfig().getBlockedMessage();
if(!blockedMessage.isBlank()){ if(!blockedMessage.isBlank()){
player.sendMessage(SERIALIZER.deserialize(blockedMessage)); player.sendMessage(blockedMessage.indexOf('&') != -1
? SERIALIZER.deserialize(blockedMessage)
: MINIMESSAGE.deserialize(blockedMessage)
);
} }
} }
@SuppressWarnings("unchecked") @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); Toml configTable = config.getTable(key);
return configTable == null ? defaultValue : (T)configTable.to(defaultValue.getClass()); return configTable == null ? defaultValue : (T)configTable.to(defaultValue.getClass());
} }

View File

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

View File

@ -115,7 +115,10 @@ public final class ProxyListener {
if(server == null) { if(server == null) {
continuation.resume(); continuation.resume();
logger.error("Cannot send the player {} to an auth server", event.getPlayer().getUsername()); 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; return;
} }
event.setInitialServer(server); event.setInitialServer(server);

View File

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