3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Add some cases where the locale should fallback to the default

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-04-17 07:06:23 -04:00
Ursprung 3d0ca2732e
Commit 50f4742240
2 geänderte Dateien mit 13 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -24,9 +24,11 @@ import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import java.net.InetSocketAddress;
import java.util.Locale;
import java.util.Optional;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.translation.GlobalTranslator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -76,9 +78,11 @@ public final class InitialInboundConnection implements InboundConnection,
* @param reason the reason for disconnecting
*/
public void disconnect(Component reason) {
Component translated = GlobalTranslator.render(reason, Locale.getDefault());
logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.legacySection().serialize(reason));
connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion()));
LegacyComponentSerializer.legacySection().serialize(translated));
connection.closeWith(ClientboundDisconnectPacket.create(translated, protocolVersion()));
}
/**
@ -86,6 +90,7 @@ public final class InitialInboundConnection implements InboundConnection,
* @param reason the reason for disconnecting
*/
public void disconnectQuietly(Component reason) {
connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion()));
Component translated = GlobalTranslator.render(reason, Locale.getDefault());
connection.closeWith(ClientboundDisconnectPacket.create(translated, protocolVersion()));
}
}

Datei anzeigen

@ -47,7 +47,6 @@ import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
@ -59,12 +58,14 @@ import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadLocalRandom;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.translation.GlobalTranslator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.asynchttpclient.ListenableFuture;
@ -191,8 +192,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
Optional<Component> disconnectReason = result.denialReason();
if (disconnectReason.isPresent()) {
// The component is guaranteed to be provided if the connection was denied.
mcConnection.closeWith(ClientboundDisconnectPacket.create(disconnectReason.get(),
inbound.protocolVersion()));
Component disconnectReasonTranslated = GlobalTranslator.render(disconnectReason.get(),
Locale.getDefault());
inbound.disconnect(disconnectReasonTranslated);
return;
}