From 3f64fb7d5f9d974a455caa66274294210be9326e Mon Sep 17 00:00:00 2001 From: Matsv Date: Fri, 1 Apr 2016 16:03:56 +0200 Subject: [PATCH] Cleanup BossBar class & add new bossbar api method, addPlayers() --- .../us/myles/ViaVersion/api/boss/BossBar.java | 8 +++++ .../us/myles/ViaVersion/boss/ViaBossBar.java | 31 +++++++++++-------- 2 files changed, 26 insertions(+), 13 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 98d814d37..b3cfa2e30 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); + /** + * add multiple players + * + * @param players list of players + * @return the bossbar instance + */ + BossBar addPlayers(Player...players); + /** * Remove the bossbar from a player * diff --git a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java index 39c6202c6..83e5c8aa3 100644 --- a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java +++ b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java @@ -3,6 +3,7 @@ package us.myles.ViaVersion.boss; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import lombok.Getter; +import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.apache.commons.lang.Validate; import org.bukkit.entity.Player; @@ -42,8 +43,7 @@ public class ViaBossBar implements BossBar { } @Override - public BossBar setTitle(String title) { - Validate.notNull(title, "Title cannot be null"); + public BossBar setTitle(@NonNull String title) { this.title = title; sendPacket(UpdateAction.UPDATE_TITLE); return this; @@ -63,24 +63,22 @@ public class ViaBossBar implements BossBar { } @Override - public BossBar setColor(BossColor color) { - Validate.notNull(color, "Color cannot be null"); + public BossBar setColor(@NonNull BossColor color) { this.color = color; sendPacket(UpdateAction.UPDATE_STYLE); return this; } @Override - public BossBar setStyle(BossStyle style) { - Validate.notNull(style, "Style cannot be null"); + public BossBar setStyle(@NonNull BossStyle style) { this.style = style; sendPacket(UpdateAction.UPDATE_STYLE); return this; } @Override - public BossBar addPlayer(Player player) { - if (player != null && !players.contains(player.getUniqueId())) { + public BossBar addPlayer(@NonNull Player player) { + if (!players.contains(player.getUniqueId())) { players.add(player.getUniqueId()); if (visible) sendPacket(player.getUniqueId(), getPacket(UpdateAction.ADD)); @@ -89,8 +87,8 @@ public class ViaBossBar implements BossBar { } @Override - public BossBar removePlayer(Player player) { - if (player != null && players.contains(player.getUniqueId())) { + public BossBar removePlayer(@NonNull Player player) { + if (players.contains(player.getUniqueId())) { players.remove(player.getUniqueId()); sendPacket(player.getUniqueId(), getPacket(UpdateAction.REMOVE)); } @@ -98,7 +96,14 @@ public class ViaBossBar implements BossBar { } @Override - public BossBar addFlag(BossFlag flag) { + public BossBar addPlayers(@NonNull Player... players) { + for (Player p : players) + addPlayer(p); + return this; + } + + @Override + public BossBar addFlag(@NonNull BossFlag flag) { if (!hasFlag(flag)) flags.add(flag); sendPacket(UpdateAction.UPDATE_FLAGS); @@ -106,7 +111,7 @@ public class ViaBossBar implements BossBar { } @Override - public BossBar removeFlag(BossFlag flag) { + public BossBar removeFlag(@NonNull BossFlag flag) { if (hasFlag(flag)) flags.remove(flag); sendPacket(UpdateAction.UPDATE_FLAGS); @@ -114,7 +119,7 @@ public class ViaBossBar implements BossBar { } @Override - public boolean hasFlag(BossFlag flag) { + public boolean hasFlag(@NonNull BossFlag flag) { return flags.contains(flag); }