Don't use boss bossbar if null
This commit is contained in:
parent
e1a4f88126
commit
9082f6ac3f
|
@ -60,7 +60,7 @@ public class BossBarTrait extends Trait {
|
||||||
}
|
}
|
||||||
|
|
||||||
private BossBar getBar() {
|
private BossBar getBar() {
|
||||||
if (npc.isSpawned() && isBoss(npc.getEntity()))
|
if (npc.isSpawned() && isBoss(npc.getEntity()) && NMS.getBossBar(npc.getEntity()) != null)
|
||||||
return (BossBar) NMS.getBossBar(npc.getEntity());
|
return (BossBar) NMS.getBossBar(npc.getEntity());
|
||||||
if (barCache == null) {
|
if (barCache == null) {
|
||||||
barCache = Bukkit.getServer().createBossBar(npc.getFullName(), color, style,
|
barCache = Bukkit.getServer().createBossBar(npc.getFullName(), color, style,
|
||||||
|
@ -98,10 +98,9 @@ public class BossBarTrait extends Trait {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBoss(Entity entity) {
|
private boolean isBoss(Entity entity) {
|
||||||
boolean isBoss = entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.WITHER
|
boolean isBoss = entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.WITHER;
|
||||||
|| entity.getType() == EntityType.GUARDIAN;
|
|
||||||
if (isBoss) {
|
if (isBoss) {
|
||||||
barCache = null;
|
onDespawn();
|
||||||
}
|
}
|
||||||
return isBoss;
|
return isBoss;
|
||||||
}
|
}
|
||||||
|
@ -129,9 +128,9 @@ public class BossBarTrait extends Trait {
|
||||||
if (!npc.isSpawned())
|
if (!npc.isSpawned())
|
||||||
return;
|
return;
|
||||||
BossBar bar = getBar();
|
BossBar bar = getBar();
|
||||||
if (bar == null) {
|
if (bar == null)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (track != null && !track.isEmpty() && npc.getEntity() instanceof LivingEntity) {
|
if (track != null && !track.isEmpty() && npc.getEntity() instanceof LivingEntity) {
|
||||||
LivingEntity entity = (LivingEntity) npc.getEntity();
|
LivingEntity entity = (LivingEntity) npc.getEntity();
|
||||||
if (track.equalsIgnoreCase("health")) {
|
if (track.equalsIgnoreCase("health")) {
|
||||||
|
@ -170,14 +169,12 @@ public class BossBarTrait extends Trait {
|
||||||
for (BarFlag flag : flags) {
|
for (BarFlag flag : flags) {
|
||||||
bar.addFlag(flag);
|
bar.addFlag(flag);
|
||||||
}
|
}
|
||||||
if (barCache != null) {
|
bar.removeAll();
|
||||||
barCache.removeAll();
|
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(npc.getEntity().getLocation(),
|
||||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(npc.getEntity().getLocation(),
|
range > 0 ? range : Setting.BOSSBAR_RANGE.asInt())) {
|
||||||
range > 0 ? range : Setting.BOSSBAR_RANGE.asInt())) {
|
if (viewPermission != null && !player.hasPermission(viewPermission))
|
||||||
if (viewPermission != null && !player.hasPermission(viewPermission))
|
continue;
|
||||||
continue;
|
bar.addPlayer(player);
|
||||||
barCache.addPlayer(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue