danik159

Untitled

Aug 11th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 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. Player player = (Player) e.getDamager();
  32. LivingEntity entity = (LivingEntity) e.getEntity();
  33. double health = entity.getHealth() - e.getDamage();
  34. double maxhealth = entity.getMaxHealth();
  35. int inthealth = (int) health;
  36. int intmaxhealth = (int) maxhealth;
  37. BossBar bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + "Damaged Entity's Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
  38. if (health/maxhealth > 0) {
  39. if (playerh.containsKey(player)) {
  40. player.sendMessage("1");
  41. bar.removePlayer(player);
  42. bar.setProgress(health/maxhealth);
  43. bar.addPlayer(player);
  44. } else {
  45. player.sendMessage("2");
  46. playerh.put(player, player);
  47. bar.setProgress(health/maxhealth);
  48. bar.addPlayer(player);
  49. }
  50. } else {
  51. bar.setProgress(0.0);
  52. }
  53. if (entity.isDead()) {
  54. playerh.clear();
  55. }
  56. Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
  57. bar.removePlayer(player);
  58. if (playerh.containsKey(player)) {
  59. playerh.clear();
  60. }
  61. }, 40);
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment