From cd7774f0561f5a29767d6ed298202eead6aa50f8 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 8 Jan 2019 13:58:24 -0200 Subject: [PATCH] Use ProtocolInfo#getServerProtocolVersion for block connection, use bungee and velocity version if not ported --- .../ViaVersion/bungee/platform/BungeeViaAPI.java | 8 ++++++-- .../blockconnections/GlassConnectionHandler.java | 6 ++++-- .../velocity/platform/VelocityViaAPI.java | 13 ++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java index df6951bf5..5b779c85f 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java @@ -2,6 +2,7 @@ package us.myles.ViaVersion.bungee.platform; import io.netty.buffer.ByteBuf; import lombok.NonNull; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import us.myles.ViaVersion.api.Via; @@ -23,14 +24,17 @@ public class BungeeViaAPI implements ViaAPI { @Override public int getPlayerVersion(@NonNull ProxiedPlayer player) { if (!isPorted(player.getUniqueId())) - return ProtocolRegistry.SERVER_PROTOCOL; + return player.getPendingConnection().getVersion(); return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); } @Override public int getPlayerVersion(@NonNull UUID uuid) { - if (!isPorted(uuid)) + if (!isPorted(uuid)) { + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); + if (player != null) return player.getPendingConnection().getVersion(); return ProtocolRegistry.SERVER_PROTOCOL; + } return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java index 50523ef31..e014fc4d5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java @@ -2,7 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.Position; -import us.myles.ViaVersion.api.protocol.ProtocolRegistry; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; public class GlassConnectionHandler extends AbstractFenceConnectionHandler { @@ -34,6 +34,8 @@ public class GlassConnectionHandler extends AbstractFenceConnectionHandler { @Override protected byte getStates(UserConnection user, Position position, int blockState) { byte states = super.getStates(user, position, blockState); - return states == 0 && (ProtocolRegistry.SERVER_PROTOCOL <= 47 && ProtocolRegistry.SERVER_PROTOCOL != -1) ? 0xF : states; + return states == 0 + && user.get(ProtocolInfo.class).getServerProtocolVersion() <= 47 + && user.get(ProtocolInfo.class).getServerProtocolVersion() != -1 ? 0xF : states; } } diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java index aca7fe39a..dc6674d6d 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java @@ -1,8 +1,11 @@ package us.myles.ViaVersion.velocity.platform; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.Player; import io.netty.buffer.ByteBuf; import lombok.NonNull; +import us.myles.ViaVersion.VelocityPlugin; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.boss.BossBar; @@ -21,14 +24,18 @@ public class VelocityViaAPI implements ViaAPI { @Override public int getPlayerVersion(@NonNull Player player) { if (!isPorted(player.getUniqueId())) - return ProtocolRegistry.SERVER_PROTOCOL; + return player.getProtocolVersion().getProtocol(); return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); } @Override public int getPlayerVersion(@NonNull UUID uuid) { - if (!isPorted(uuid)) - return ProtocolRegistry.SERVER_PROTOCOL; + if (!isPorted(uuid)) { + return VelocityPlugin.PROXY.getPlayer(uuid) + .map(InboundConnection::getProtocolVersion) + .map(ProtocolVersion::getProtocol) + .orElse(ProtocolRegistry.SERVER_PROTOCOL); + } return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion(); }