Remove boss bar registration system

This commit is contained in:
Kieran Wallbanks 2021-03-27 13:18:08 +00:00
parent 404d6aa45e
commit 45f6d4b80c
3 changed files with 16 additions and 16 deletions

View File

@ -25,16 +25,13 @@ final class BossBarHolder implements Viewable {
protected final UUID uuid = UUID.randomUUID();
protected final Set<Player> players = new CopyOnWriteArraySet<>();
protected final BossBar bar;
protected boolean registered;
BossBarHolder(@NotNull BossBar bar) {
this.bar = bar;
this.registered = false;
}
@NotNull BossBarPacket createRemovePacket() {
return this.createGenericPacket(REMOVE, packet -> {
});
return this.createGenericPacket(REMOVE, packet -> { });
}
@NotNull BossBarPacket createAddPacket() {

View File

@ -56,7 +56,7 @@ class BossBarListener implements BossBar.Listener {
private void doIfRegistered(@NotNull BossBar bar, @NotNull Consumer<BossBarHolder> consumer) {
BossBarHolder holder = this.manager.bars.get(bar);
if (holder != null && holder.registered) {
if (holder != null) {
consumer.accept(holder);
}
}

View File

@ -58,9 +58,9 @@ public class BossBarManager {
* @param bar the boss bar to hide
*/
public void removeBossBar(@NotNull Player player, @NotNull BossBar bar) {
BossBarHolder holder = this.getOrCreateHandler(bar);
BossBarHolder holder = this.bars.get(bar);
if (holder.removeViewer(player)) {
if (holder != null && holder.removeViewer(player)) {
player.getPlayerConnection().sendPacket(holder.createRemovePacket());
this.removePlayer(player, holder);
}
@ -96,18 +96,21 @@ public class BossBarManager {
* @param bar the boss bar to hide
*/
public void removeBossBar(@NotNull Collection<Player> players, @NotNull BossBar bar) {
BossBarHolder holder = this.getOrCreateHandler(bar);
Collection<Player> removedPlayers = new ArrayList<>();
BossBarHolder holder = this.bars.get(bar);
for (Player player : players) {
if (holder.removeViewer(player)) {
removedPlayers.add(player);
this.removePlayer(player, holder);
if (holder != null) {
Collection<Player> removedPlayers = new ArrayList<>();
for (Player player : players) {
if (holder.removeViewer(player)) {
removedPlayers.add(player);
this.removePlayer(player, holder);
}
}
}
if (!removedPlayers.isEmpty()) {
PacketUtils.sendGroupedPacket(removedPlayers, holder.createRemovePacket());
if (!removedPlayers.isEmpty()) {
PacketUtils.sendGroupedPacket(removedPlayers, holder.createRemovePacket());
}
}
}