Search in sources :

Example 16 with BossBar

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();
        }
    }
}
Also used : BossBar(org.bukkit.boss.BossBar)

Example 17 with BossBar

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;
}
Also used : BossBar(org.bukkit.boss.BossBar)

Example 18 with 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);
            });
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) BossBar(org.bukkit.boss.BossBar) Vector(org.bukkit.util.Vector)

Example 19 with BossBar

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);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) BiMap(com.google.common.collect.BiMap) Attribute(org.bukkit.attribute.Attribute) java.util(java.util) Entity(org.bukkit.entity.Entity) Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) Player(org.bukkit.entity.Player) LivingEntity(org.bukkit.entity.LivingEntity) Collectors(java.util.stream.Collectors) Vector(org.bukkit.util.Vector) HashBiMap(com.google.common.collect.HashBiMap) BarColor(org.bukkit.boss.BarColor) BossBar(org.bukkit.boss.BossBar) BarStyle(org.bukkit.boss.BarStyle) Bukkit(org.bukkit.Bukkit) Player(org.bukkit.entity.Player) BossBar(org.bukkit.boss.BossBar)

Example 20 with BossBar

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);
            }
        }
    });
}
Also used : Player(org.bukkit.entity.Player) BossBar(org.bukkit.boss.BossBar)

Aggregations

BossBar (org.bukkit.boss.BossBar)33 UUID (java.util.UUID)6 Location (org.bukkit.Location)5 BarFlag (org.bukkit.boss.BarFlag)5 Player (org.bukkit.entity.Player)5 Vector (org.bukkit.util.Vector)5 ArmorStand (org.bukkit.entity.ArmorStand)4 Seat (me.legofreak107.vehicles.objects.Seat)3 Vehicle (me.legofreak107.vehicles.objects.Vehicle)3 CommandException (net.citizensnpcs.api.command.exception.CommandException)3 EntityArmorStand (net.minecraft.server.v1_12_R1.EntityArmorStand)3 PacketPlayInSteerVehicle (net.minecraft.server.v1_12_R1.PacketPlayInSteerVehicle)3 BarColor (org.bukkit.boss.BarColor)3 BarStyle (org.bukkit.boss.BarStyle)3 CraftArmorStand (org.bukkit.craftbukkit.v1_12_R1.entity.CraftArmorStand)3 PlayerInventory (org.bukkit.inventory.PlayerInventory)3 java.util (java.util)2 LivingEntity (org.bukkit.entity.LivingEntity)2 EulerAngle (org.bukkit.util.EulerAngle)2 Denizen (com.denizenscript.denizen.Denizen)1