mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 20:25:19 +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());
|
NMS.replaceTrackerEntry((Player) getEntity());
|
||||||
PlayerUpdateTask.registerPlayer(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 {
|
try {
|
||||||
entity.setNoDamageTicks(data().get(NPC.Metadata.SPAWN_NODAMAGE_TICKS,
|
entity.setNoDamageTicks(data().get(NPC.Metadata.SPAWN_NODAMAGE_TICKS,
|
||||||
Setting.DEFAULT_SPAWN_NODAMAGE_TICKS.asInt()));
|
Setting.DEFAULT_SPAWN_NODAMAGE_TICKS.asInt()));
|
||||||
|
@ -38,6 +38,16 @@ public class BossBarTrait extends Trait {
|
|||||||
super("bossbar");
|
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() {
|
public BarColor getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
@ -67,13 +77,20 @@ public class BossBarTrait extends Trait {
|
|||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDespawn() {
|
||||||
|
if (barCache != null) {
|
||||||
|
barCache.removeAll();
|
||||||
|
barCache.hide();
|
||||||
|
barCache = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!npc.isSpawned())
|
if (!npc.isSpawned())
|
||||||
return;
|
return;
|
||||||
BossBar bar = isBoss(npc.getEntity()) ? (BossBar) NMS.getBossBar(npc.getEntity())
|
BossBar bar = getBar();
|
||||||
: barCache == null ? barCache = Bukkit.getServer().createBossBar(npc.getFullName(), color, style,
|
|
||||||
flags.toArray(new BarFlag[flags.size()])) : barCache;
|
|
||||||
if (bar == null) {
|
if (bar == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user