From 0a53343547fadd76832b2f2bb58c83d4511ae00d Mon Sep 17 00:00:00 2001 From: kashike Date: Sun, 2 Jun 2019 14:47:41 -0700 Subject: [PATCH] Rename some bossbar-related fields and methods --- .../api/util/bossbar/BossBar.java | 14 +++---- .../api/util/bossbar/BossBarFlag.java | 6 +-- .../api/util/bossbar/BossBarOverlay.java | 10 ++--- .../proxy/util/bossbar/VelocityBossBar.java | 40 ++++++++++--------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBar.java b/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBar.java index cdad72698..d5bf30744 100644 --- a/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBar.java +++ b/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBar.java @@ -66,19 +66,19 @@ public interface BossBar { void setTitle(@NonNull Component title); /** - * Gets the boss bar's progress. In Minecraft, this is called 'health' of the boss bar. + * Gets the boss bar's percent. * - * @return progress + * @return percent */ - float getProgress(); + float getPercent(); /** - * Sets a new progress of the boss bar. In Minecraft, this is called 'health' of the boss bar. + * Sets a new percent of the boss bar. * - * @param progress a float between 0 and 1, representing boss bar's progress - * @throws IllegalArgumentException if the new progress is not between 0 and 1 + * @param percent a float between 0 and 1, representing boss bar's percent + * @throws IllegalArgumentException if the new percent is not between 0 and 1 */ - void setProgress(float progress); + void setPercent(float percent); /** * Returns a copy of the {@link Collection} of all {@link Player} added to the boss bar. diff --git a/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBarFlag.java b/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBarFlag.java index d94a2cb29..1e5d46ac6 100644 --- a/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBarFlag.java +++ b/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBarFlag.java @@ -4,7 +4,7 @@ package com.velocitypowered.api.util.bossbar; * Represents any {@link BossBar}'s flags. */ public enum BossBarFlag { - DARKEN_SKY, - DRAGON_BAR, - CREATE_FOG + DARKEN_SCREEN, + PLAY_BOSS_MUSIC, + CREATE_WORLD_FOG } diff --git a/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBarOverlay.java b/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBarOverlay.java index 892710bd5..8d52ffbe0 100644 --- a/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBarOverlay.java +++ b/api/src/main/java/com/velocitypowered/api/util/bossbar/BossBarOverlay.java @@ -4,9 +4,9 @@ package com.velocitypowered.api.util.bossbar; * Represents a overlay of a {@link BossBar}. */ public enum BossBarOverlay { - SOLID, - SEGMENTED_6, - SEGMENTED_10, - SEGMENTED_12, - SEGMENTED_20 + PROGRESS, + NOTCHED_6, + NOTCHED_10, + NOTCHED_12, + NOTCHED_20 } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/VelocityBossBar.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/VelocityBossBar.java index 6162fe7d3..aca1ecb9a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/VelocityBossBar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/VelocityBossBar.java @@ -30,7 +30,7 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos private final UUID uuid; private boolean visible; private Component title; - private float progress; + private float percent; private BossBarColor color; private BossBarOverlay overlay; @@ -39,17 +39,15 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos * @param title the title for the bar * @param color the color of the bar * @param overlay the overlay to use - * @param progress the progress of the bar + * @param percent the percent of the bar */ public VelocityBossBar( - Component title, BossBarColor color, BossBarOverlay overlay, float progress) { + Component title, BossBarColor color, BossBarOverlay overlay, float percent) { this.title = checkNotNull(title, "title"); this.color = checkNotNull(color, "color"); this.overlay = checkNotNull(overlay, "overlay"); - this.progress = progress; - if (progress > 1 || progress < 0) { - throw new IllegalArgumentException("Progress not between 0 and 1"); - } + this.percent = percent; + checkPercent(percent); this.uuid = UUID.randomUUID(); visible = true; players = new ArrayList<>(); @@ -115,25 +113,29 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos } @Override - public float getProgress() { - return progress; + public float getPercent() { + return percent; } @Override - public void setProgress(float progress) { - if (progress > 1 || progress < 0) { - throw new IllegalArgumentException("Progress should be between 0 and 1"); - } - this.progress = progress; + public void setPercent(float percent) { + checkPercent(percent); + this.percent = percent; if (visible) { BossBar bar = new BossBar(); bar.setUuid(uuid); bar.setAction(BossBar.UPDATE_PERCENT); - bar.setPercent(progress); + bar.setPercent(percent); sendToAffected(bar); } } + private void checkPercent(final float percent) { + if (percent < 0f || percent > 1f) { + throw new IllegalArgumentException("Percent must be between 0 and 1"); + } + } + @Override public @Nullable Collection getPlayers() { return ImmutableList.copyOf(players); @@ -221,13 +223,13 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos private short serializeFlags() { short flagMask = 0x0; - if (flags.contains(BossBarFlag.DARKEN_SKY)) { + if (flags.contains(BossBarFlag.DARKEN_SCREEN)) { flagMask |= 0x1; } - if (flags.contains(BossBarFlag.DRAGON_BAR)) { + if (flags.contains(BossBarFlag.PLAY_BOSS_MUSIC)) { flagMask |= 0x2; } - if (flags.contains(BossBarFlag.CREATE_FOG)) { + if (flags.contains(BossBarFlag.CREATE_WORLD_FOG)) { flagMask |= 0x4; } return flagMask; @@ -240,7 +242,7 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos bossBar.setName(GsonComponentSerializer.INSTANCE.serialize(title)); bossBar.setColor(color.ordinal()); bossBar.setOverlay(overlay.ordinal()); - bossBar.setPercent(progress); + bossBar.setPercent(percent); bossBar.setFlags(serializeFlags()); return bossBar; }