use of org.bukkit.boss.BossBar in project Denizen-For-Bukkit by DenizenScript.
the class BossBarHelper method removeSimpleBossBar.
public static void removeSimpleBossBar(Player player) {
UUID uuid = player.getUniqueId();
if (bossBars.containsKey(uuid) && !bossBars.get(uuid).isEmpty()) {
Iterator<BossBar> iterator = bossBars.get(uuid).iterator();
while (iterator.hasNext()) {
BossBar bossBar = iterator.next();
bossBar.removePlayer(player);
iterator.remove();
}
}
}
use of org.bukkit.boss.BossBar in project InfernalMobs by NyaaCat.
the class BossBarManager method getBossBar.
private static BossBar getBossBar(LivingEntity livingEntity) {
BossBar bossBar = bossBarMap.computeIfAbsent(livingEntity, k -> {
String customName = livingEntity.getCustomName() == null ? livingEntity.getName() : livingEntity.getCustomName();
BossBar bossBar1 = Bukkit.createBossBar(customName, BarColor.BLUE, BarStyle.SEGMENTED_10);
refreshBar(bossBar1, livingEntity);
return bossBar1;
});
return bossBar;
}
use of org.bukkit.boss.BossBar in project InfernalMobs by NyaaCat.
the class BossBarManager method registerNearbyBossBar.
static void registerNearbyBossBar(Player p, Set<Entity> nearbyInfMobs) {
int maxBars = getMaxBarCount();
HashSet<BossBar> bossBars = playerBarMap.computeIfAbsent(p, k -> new HashSet<>());
// bossBars.clear();
List<AngledEntity> angleSet = new ArrayList<>();
nearbyInfMobs.forEach(entity -> {
LivingEntity currentMobEntity = (LivingEntity) entity;
Vector eyeSight = p.getEyeLocation().getDirection();
Vector mobVector = currentMobEntity.getEyeLocation().toVector().subtract(p.getEyeLocation().toVector());
double angle = Helper.getVectorAngle(eyeSight, mobVector);
if (!Double.isFinite(angle)) {
return;
}
angleSet.add(new AngledEntity(angle, calcDistance(p, entity), currentMobEntity));
});
List<AngledEntity> collect = angleSet.stream().sorted().limit(maxBars).collect(Collectors.toList());
synchronized (registerLock) {
bossBars.clear();
if (!collect.isEmpty()) {
collect.forEach(angle -> {
BossBar bossBar = getBossBar(angle.livingEntity);
registerPlayer(bossBar, p);
});
}
}
}
use of org.bukkit.boss.BossBar in project InfernalMobs by NyaaCat.
the class BossBarManager method updateBar.
static void updateBar() {
Bukkit.getScheduler().runTaskLaterAsynchronously(InfernalMobs.instance, () -> {
if (!barPlayerMap.isEmpty()) {
synchronized (registerLock) {
List<BossBar> removeList = new ArrayList<>();
synchronized (barPlayerMap) {
barPlayerMap.forEach((bossBar, players) -> {
if (bossBar == null)
return;
if (!players.isEmpty()) {
for (Player player : players) {
HashSet<BossBar> bossBars = playerBarMap.computeIfAbsent(player, player1 -> new HashSet<>());
if (bossBars.contains(bossBar)) {
bossBar.addPlayer(player);
} else {
bossBar.removePlayer(player);
}
}
}
BiMap<BossBar, LivingEntity> inverse = bossBarMap.inverse();
LivingEntity livingEntity = inverse.get(bossBar);
if (livingEntity == null) {
bossBar.removeAll();
inverse.remove(bossBar);
removeList.add(bossBar);
return;
}
// refreshBar(bossBar, livingEntity);
});
removeList.forEach(bossBar -> {
barPlayerMap.remove(bossBar);
Bukkit.getScheduler().runTask(InfernalMobs.instance, () -> playerBarMap.forEach((player, bossBars) -> bossBars.remove(bossBar)));
});
}
}
}
}, 1);
}
use of org.bukkit.boss.BossBar in project InfernalMobs by NyaaCat.
the class BossBarManager method removeMob.
public static void removeMob(Mob mob, LivingEntity mobEntity) {
Bukkit.getScheduler().runTaskAsynchronously(InfernalMobs.instance, () -> {
BossBar bossBar = bossBarMap.get(mobEntity);
if (bossBar == null)
return;
HashSet<Player> players = barPlayerMap.computeIfAbsent(bossBar, (bar) -> new HashSet<>());
if (!players.isEmpty()) {
players.forEach(player -> {
HashSet<BossBar> bossBars = playerBarMap.get(player);
bossBars.remove(bossBar);
});
}
players.clear();
Bukkit.getScheduler().runTaskLater(InfernalMobs.instance, bossBar::removeAll, 20);
bossBar.setTitle(bossBar.getTitle().concat(ConfigReader.getBossbarDeathHint()));
refreshBar(bossBar, mobEntity);
synchronized (bossBarMap) {
synchronized (barPlayerMap) {
bossBarMap.remove(mobEntity);
barPlayerMap.remove(bossBar);
}
}
});
}
Aggregations