Advertisement
danik159

Untitled

Aug 10th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. HashMap<Player,Player> playerh = new HashMap<>();
  2. @SuppressWarnings("deprecation")
  3. @EventHandler
  4. public void onDamage(EntityDamageByEntityEvent e) {
  5. if (e.getDamager() instanceof Player) {
  6. Player player = (Player) e.getDamager();
  7. LivingEntity entity = (LivingEntity) e.getEntity();
  8. double health = entity.getHealth() - e.getDamage();
  9. double maxhealth = entity.getMaxHealth();
  10. int inthealth = (int) health;
  11. int intmaxhealth = (int) maxhealth;
  12. BossBar bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + "Damaged Entity's Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
  13. if (playerh.isEmpty()) {
  14. player.sendMessage("1");
  15. bar.setProgress(health/maxhealth);
  16. bar.addPlayer(player);
  17. playerh.put(player, player);
  18. } else {
  19. playerh.clear();
  20. bar.setProgress(health/maxhealth);
  21. }
  22.  
  23. Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
  24. bar.removePlayer(player);
  25. if (!playerh.isEmpty()) {
  26. playerh.clear();
  27. }
  28. }, 40);
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement