mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-29 14:15:50 +01:00
Remove bossbar on despawn
This commit is contained in:
parent
af08a77b8e
commit
2a5b62aae0
@ -342,7 +342,8 @@ public class CitizensNPC extends AbstractNPC {
|
||||
NMS.replaceTrackerEntry((Player) getEntity());
|
||||
PlayerUpdateTask.registerPlayer(getEntity());
|
||||
}
|
||||
if (SUPPORT_NODAMAGE_TICKS && Setting.DEFAULT_SPAWN_NODAMAGE_TICKS.asInt() != 20) {
|
||||
if (SUPPORT_NODAMAGE_TICKS && (data().has(NPC.Metadata.SPAWN_NODAMAGE_TICKS)
|
||||
|| Setting.DEFAULT_SPAWN_NODAMAGE_TICKS.asInt() != 20)) {
|
||||
try {
|
||||
entity.setNoDamageTicks(data().get(NPC.Metadata.SPAWN_NODAMAGE_TICKS,
|
||||
Setting.DEFAULT_SPAWN_NODAMAGE_TICKS.asInt()));
|
||||
|
@ -38,6 +38,16 @@ public class BossBarTrait extends Trait {
|
||||
super("bossbar");
|
||||
}
|
||||
|
||||
private BossBar getBar() {
|
||||
if (npc.isSpawned() && isBoss(npc.getEntity()))
|
||||
return (BossBar) NMS.getBossBar(npc.getEntity());
|
||||
if (barCache == null) {
|
||||
barCache = Bukkit.getServer().createBossBar(npc.getFullName(), color, style,
|
||||
flags.toArray(new BarFlag[flags.size()]));
|
||||
}
|
||||
return barCache;
|
||||
}
|
||||
|
||||
public BarColor getColor() {
|
||||
return color;
|
||||
}
|
||||
@ -67,13 +77,20 @@ public class BossBarTrait extends Trait {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDespawn() {
|
||||
if (barCache != null) {
|
||||
barCache.removeAll();
|
||||
barCache.hide();
|
||||
barCache = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!npc.isSpawned())
|
||||
return;
|
||||
BossBar bar = isBoss(npc.getEntity()) ? (BossBar) NMS.getBossBar(npc.getEntity())
|
||||
: barCache == null ? barCache = Bukkit.getServer().createBossBar(npc.getFullName(), color, style,
|
||||
flags.toArray(new BarFlag[flags.size()])) : barCache;
|
||||
BossBar bar = getBar();
|
||||
if (bar == null) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user