mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-21 00:17:44 +01:00
Add some cases where the locale should fallback to the default
This commit is contained in:
@@ -24,9 +24,11 @@ import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
|
|||||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
|
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
|
||||||
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
|
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
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.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -76,9 +78,11 @@ public final class InitialInboundConnection implements InboundConnection,
|
|||||||
* @param reason the reason for disconnecting
|
* @param reason the reason for disconnecting
|
||||||
*/
|
*/
|
||||||
public void disconnect(Component reason) {
|
public void disconnect(Component reason) {
|
||||||
|
Component translated = GlobalTranslator.render(reason, Locale.getDefault());
|
||||||
|
|
||||||
logger.info("{} has disconnected: {}", this,
|
logger.info("{} has disconnected: {}", this,
|
||||||
LegacyComponentSerializer.legacySection().serialize(reason));
|
LegacyComponentSerializer.legacySection().serialize(translated));
|
||||||
connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion()));
|
connection.closeWith(ClientboundDisconnectPacket.create(translated, protocolVersion()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,6 +90,7 @@ public final class InitialInboundConnection implements InboundConnection,
|
|||||||
* @param reason the reason for disconnecting
|
* @param reason the reason for disconnecting
|
||||||
*/
|
*/
|
||||||
public void disconnectQuietly(Component reason) {
|
public void disconnectQuietly(Component reason) {
|
||||||
connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion()));
|
Component translated = GlobalTranslator.render(reason, Locale.getDefault());
|
||||||
|
connection.closeWith(ClientboundDisconnectPacket.create(translated, protocolVersion()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import com.velocitypowered.proxy.config.VelocityConfiguration;
|
|||||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
import com.velocitypowered.proxy.network.StateRegistry;
|
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.ClientboundEncryptionRequestPacket;
|
||||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
|
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
|
||||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
|
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
|
||||||
@@ -59,12 +58,14 @@ import java.security.GeneralSecurityException;
|
|||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.translation.GlobalTranslator;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.asynchttpclient.ListenableFuture;
|
import org.asynchttpclient.ListenableFuture;
|
||||||
@@ -191,8 +192,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
Optional<Component> disconnectReason = result.denialReason();
|
Optional<Component> disconnectReason = result.denialReason();
|
||||||
if (disconnectReason.isPresent()) {
|
if (disconnectReason.isPresent()) {
|
||||||
// The component is guaranteed to be provided if the connection was denied.
|
// The component is guaranteed to be provided if the connection was denied.
|
||||||
mcConnection.closeWith(ClientboundDisconnectPacket.create(disconnectReason.get(),
|
Component disconnectReasonTranslated = GlobalTranslator.render(disconnectReason.get(),
|
||||||
inbound.protocolVersion()));
|
Locale.getDefault());
|
||||||
|
inbound.disconnect(disconnectReasonTranslated);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user