Add BossBar API (#213)

This commit is contained in:
MrIvanPlays
2019-06-02 22:02:43 +03:00
committed by Andrew Steinborn
parent dfe210707f
commit 20b34447f8
7 changed files with 506 additions and 0 deletions

View File

@@ -10,11 +10,15 @@ import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerInfo;
import com.velocitypowered.api.scheduler.Scheduler;
import com.velocitypowered.api.util.ProxyVersion;
import com.velocitypowered.api.util.bossbar.BossBar;
import com.velocitypowered.api.util.bossbar.BossBarColor;
import com.velocitypowered.api.util.bossbar.BossBarOverlay;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Provides an interface to a Minecraft server proxy.
@@ -173,4 +177,17 @@ public interface ProxyServer {
* @return the proxy version
*/
ProxyVersion getVersion();
/**
* Creates a new {@link BossBar}.
*
* @param title boss bar title
* @param color boss bar color
* @param overlay boss bar overlay
* @param progress boss bar progress
* @return a completely new and fresh boss bar
*/
@NonNull
BossBar createBossBar(@NonNull Component title, @NonNull BossBarColor color,
@NonNull BossBarOverlay overlay, float progress);
}

View File

@@ -0,0 +1,163 @@
package com.velocitypowered.api.util.bossbar;
import com.velocitypowered.api.proxy.Player;
import java.util.Collection;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents a boss bar, which can be send to a (group of) player(s).
* <b>Boss bars only work on 1.9 and above.</b>
*/
public interface BossBar {
/**
* Adds all specified players to this boss bar.
*
* @param players players
* @see #addPlayer(Player)
*/
void addPlayers(Iterable<Player> players);
/**
* Adds player to this boss bar. This adds the player to the {@link #getPlayers()} and makes him
* see the boss bar.
*
* @param player the player you wish to add
*/
void addPlayer(@NonNull Player player);
/**
* Removes player from this boss bar. This removes the player from {@link #getPlayers()} and makes
* him not see the boss bar.
*
* @param player the player you wish to remove
*/
void removePlayer(@NonNull Player player);
/**
* Removes all specified players from this boss bar.
*
* @param players players
* @see #removePlayer(Player)
*/
void removePlayers(Iterable<Player> players);
/**
* Removes all players, that see this boss bar.
*
* @see #removePlayer(Player)
*/
void removeAllPlayers();
/**
* Gets the title of this boss bar.
*
* @return title
*/
@NonNull
Component getTitle();
/**
* Sets a new title of the boss bar.
*
* @param title new title
*/
void setTitle(@NonNull Component title);
/**
* Gets the boss bar's progress. In Minecraft, this is called 'health' of the boss bar.
*
* @return progress
*/
float getProgress();
/**
* Sets a new progress of the boss bar. In Minecraft, this is called 'health' 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
*/
void setProgress(float progress);
/**
* Returns a copy of the {@link Collection} of all {@link Player} added to the boss bar.
* <i>Can be empty.</i>
*
* @return players
*/
Collection<Player> getPlayers();
/**
* Gets the color of the boss bar.
*
* @return boss bar color
*/
@NonNull
BossBarColor getColor();
/**
* Sets a new color of the boss bar.
*
* @param color the color you wish the boss bar be displayed with
*/
void setColor(@NonNull BossBarColor color);
/**
* Gets the overlay of the boss bar.
*
* @return boss bar overlay
*/
@NonNull
BossBarOverlay getOverlay();
/**
* Sets a new overlay of the boss bar.
*
* @param overlay the overlay you wish the boss bar be displayed with
*/
void setOverlay(@NonNull BossBarOverlay overlay);
/**
* Returns whenever this boss bar is visible to all added {@link #getPlayers()}. By default, it
* returns <code>true</code>.
*
* @return <code>true</code> if visible, otherwise <code>false</code>
*/
boolean isVisible();
/**
* Sets a new visibility to the boss bar.
*
* @param visible boss bar visibility value
*/
void setVisible(boolean visible);
/**
* Returns a copy of of the {@link Collection} of all {@link BossBarFlag}s added to the boss bar.
*
* @return flags
*/
Collection<BossBarFlag> getFlags();
/**
* Adds new flags to the boss bar.
*
* @param flags the flags you wish to add
*/
void addFlags(BossBarFlag... flags);
/**
* Removes flag from the boss bar.
*
* @param flag the flag you wish to remove
*/
void removeFlag(BossBarFlag flag);
/**
* Removes flags from the boss bar.
*
* @param flags the flags you wish to remove
*/
void removeFlags(BossBarFlag... flags);
}

View File

@@ -0,0 +1,14 @@
package com.velocitypowered.api.util.bossbar;
/**
* Represents a color of a {@link BossBar}.
*/
public enum BossBarColor {
PINK,
BLUE,
RED,
GREEN,
YELLOW,
PURPLE,
WHITE;
}

View File

@@ -0,0 +1,10 @@
package com.velocitypowered.api.util.bossbar;
/**
* Represents any {@link BossBar}'s flags.
*/
public enum BossBarFlag {
DARKEN_SKY,
DRAGON_BAR,
CREATE_FOG
}

View File

@@ -0,0 +1,12 @@
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
}