Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HashMap<Player,Player> playerh = new HashMap<>();
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onDamage(EntityDamageByEntityEvent e) {
- if (e.getDamager() instanceof Player) {
- Player player = (Player) e.getDamager();
- LivingEntity entity = (LivingEntity) e.getEntity();
- double health = entity.getHealth() - e.getDamage();
- double maxhealth = entity.getMaxHealth();
- int inthealth = (int) health;
- int intmaxhealth = (int) maxhealth;
- BossBar bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + "Damaged Entity's Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
- if (playerh.isEmpty()) {
- player.sendMessage("1");
- bar.setProgress(health/maxhealth);
- bar.addPlayer(player);
- playerh.put(player, player);
- } else {
- playerh.clear();
- bar.setProgress(health/maxhealth);
- }
- Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
- bar.removePlayer(player);
- if (!playerh.isEmpty()) {
- playerh.clear();
- }
- }, 40);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement