mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-01 21:11:33 +01:00
Remove BossBar from the Player class, BossBar#addViewer should be used instead
This commit is contained in:
parent
bf0dd4a750
commit
20e78afb40
@ -18,6 +18,8 @@ public class AdvancementTab implements Viewable {
|
||||
|
||||
private Set<Player> viewers = new HashSet<>();
|
||||
|
||||
private AdvancementRoot root;
|
||||
|
||||
// Advancement -> its parent
|
||||
private Map<Advancement, Advancement> advancementMap = new HashMap<>();
|
||||
|
||||
@ -27,13 +29,24 @@ public class AdvancementTab implements Viewable {
|
||||
// will never change (since the root identifier is always the same)
|
||||
protected ByteBuf removeBuffer;
|
||||
|
||||
protected AdvancementTab(String rootIdentifier, Advancement root) {
|
||||
protected AdvancementTab(String rootIdentifier, AdvancementRoot root) {
|
||||
this.root = root;
|
||||
|
||||
cacheAdvancement(rootIdentifier, root, null);
|
||||
|
||||
final AdvancementsPacket removePacket = AdvancementUtils.getRemovePacket(new String[]{rootIdentifier});
|
||||
this.removeBuffer = PacketUtils.writePacket(removePacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root advancement of this tab
|
||||
*
|
||||
* @return the root advancement
|
||||
*/
|
||||
public AdvancementRoot getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and add an advancement into this tab
|
||||
*
|
||||
|
@ -34,17 +34,19 @@ public class BossBar implements Viewable {
|
||||
|
||||
@Override
|
||||
public boolean addViewer(Player player) {
|
||||
boolean result = this.viewers.add(player);
|
||||
player.refreshAddBossbar(this);
|
||||
final boolean result = this.viewers.add(player);
|
||||
if (result) {
|
||||
addToPlayer(player);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeViewer(Player player) {
|
||||
boolean result = this.viewers.remove(player);
|
||||
player.refreshRemoveBossbar(this);
|
||||
final boolean result = this.viewers.remove(player);
|
||||
if (result) {
|
||||
removeToPlayer(player);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -139,7 +141,6 @@ public class BossBar implements Viewable {
|
||||
bossBarPacket.uuid = uuid;
|
||||
bossBarPacket.action = BossBarPacket.Action.REMOVE;
|
||||
sendPacketToViewers(bossBarPacket);
|
||||
getViewers().forEach(player -> player.refreshRemoveBossbar(this));
|
||||
}
|
||||
|
||||
private void addToPlayer(Player player) {
|
||||
|
@ -2,7 +2,6 @@ package net.minestom.server.entity;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.attribute.Attribute;
|
||||
import net.minestom.server.bossbar.BossBar;
|
||||
import net.minestom.server.chat.ChatParser;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.chat.RichMessage;
|
||||
@ -108,7 +107,6 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
private byte targetLastStage;
|
||||
private int blockBreakTime;
|
||||
|
||||
private Set<BossBar> bossBars = new CopyOnWriteArraySet<>();
|
||||
private Team team;
|
||||
private BelowNameScoreboard belowNameScoreboard;
|
||||
|
||||
@ -490,7 +488,6 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
public void remove() {
|
||||
super.remove();
|
||||
this.packets.clear();
|
||||
clearBossBars();
|
||||
if (getOpenInventory() != null)
|
||||
getOpenInventory().removeViewer(this);
|
||||
this.viewableEntities.forEach(entity -> entity.removeViewer(this));
|
||||
@ -1411,13 +1408,6 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
return targetCustomBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an unmodifiable {@link Set} containing all the current player viewable boss bars
|
||||
*/
|
||||
public Set<BossBar> getBossBars() {
|
||||
return Collections.unmodifiableSet(bossBars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player open inventory
|
||||
*
|
||||
@ -1527,13 +1517,6 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
return Collections.unmodifiableSet(viewableChunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all the boss bars that the player has
|
||||
*/
|
||||
public void clearBossBars() {
|
||||
this.bossBars.forEach(bossBar -> bossBar.removeViewer(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a {@link UpdateViewPositionPacket} to the player
|
||||
*
|
||||
@ -1891,26 +1874,6 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally to add Bossbar in the {@link #getBossBars()} set
|
||||
* You probably want to use {@link BossBar#addViewer(Player)}
|
||||
*
|
||||
* @param bossBar the bossbar to add internally
|
||||
*/
|
||||
public void refreshAddBossbar(BossBar bossBar) {
|
||||
this.bossBars.add(bossBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally to remove Bossbar from the {@link #getBossBars()} set
|
||||
* You probably want to use {@link BossBar#removeViewer(Player)}
|
||||
*
|
||||
* @param bossBar the bossbar to remove internally
|
||||
*/
|
||||
public void refreshRemoveBossbar(BossBar bossBar) {
|
||||
this.bossBars.remove(bossBar);
|
||||
}
|
||||
|
||||
public void refreshVehicleSteer(float sideways, float forward, boolean jump, boolean unmount) {
|
||||
this.vehicleInformation.refresh(sideways, forward, jump, unmount);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user