Skip to content

Commit

Permalink
fix(velocity): version of component holder in disconnect login packet
Browse files Browse the repository at this point in the history
The disconnect packet during the login phase always expects a JSON text
string, even on 1.20.3 and above, contrary to all other packets that
take a NBT data.

This resulted in a deserialisation error message on the client, which is
fixed by this commit.
  • Loading branch information
diogotcorreia committed Apr 22, 2024
1 parent 1fbe8d8 commit ab7e3d0
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import com.rexcantor64.triton.api.config.FeatureSyntax;
import com.rexcantor64.triton.api.language.MessageParser;
import com.rexcantor64.triton.velocity.player.VelocityLanguagePlayer;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import lombok.val;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
Expand Down Expand Up @@ -37,7 +41,16 @@ private FeatureSyntax getKickSyntax() {
player,
getKickSyntax()
)
.map(result -> new ComponentHolder(player.getProtocolVersion(), result))
.map(result -> {
// During the Login phase, this packet is supposed to send JSON text even on 1.20.3+ (instead of NBT data)
// https://github.com/PaperMC/Velocity/blob/be678840de9c927c9e17bcea06ed7aedcea77d1e/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/DisconnectPacket.java#L81-L82
val connectedPlayer = (ConnectedPlayer) player.getParent();
val isLoginPhase = connectedPlayer.getConnection().getState() == StateRegistry.LOGIN;
return new ComponentHolder(
isLoginPhase ? ProtocolVersion.MINECRAFT_1_20_2 : player.getProtocolVersion(),
result
);
})
.mapToObj(
result -> {
disconnectPacket.setReason(result);
Expand Down

0 comments on commit ab7e3d0

Please sign in to comment.