From d239d2f967d5be4e284dd9ca03ba85e051549f5d Mon Sep 17 00:00:00 2001 From: Mats Date: Mon, 9 May 2016 18:44:10 +0200 Subject: [PATCH] Stop depending the bossbar metadata rewriter on the bukkit api (#391) * Don't depend the bossbar metadata rewriter on the bukkit api * Rename field --- .../java/us/myles/ViaVersion/api/boss/BossBar.java | 8 ++++++++ .../java/us/myles/ViaVersion/boss/ViaBossBar.java | 11 ++++++++--- .../protocol1_9to1_8/storage/EntityTracker.java | 8 +++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java b/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java index 86f5c0a96..68a0ecbd3 100644 --- a/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java +++ b/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java @@ -69,6 +69,14 @@ public interface BossBar { */ BossBar addPlayer(Player player); + /** + * Show the bossbar to a player (uuid) + * + * @param player uuid of the player + * @return the BossBar instance + */ + BossBar addPlayer(UUID player); + /** * add multiple players * diff --git a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java index 619214e08..eacbbfa86 100644 --- a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java +++ b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java @@ -78,10 +78,15 @@ public class ViaBossBar implements BossBar { @Override public BossBar addPlayer(@NonNull Player player) { - if (!players.contains(player.getUniqueId())) { - players.add(player.getUniqueId()); + return addPlayer(player.getUniqueId()); + } + + @Override + public BossBar addPlayer(UUID player) { + if (!players.contains(player)) { + players.add(player); if (visible) - sendPacket(player.getUniqueId(), getPacket(UpdateAction.ADD)); + sendPacket(player, getPacket(UpdateAction.ADD)); } return this; } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java index 3caf9e55c..f556590b3 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java @@ -5,10 +5,8 @@ import com.google.common.cache.CacheBuilder; import io.netty.buffer.ByteBuf; import lombok.Getter; import lombok.Setter; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; @@ -179,7 +177,7 @@ public class EntityTracker extends StoredObject { } } } - Player player = Bukkit.getPlayer(getUser().get(ProtocolInfo.class).getUuid()); + UUID uuid = getUser().get(ProtocolInfo.class).getUuid(); // Boss bar if (((ViaVersionPlugin) ViaVersion.getInstance()).isBossbarPatch()) { if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) { @@ -190,7 +188,7 @@ public class EntityTracker extends StoredObject { if (bar == null) { bar = ViaVersion.getInstance().createBossBar(title, BossColor.PINK, BossStyle.SOLID); bossBarMap.put(entityID, bar); - bar.addPlayer(player); + bar.addPlayer(uuid); bar.show(); } else { bar.setTitle(title); @@ -204,7 +202,7 @@ public class EntityTracker extends StoredObject { String title = type == EntityType.ENDER_DRAGON ? "Ender Dragon" : "Wither"; bar = ViaVersion.getInstance().createBossBar(title, health, BossColor.PINK, BossStyle.SOLID); bossBarMap.put(entityID, bar); - bar.addPlayer(player); + bar.addPlayer(uuid); bar.show(); } else { bar.setHealth(health);