danik159

Untitled

Sep 30th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 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. HashMap<Player,Player> playera = new HashMap<>();
  28. @SuppressWarnings("deprecation")
  29. @EventHandler
  30. public void onDamage(EntityDamageByEntityEvent e) {
  31. if (e.getDamager() instanceof Player) {
  32. LivingEntity entity = (LivingEntity) e.getEntity();
  33. Player player = (Player) e.getDamager();
  34. double health = entity.getHealth() - e.getDamage();
  35. double maxhealth = entity.getMaxHealth();
  36. int inthealth = (int) health;
  37. int intmaxhealth = (int) maxhealth;
  38. if (health > 0) {
  39. if (!playerh.containsKey(player)) {
  40. if (entity.getCustomName() == null) {
  41. bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + entity.getType().toString().toLowerCase() + "'s Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
  42. } else {
  43. bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + entity.getCustomName() + "'s Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
  44. }
  45. playerh.put(player, player);
  46. if (health/maxhealth <= 1.0 && health/maxhealth >0.5) {
  47. bar.setColor(BarColor.GREEN);
  48. } else if (health/maxhealth <= 0.5 && health/maxhealth >0.3) {
  49. bar.setColor(BarColor.YELLOW);
  50. } else if (health/maxhealth <= 0.3 && health/maxhealth >0.0) {
  51. bar.setColor(BarColor.RED);
  52. }
  53. bar.setProgress(health/maxhealth);
  54. bar.addPlayer(player);
  55. } else {
  56. bar.setProgress(health/maxhealth);
  57. if (entity.getCustomName() == null ) {
  58. bar.setTitle(ChatColor.LIGHT_PURPLE + entity.getType().toString().toLowerCase() + "'s Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥");
  59. if (health/maxhealth <= 1.0 && health/maxhealth >0.5) {
  60. bar.setColor(BarColor.GREEN);
  61. } else if (health/maxhealth <= 0.5 && health/maxhealth >0.3) {
  62. bar.setColor(BarColor.YELLOW);
  63. } else if (health/maxhealth <= 0.3 && health/maxhealth >0.0) {
  64. bar.setColor(BarColor.RED);
  65. }
  66. } else {
  67. bar.setTitle(ChatColor.LIGHT_PURPLE + entity.getCustomName() + "'s Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥");
  68. if (health/maxhealth <= 1.0 && health/maxhealth >0.5) {
  69. bar.setColor(BarColor.GREEN);
  70. } else if (health/maxhealth <= 0.5 && health/maxhealth >0.3) {
  71. bar.setColor(BarColor.YELLOW);
  72. } else if (health/maxhealth <= 0.3 && health/maxhealth >0.0) {
  73. bar.setColor(BarColor.RED);
  74. }
  75. }
  76. }
  77. Bukkit.getScheduler().cancelTasks(this);
  78. Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
  79. bar.removePlayer(player);
  80. if (playerh.containsKey(player)) {
  81. playerh.clear();
  82. }
  83. }, 40);
  84. } else {
  85. bar.setProgress(0.0);
  86. playerh.clear();
  87. if (entity.getCustomName() == null ) {
  88. bar.setTitle(ChatColor.LIGHT_PURPLE + entity.getType().toString().toLowerCase() + "'s Hp: " + ChatColor.RED + 0 + "♥ / " + intmaxhealth + "♥");
  89. } else {
  90. bar.setTitle(ChatColor.LIGHT_PURPLE + entity.getCustomName() + "'s Hp: " + ChatColor.RED + 0 + "♥ / " + intmaxhealth + "♥");
  91. }
  92. bar.removePlayer(player);
  93. if (playerh.containsKey(player)) {
  94. playerh.clear();
  95. }
  96.  
  97. }
  98.  
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment