13
0
geforkt von Mirrors/Velocity

Move VelocityMessages into config.toml

Dieser Commit ist enthalten in:
Frank van der Heijden 2020-08-19 20:42:22 +02:00
Ursprung 9e27dac557
Commit 3711d56e8c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 26DA56488D314D11
6 geänderte Dateien mit 43 neuen und 38 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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

Datei anzeigen

@ -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());
}

Datei anzeigen

@ -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<RegisteredServer> 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();

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -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."