From 812141f4006cd500780f876921c2df8648a0d746 Mon Sep 17 00:00:00 2001 From: Mystiflow Date: Sat, 29 Oct 2016 07:59:38 +0100 Subject: [PATCH] Only double switch if the dimension is the same. (#1977) According to the protocol, a double respawn packet is only needed to be sent if from the same dimension, so by storing the last known dimension, we are able to compare and avoid the double packet. This also maintains the same behaviour for Spigot https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/ad2f806097e51fbf72f64ba97e2e4c3785326f42 --- .../java/net/md_5/bungee/ServerConnector.java | 7 ++++++- .../main/java/net/md_5/bungee/UserConnection.java | 15 ++++++--------- .../md_5/bungee/connection/DownstreamBridge.java | 7 +++++++ 3 files changed, 19 insertions(+), 10 deletions(-) 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 72ca169e..0766e819 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -222,10 +222,15 @@ public class ServerConnector extends PacketHandler } user.getSentBossBars().clear(); - user.sendDimensionSwitch(); + user.setDimensionChange( true ); + if ( login.getDimension() == user.getDimension() ) + { + user.unsafe().sendPacket( new Respawn( ( login.getDimension() >= 0 ? -1 : 0 ), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) ); + } user.setServerEntityId( login.getEntityId() ); user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) ); + user.setDimension( login.getDimension() ); // Remove from old servers user.getServer().disconnect( "Quitting" ); diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 0e621c2e..d620fbf5 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -55,6 +55,7 @@ import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.PlayerListHeaderFooter; import net.md_5.bungee.protocol.packet.PluginMessage; +import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.tab.ServerUnique; import net.md_5.bungee.tab.TabList; @@ -80,6 +81,9 @@ public final class UserConnection implements ProxiedPlayer private ServerConnection server; @Getter @Setter + private int dimension; + @Getter + @Setter private boolean dimensionChange = true; @Getter private final Collection pendingConnects = new HashSet<>(); @@ -210,17 +214,10 @@ public final class UserConnection implements ProxiedPlayer connect( target, callback, false ); } - void sendDimensionSwitch() - { - dimensionChange = true; - unsafe().sendPacket( PacketConstants.DIM1_SWITCH ); - unsafe().sendPacket( PacketConstants.DIM2_SWITCH ); - } - public void connectNow(ServerInfo target) { - sendDimensionSwitch(); - connect( target ); + dimensionChange = true; + connect(target); } public ServerInfo updateAndGetNextServer(ServerInfo currentTarget) diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 288d6024..22f10452 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -33,6 +33,7 @@ import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.packet.BossBar; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.PlayerListItem; +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.ScoreboardDisplay; @@ -504,6 +505,12 @@ public class DownstreamBridge extends PacketHandler } } + @Override + public void handle(Respawn respawn) + { + con.setDimension( respawn.getDimension() ); + } + @Override public String toString() {