From 7d68335c1d2efb682e6bded81b0856ef4b931380 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 28 Apr 2019 10:52:49 +1000 Subject: [PATCH] Fix switching to servers with larger view distance --- .../protocol/AbstractPacketHandler.java | 5 +++ .../net/md_5/bungee/protocol/Protocol.java | 5 +++ .../bungee/protocol/packet/ViewDistance.java | 37 +++++++++++++++++++ .../java/net/md_5/bungee/ServerConnector.java | 5 +++ 4 files changed, 52 insertions(+) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/ViewDistance.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 e49af259..39e257c3 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 @@ -33,6 +33,7 @@ import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.TabCompleteResponse; import net.md_5.bungee.protocol.packet.Team; import net.md_5.bungee.protocol.packet.Title; +import net.md_5.bungee.protocol.packet.ViewDistance; public abstract class AbstractPacketHandler { @@ -168,4 +169,8 @@ public abstract class AbstractPacketHandler public void handle(Commands commands) throws Exception { } + + public void handle(ViewDistance viewDistance) 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 564c8800..0e6cac95 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 @@ -39,6 +39,7 @@ import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.TabCompleteResponse; import net.md_5.bungee.protocol.packet.Team; import net.md_5.bungee.protocol.packet.Title; +import net.md_5.bungee.protocol.packet.ViewDistance; public enum Protocol { @@ -184,6 +185,10 @@ public enum Protocol Commands.class, map( ProtocolConstants.MINECRAFT_1_13, 0x11 ) ); + TO_CLIENT.registerPacket( + ViewDistance.class, + map( ProtocolConstants.MINECRAFT_1_14, 0x41 ) + ); TO_SERVER.registerPacket( KeepAlive.class, diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ViewDistance.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ViewDistance.java new file mode 100644 index 00000000..b693a509 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ViewDistance.java @@ -0,0 +1,37 @@ +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 ViewDistance extends DefinedPacket +{ + + private int distance; + + @Override + public void read(ByteBuf buf) + { + distance = DefinedPacket.readVarInt( buf ); + } + + @Override + public void write(ByteBuf buf) + { + DefinedPacket.writeVarInt( distance, buf ); + } + + @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 fb2d9e27..552af4fc 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -46,6 +46,7 @@ import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardScore; import net.md_5.bungee.protocol.packet.SetCompression; +import net.md_5.bungee.protocol.packet.ViewDistance; import net.md_5.bungee.util.BufUtil; import net.md_5.bungee.util.QuietException; @@ -258,6 +259,10 @@ public class ServerConnector extends PacketHandler user.setServerEntityId( login.getEntityId() ); user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) ); + if ( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_14 ) + { + user.unsafe().sendPacket( new ViewDistance( login.getViewDistance() ) ); + } user.setDimension( login.getDimension() ); // Remove from old servers