From 984791212880968fa7a08e43ba6446bf44ce407d Mon Sep 17 00:00:00 2001 From: Hugo Kerstens Date: Sun, 27 Mar 2016 21:25:31 +0200 Subject: [PATCH] Make BossBar API easier to use --- .../us/myles/ViaVersion/api/boss/BossBar.java | 20 ++++++------- .../us/myles/ViaVersion/boss/ViaBossBar.java | 30 ++++++++++++------- 2 files changed, 30 insertions(+), 20 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 07cfd4b34..98d814d37 100644 --- a/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java +++ b/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java @@ -18,7 +18,7 @@ public interface BossBar { * * @param title Title can be in either JSON or just text */ - void setTitle(String title); + BossBar setTitle(String title); /** * Get the health @@ -32,7 +32,7 @@ public interface BossBar { * * @param health this float has to be between 0F - 1F */ - void setHealth(float health); + BossBar setHealth(float health); /** * Get the bossbar color @@ -46,7 +46,7 @@ public interface BossBar { * * @param color Whatever color you want! */ - void setColor(BossColor color); + BossBar setColor(BossColor color); /** * Get the bosbar style @@ -60,35 +60,35 @@ public interface BossBar { * * @param style BossStyle */ - void setStyle(BossStyle style); + BossBar setStyle(BossStyle style); /** * Show the bossbar to a player. * * @param player */ - void addPlayer(Player player); + BossBar addPlayer(Player player); /** * Remove the bossbar from a player * * @param player */ - void removePlayer(Player player); + BossBar removePlayer(Player player); /** * Add flags * * @param flag */ - void addFlag(BossFlag flag); + BossBar addFlag(BossFlag flag); /** * Remove flags. * * @param flag */ - void removeFlag(BossFlag flag); + BossBar removeFlag(BossFlag flag); /** * @param flag @@ -106,12 +106,12 @@ public interface BossBar { /** * Show the bossbar to everyone (In the getPlayer set) */ - void show(); + BossBar show(); /** * Hide the bossbar from everyone (In the getPlayer set) */ - void hide(); + BossBar hide(); /** * Is it visible? diff --git a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java index 47abd63ae..076b7ef13 100644 --- a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java +++ b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java @@ -42,17 +42,19 @@ public class ViaBossBar implements BossBar { } @Override - public void setTitle(String title) { + public BossBar setTitle(String title) { Validate.notNull(title, "Title cannot be null"); this.title = title; sendPacket(UpdateAction.UPDATE_TITLE); + return this; } @Override - public void setHealth(float health) { + public BossBar setHealth(float health) { Validate.isTrue((health >= 0 && health <= 1), "Health must be between 0 and 1"); this.health = health; sendPacket(UpdateAction.UPDATE_HEALTH); + return this; } @Override @@ -61,48 +63,54 @@ public class ViaBossBar implements BossBar { } @Override - public void setColor(BossColor color) { + public BossBar setColor(BossColor color) { Validate.notNull(color, "Color cannot be null"); this.color = color; sendPacket(UpdateAction.UPDATE_STYLE); + return this; } @Override - public void setStyle(BossStyle style) { + public BossBar setStyle(BossStyle style) { Validate.notNull(style, "Style cannot be null"); this.style = style; sendPacket(UpdateAction.UPDATE_STYLE); + return this; } @Override - public void addPlayer(Player player) { + public BossBar addPlayer(Player player) { if (player != null && !players.contains(player.getUniqueId())) { players.add(player.getUniqueId()); if (visible) sendPacket(player.getUniqueId(), getPacket(UpdateAction.ADD)); } + return this; } @Override - public void removePlayer(Player player) { + public BossBar removePlayer(Player player) { if (player != null && players.contains(player.getUniqueId())) { players.remove(player.getUniqueId()); sendPacket(player.getUniqueId(), getPacket(UpdateAction.REMOVE)); } + return this; } @Override - public void addFlag(BossFlag flag) { + public BossBar addFlag(BossFlag flag) { if (!hasFlag(flag)) flags.add(flag); sendPacket(UpdateAction.UPDATE_FLAGS); + return this; } @Override - public void removeFlag(BossFlag flag) { + public BossBar removeFlag(BossFlag flag) { if (hasFlag(flag)) flags.remove(flag); sendPacket(UpdateAction.UPDATE_FLAGS); + return this; } @Override @@ -116,13 +124,15 @@ public class ViaBossBar implements BossBar { } @Override - public void show() { + public BossBar show() { setVisible(true); + return this; } @Override - public void hide() { + public BossBar hide() { setVisible(false); + return this; } @Override