diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 9b1b902b8..c04b19cf2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -795,11 +795,22 @@ public class VelocityConfiguration implements ProxyConfig { public static class Messages { private String kickPrefix = "&cKicked from %s: "; private String disconnectPrefix = "&cCan't connect to %s: "; + private String onlineModeOnly = "&cThis server only accepts connections from online-mode clients." + + "\n\n&7Did you change your username? Sign out of Minecraft, sign back in, and try again."; + private String noAvailableServers = "&cThere are no available servers."; + private String alreadyConnected = "&cYou are already connected to this proxy!"; + private String movedToNewServerPrefix = "&cThe server you were on kicked you: "; + private String genericConnectionError = "&cAn internal error occurred in your connection."; private Messages(CommentedConfig toml) { if (toml != null) { this.kickPrefix = toml.getOrElse("kick-prefix", kickPrefix); this.disconnectPrefix = toml.getOrElse("disconnect-prefix", disconnectPrefix); + this.onlineModeOnly = toml.getOrElse("online-mode-only", onlineModeOnly); + this.noAvailableServers = toml.getOrElse("no-available-servers", noAvailableServers); + this.alreadyConnected = toml.getOrElse("already-connected", alreadyConnected); + this.movedToNewServerPrefix = toml.getOrElse("moved-to-new-server-prefix", movedToNewServerPrefix); + this.genericConnectionError = toml.getOrElse("generic-connection-error", genericConnectionError); } } @@ -811,6 +822,26 @@ public class VelocityConfiguration implements ProxyConfig { return serialize(String.format(disconnectPrefix, server)); } + public Component getOnlineModeOnly() { + return serialize(onlineModeOnly); + } + + public Component getNoAvailableServers() { + return serialize(noAvailableServers); + } + + public Component getAlreadyConnected() { + return serialize(alreadyConnected); + } + + public Component getMovedToNewServerPrefix() { + return serialize(movedToNewServerPrefix); + } + + public Component getGenericConnectionError() { + return serialize(genericConnectionError); + } + private Component serialize(String str) { if (str.startsWith("{")) { return GsonComponentSerializer.gson().deserialize(str); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index b8ee436da..e44f83ce6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -31,7 +31,6 @@ import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse; import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse.Offer; import com.velocitypowered.proxy.protocol.packet.TitlePacket; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; -import com.velocitypowered.proxy.util.VelocityMessages; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; @@ -279,7 +278,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public void exception(Throwable throwable) { - player.disconnect(VelocityMessages.GENERIC_CONNECTION_ERROR); + player.disconnect(server.getConfiguration().getMessages().getGenericConnectionError()); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 6536a554b..f6a898ef2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -53,7 +53,6 @@ import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.tablist.VelocityTabList; import com.velocitypowered.proxy.tablist.VelocityTabListLegacy; import com.velocitypowered.proxy.util.DurationUtils; -import com.velocitypowered.proxy.util.VelocityMessages; import com.velocitypowered.proxy.util.collect.CappedSet; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; @@ -596,7 +595,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { disconnect(friendlyReason); } else { if (res.getMessageComponent() == null) { - sendMessage(VelocityMessages.MOVED_TO_NEW_SERVER.append(friendlyReason)); + sendMessage(server.getConfiguration().getMessages().getMovedToNewServerPrefix().append(friendlyReason)); } else { sendMessage(res.getMessageComponent()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 8061710b8..adddd8cca 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -33,7 +33,6 @@ import com.velocitypowered.proxy.protocol.packet.EncryptionResponse; import com.velocitypowered.proxy.protocol.packet.ServerLogin; import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; import com.velocitypowered.proxy.protocol.packet.SetCompression; -import com.velocitypowered.proxy.util.VelocityMessages; import io.netty.buffer.ByteBuf; import io.netty.handler.timeout.ReadTimeoutHandler; import java.net.InetSocketAddress; @@ -133,7 +132,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { GameProfile.class), true); } else if (profileResponse.getStatusCode() == 204) { // Apparently an offline-mode user logged onto this online-mode proxy. - inbound.disconnect(VelocityMessages.ONLINE_MODE_ONLY); + inbound.disconnect(server.getConfiguration().getMessages().getOnlineModeOnly()); } else { // Something else went wrong logger.error( @@ -224,7 +223,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { mcConnection, inbound.getVirtualHost().orElse(null), onlineMode); this.connectedPlayer = player; if (!server.canRegisterConnection(player)) { - player.disconnect0(VelocityMessages.ALREADY_CONNECTED, true); + player.disconnect0(server.getConfiguration().getMessages().getAlreadyConnected(), true); return CompletableFuture.completedFuture(null); } @@ -275,7 +274,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { player.disconnect0(reason.get(), true); } else { if (!server.registerConnection(player)) { - player.disconnect0(VelocityMessages.ALREADY_CONNECTED, true); + player.disconnect0(server.getConfiguration().getMessages().getAlreadyConnected(), true); return; } @@ -295,7 +294,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { .thenRunAsync(() -> { Optional toTry = event.getInitialServer(); if (!toTry.isPresent()) { - player.disconnect0(VelocityMessages.NO_AVAILABLE_SERVERS, true); + player.disconnect0(server.getConfiguration().getMessages().getNoAvailableServers(), true); return; } player.createConnectionRequest(toTry.get()).fireAndForget(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityMessages.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityMessages.java deleted file mode 100644 index a85a8b588..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityMessages.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.velocitypowered.proxy.util; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.format.NamedTextColor; - -public final class VelocityMessages { - - public static final Component ONLINE_MODE_ONLY = TextComponent - .builder("This server only accepts connections from online-mode clients.") - .color(NamedTextColor.RED) - .append( - TextComponent.of("\n\nDid you change your username? Sign out of Minecraft, sign back in, " - + "and try again.", NamedTextColor.GRAY) - ) - .build(); - public static final Component NO_AVAILABLE_SERVERS = TextComponent - .of("There are no available servers.", NamedTextColor.RED); - public static final Component ALREADY_CONNECTED = TextComponent - .of("You are already connected to this proxy!", NamedTextColor.RED); - public static final Component MOVED_TO_NEW_SERVER = TextComponent - .of("The server you were on kicked you: ", NamedTextColor.RED); - public static final Component GENERIC_CONNECTION_ERROR = TextComponent - .of("An internal error occurred in your connection.", NamedTextColor.RED); - - private VelocityMessages() { - throw new AssertionError(); - } -} diff --git a/proxy/src/main/resources/default-velocity.toml b/proxy/src/main/resources/default-velocity.toml index 225af25fb..0b2dbdfb8 100644 --- a/proxy/src/main/resources/default-velocity.toml +++ b/proxy/src/main/resources/default-velocity.toml @@ -167,3 +167,9 @@ kick-prefix = "&cKicked from %s: " # Prefix when the player is disconnected from a server. # First argument '%s': the server name disconnect-prefix = "&cCan't connect to %s: " + +online-mode-only = "&cThis server only accepts connections from online-mode clients.\n\n&7Did you change your username? Sign out of Minecraft, sign back in, and try again." +no-available-servers = "&cThere are no available servers." +already-connected = "&cYou are already connected to this proxy!" +moved-to-new-server-prefix = "&cThe server you were on kicked you: " +generic-connection-error = "&cAn internal error occurred in your connection." \ No newline at end of file