3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-06 00:00:47 +01:00

Rename some bossbar-related fields and methods

Dieser Commit ist enthalten in:
kashike 2019-06-02 14:47:41 -07:00
Ursprung 20b34447f8
Commit 0a53343547
4 geänderte Dateien mit 36 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -66,19 +66,19 @@ public interface BossBar {
void setTitle(@NonNull Component title); 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 * @param percent a float between 0 and 1, representing boss bar's percent
* @throws IllegalArgumentException if the new progress is not between 0 and 1 * @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. * Returns a copy of the {@link Collection} of all {@link Player} added to the boss bar.

Datei anzeigen

@ -4,7 +4,7 @@ package com.velocitypowered.api.util.bossbar;
* Represents any {@link BossBar}'s flags. * Represents any {@link BossBar}'s flags.
*/ */
public enum BossBarFlag { public enum BossBarFlag {
DARKEN_SKY, DARKEN_SCREEN,
DRAGON_BAR, PLAY_BOSS_MUSIC,
CREATE_FOG CREATE_WORLD_FOG
} }

Datei anzeigen

@ -4,9 +4,9 @@ package com.velocitypowered.api.util.bossbar;
* Represents a overlay of a {@link BossBar}. * Represents a overlay of a {@link BossBar}.
*/ */
public enum BossBarOverlay { public enum BossBarOverlay {
SOLID, PROGRESS,
SEGMENTED_6, NOTCHED_6,
SEGMENTED_10, NOTCHED_10,
SEGMENTED_12, NOTCHED_12,
SEGMENTED_20 NOTCHED_20
} }

Datei anzeigen

@ -30,7 +30,7 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos
private final UUID uuid; private final UUID uuid;
private boolean visible; private boolean visible;
private Component title; private Component title;
private float progress; private float percent;
private BossBarColor color; private BossBarColor color;
private BossBarOverlay overlay; 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 title the title for the bar
* @param color the color of the bar * @param color the color of the bar
* @param overlay the overlay to use * @param overlay the overlay to use
* @param progress the progress of the bar * @param percent the percent of the bar
*/ */
public VelocityBossBar( public VelocityBossBar(
Component title, BossBarColor color, BossBarOverlay overlay, float progress) { Component title, BossBarColor color, BossBarOverlay overlay, float percent) {
this.title = checkNotNull(title, "title"); this.title = checkNotNull(title, "title");
this.color = checkNotNull(color, "color"); this.color = checkNotNull(color, "color");
this.overlay = checkNotNull(overlay, "overlay"); this.overlay = checkNotNull(overlay, "overlay");
this.progress = progress; this.percent = percent;
if (progress > 1 || progress < 0) { checkPercent(percent);
throw new IllegalArgumentException("Progress not between 0 and 1");
}
this.uuid = UUID.randomUUID(); this.uuid = UUID.randomUUID();
visible = true; visible = true;
players = new ArrayList<>(); players = new ArrayList<>();
@ -115,25 +113,29 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos
} }
@Override @Override
public float getProgress() { public float getPercent() {
return progress; return percent;
} }
@Override @Override
public void setProgress(float progress) { public void setPercent(float percent) {
if (progress > 1 || progress < 0) { checkPercent(percent);
throw new IllegalArgumentException("Progress should be between 0 and 1"); this.percent = percent;
}
this.progress = progress;
if (visible) { if (visible) {
BossBar bar = new BossBar(); BossBar bar = new BossBar();
bar.setUuid(uuid); bar.setUuid(uuid);
bar.setAction(BossBar.UPDATE_PERCENT); bar.setAction(BossBar.UPDATE_PERCENT);
bar.setPercent(progress); bar.setPercent(percent);
sendToAffected(bar); sendToAffected(bar);
} }
} }
private void checkPercent(final float percent) {
if (percent < 0f || percent > 1f) {
throw new IllegalArgumentException("Percent must be between 0 and 1");
}
}
@Override @Override
public @Nullable Collection<Player> getPlayers() { public @Nullable Collection<Player> getPlayers() {
return ImmutableList.copyOf(players); return ImmutableList.copyOf(players);
@ -221,13 +223,13 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos
private short serializeFlags() { private short serializeFlags() {
short flagMask = 0x0; short flagMask = 0x0;
if (flags.contains(BossBarFlag.DARKEN_SKY)) { if (flags.contains(BossBarFlag.DARKEN_SCREEN)) {
flagMask |= 0x1; flagMask |= 0x1;
} }
if (flags.contains(BossBarFlag.DRAGON_BAR)) { if (flags.contains(BossBarFlag.PLAY_BOSS_MUSIC)) {
flagMask |= 0x2; flagMask |= 0x2;
} }
if (flags.contains(BossBarFlag.CREATE_FOG)) { if (flags.contains(BossBarFlag.CREATE_WORLD_FOG)) {
flagMask |= 0x4; flagMask |= 0x4;
} }
return flagMask; return flagMask;
@ -240,7 +242,7 @@ public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.Bos
bossBar.setName(GsonComponentSerializer.INSTANCE.serialize(title)); bossBar.setName(GsonComponentSerializer.INSTANCE.serialize(title));
bossBar.setColor(color.ordinal()); bossBar.setColor(color.ordinal());
bossBar.setOverlay(overlay.ordinal()); bossBar.setOverlay(overlay.ordinal());
bossBar.setPercent(progress); bossBar.setPercent(percent);
bossBar.setFlags(serializeFlags()); bossBar.setFlags(serializeFlags());
return bossBar; return bossBar;
} }