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..47abd63ae 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().isPorted(uuid) || !(ViaVersion.getInstance().getPlayerVersion(uuid) >= ProtocolVersion.V1_9)) { players.remove(uuid); return; }