danik159

Untitled

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