From c2cc33c6d74ceddaf55cb8960ac305920cc41e90 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 21 Feb 2020 09:40:13 +1100 Subject: [PATCH] #2774: doImmediateRespawn not updated when switching servers --- .../protocol/AbstractPacketHandler.java | 5 +++ .../net/md_5/bungee/protocol/Protocol.java | 5 +++ .../bungee/protocol/packet/GameState.java | 42 +++++++++++++++++++ .../java/net/md_5/bungee/ServerConnector.java | 6 +++ 4 files changed, 58 insertions(+) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/GameState.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index 39e257c3..ac31e435 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -8,6 +8,7 @@ import net.md_5.bungee.protocol.packet.Commands; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.EntityStatus; +import net.md_5.bungee.protocol.packet.GameState; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.Kick; @@ -173,4 +174,8 @@ public abstract class AbstractPacketHandler public void handle(ViewDistance viewDistance) throws Exception { } + + public void handle(GameState gameState) throws Exception + { + } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 8c99ee85..3e3cf99e 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -16,6 +16,7 @@ import net.md_5.bungee.protocol.packet.Commands; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.EntityStatus; +import net.md_5.bungee.protocol.packet.GameState; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.Kick; @@ -202,6 +203,10 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_13, 0x11 ), map( ProtocolConstants.MINECRAFT_1_15, 0x12 ) ); + TO_CLIENT.registerPacket( + GameState.class, + map( ProtocolConstants.MINECRAFT_1_15, 0x1F ) + ); TO_CLIENT.registerPacket( ViewDistance.class, map( ProtocolConstants.MINECRAFT_1_14, 0x41 ), diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/GameState.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/GameState.java new file mode 100644 index 00000000..3c74354b --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/GameState.java @@ -0,0 +1,42 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class GameState extends DefinedPacket +{ + + public static final short IMMEDIATE_RESPAWN = 11; + // + private short state; + private float value; + + @Override + public void read(ByteBuf buf) + { + state = buf.readUnsignedByte(); + value = buf.readFloat(); + } + + @Override + public void write(ByteBuf buf) + { + buf.writeByte( state ); + buf.writeFloat( value ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 2ebfef5e..65d4b0b1 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -37,6 +37,7 @@ import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EntityStatus; +import net.md_5.bungee.protocol.packet.GameState; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.Login; @@ -251,6 +252,11 @@ public class ServerConnector extends PacketHandler // Update debug info from login packet user.unsafe().sendPacket( new EntityStatus( user.getClientEntityId(), login.isReducedDebugInfo() ? EntityStatus.DEBUG_INFO_REDUCED : EntityStatus.DEBUG_INFO_NORMAL ) ); + // And immediate respawn + if ( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_15 ) + { + user.unsafe().sendPacket( new GameState( GameState.IMMEDIATE_RESPAWN, login.isNormalRespawn() ? 0 : 1 ) ); + } user.setDimensionChange( true ); if ( login.getDimension() == user.getDimension() )