|
40 | 40 | import com.velocitypowered.proxy.connection.MinecraftSessionHandler; |
41 | 41 | import com.velocitypowered.proxy.crypto.IdentifiedKeyImpl; |
42 | 42 | import com.velocitypowered.proxy.protocol.StateRegistry; |
| 43 | +import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; |
43 | 44 | import com.velocitypowered.proxy.protocol.packet.LoginAcknowledgedPacket; |
44 | 45 | import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; |
45 | 46 | import com.velocitypowered.proxy.protocol.packet.ServerboundCookieResponsePacket; |
46 | 47 | import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; |
| 48 | +import com.velocitypowered.proxy.util.ClosestLocaleMatcher; |
47 | 49 | import io.netty.buffer.ByteBuf; |
| 50 | +import java.util.Locale; |
48 | 51 | import java.util.Objects; |
49 | 52 | import java.util.Optional; |
50 | 53 | import java.util.UUID; |
51 | 54 | import java.util.concurrent.CompletableFuture; |
52 | 55 | import net.kyori.adventure.text.Component; |
53 | 56 | import net.kyori.adventure.text.format.NamedTextColor; |
| 57 | +import net.kyori.adventure.translation.GlobalTranslator; |
54 | 58 | import org.apache.logging.log4j.LogManager; |
55 | 59 | import org.apache.logging.log4j.Logger; |
56 | 60 | import org.checkerframework.checker.nullness.qual.MonotonicNonNull; |
@@ -97,16 +101,25 @@ public void activated() { |
97 | 101 | } |
98 | 102 |
|
99 | 103 | // Initiate a regular connection and move over to it. |
| 104 | + if (!server.canRegisterConnection(profileEvent.getGameProfile())) { |
| 105 | + // ConnectedPlayer#disconnect0 uses its own translateMessage(), which uses the players' PlayerSettings |
| 106 | + // to translate the message, but at this stage this wouldn't have been set yet, resulting in |
| 107 | + // Locale.getDefault() being used anyway. |
| 108 | + mcConnection.closeWith(DisconnectPacket.create( |
| 109 | + GlobalTranslator.render( |
| 110 | + Component.translatable("velocity.error.already-connected-proxy", NamedTextColor.RED), |
| 111 | + ClosestLocaleMatcher.INSTANCE.lookupClosest(Locale.getDefault()) |
| 112 | + ), |
| 113 | + mcConnection.getProtocolVersion(), |
| 114 | + mcConnection.getState() |
| 115 | + )); |
| 116 | + return CompletableFuture.completedFuture(null); |
| 117 | + } |
| 118 | + |
100 | 119 | ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(), |
101 | 120 | mcConnection, inbound.getVirtualHost().orElse(null), inbound.getRawVirtualHost().orElse(null), onlineMode, |
102 | 121 | inbound.getHandshakeIntent(), inbound.getIdentifiedKey()); |
103 | 122 | this.connectedPlayer = player; |
104 | | - if (!server.canRegisterConnection(player)) { |
105 | | - player.disconnect0( |
106 | | - Component.translatable("velocity.error.already-connected-proxy", NamedTextColor.RED), |
107 | | - true); |
108 | | - return CompletableFuture.completedFuture(null); |
109 | | - } |
110 | 123 |
|
111 | 124 | if (server.getConfiguration().isLogPlayerConnections()) { |
112 | 125 | logger.info("{} has connected", player); |
|
0 commit comments