From 293c1229ff94f4835e0c8774aecdb99d59b5c67c Mon Sep 17 00:00:00 2001 From: Hugo Kerstens Date: Sun, 27 Mar 2016 17:58:31 +0100 Subject: [PATCH 1/2] Update BossBar API to use protocol version and add protocol version by uuid API method --- src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java | 9 ++++++++- src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java | 8 ++++++++ src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index 91dd2d614..daa3e2af7 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -233,6 +233,13 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe return portedPlayers.get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); } + @Override + public int getPlayerVersion(@NonNull UUID uuid) { + if (!isPorted(uuid)) + return ProtocolRegistry.SERVER_PROTOCOL; + return portedPlayers.get(uuid).get(ProtocolInfo.class).getProtocolVersion(); + } + @Override public boolean isPorted(UUID playerUUID) { return portedPlayers.containsKey(playerUUID); @@ -257,7 +264,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe @Override public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException { - if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not on 1.9"); + if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!"); UserConnection ci = portedPlayers.get(uuid); ci.sendRawPacket(packet); } diff --git a/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java b/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java index 49182fa1b..89d84144e 100644 --- a/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java +++ b/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java @@ -25,6 +25,14 @@ public interface ViaVersionAPI { */ int getPlayerVersion(Player player); + /** + * Get protocol number from a player + * + * @param uuid UUID of a player + * @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1) + */ + int getPlayerVersion(UUID uuid); + /** * Is player using 1.9? * diff --git a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java index 24eacea57..94dd01eda 100644 --- a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java +++ b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java @@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.boss.BossBar; import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossFlag; import us.myles.ViaVersion.api.boss.BossStyle; +import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; @@ -143,7 +144,7 @@ public class ViaBossBar implements BossBar { } private void sendPacket(UUID uuid, ByteBuf buf) { - if (!ViaVersion.getInstance().isPorted(uuid)) { + if (ViaVersion.getInstance().getPlayerVersion(uuid) > ProtocolVersion.V1_9) { players.remove(uuid); return; } From f5f4876182fb9a8c29b06cb470a5330e59b0e0f2 Mon Sep 17 00:00:00 2001 From: Hugo Kerstens Date: Sun, 27 Mar 2016 18:05:04 +0100 Subject: [PATCH 2/2] Add check for isPorted because server can be using 1.9 --- src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java index 94dd01eda..47abd63ae 100644 --- a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java +++ b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java @@ -144,7 +144,7 @@ public class ViaBossBar implements BossBar { } private void sendPacket(UUID uuid, ByteBuf buf) { - if (ViaVersion.getInstance().getPlayerVersion(uuid) > ProtocolVersion.V1_9) { + if (!ViaVersion.getInstance().isPorted(uuid) || !(ViaVersion.getInstance().getPlayerVersion(uuid) >= ProtocolVersion.V1_9)) { players.remove(uuid); return; }