danik159

Untitled

Aug 12th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. package com.chickenstyle.bar;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.boss.BarColor;
  8. import org.bukkit.boss.BarStyle;
  9. import org.bukkit.boss.BossBar;
  10. import org.bukkit.entity.LivingEntity;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17.  
  18. public class Main extends JavaPlugin implements Listener {
  19.  
  20. BossBar bar;
  21. public void onEnable() {
  22. System.out.print(ChatColor.GOLD + "BossBar+ Is Working!");
  23. Bukkit.getPluginManager().registerEvents(this, this);
  24. }
  25.  
  26. HashMap<Player,Player> playerh = new HashMap<>();
  27. @SuppressWarnings("deprecation")
  28. @EventHandler
  29. public void onDamage(EntityDamageByEntityEvent e) {
  30. if (e.getDamager() instanceof Player) {
  31. LivingEntity entity = (LivingEntity) e.getEntity();
  32. Player player = (Player) e.getDamager();
  33. double health = entity.getHealth() - e.getDamage();
  34. double maxhealth = entity.getMaxHealth();
  35. int inthealth = (int) health;
  36. int intmaxhealth = (int) maxhealth;
  37. if (health > 0) {
  38. if (!playerh.containsKey(player)) {;
  39. bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + "Damaged Entity's Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
  40. playerh.put(player, player);
  41. bar.setProgress(health/maxhealth);
  42. bar.addPlayer(player);
  43. } else {
  44. bar.setProgress(health/maxhealth);
  45. bar.setTitle(ChatColor.LIGHT_PURPLE + "Damaged Entity's Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥");
  46. }
  47. Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
  48. bar.removePlayer(player);
  49. if (playerh.containsKey(player)) {
  50. playerh.clear();
  51. }
  52. }, 40);
  53. } else {
  54. bar.setProgress(0.0);
  55. playerh.clear();
  56. Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
  57. bar.removePlayer(player);
  58. if (playerh.containsKey(player)) {
  59. playerh.clear();
  60. }
  61. }, 60);
  62.  
  63. }
  64.  
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment