danik159

Untitled

Aug 11th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 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. public void Prog(int intmaxhealth,int inthealth) {
  32. bar.setProgress(inthealth/intmaxhealth);
  33. }
  34. public void rem (Player player) {
  35. bar.removePlayer(player);
  36. }
  37.  
  38. HashMap<Player,Player> playerh = new HashMap<>();
  39. @SuppressWarnings("deprecation")
  40. @EventHandler
  41. public void onDamage(EntityDamageByEntityEvent e) {
  42. if (e.getDamager() instanceof Player) {
  43. Player player = (Player) e.getDamager();
  44. LivingEntity entity = (LivingEntity) e.getEntity();
  45. double health = entity.getHealth() - e.getDamage();
  46. double maxhealth = entity.getMaxHealth();
  47. int inthealth = (int) health;
  48. int intmaxhealth = (int) maxhealth;
  49. if (playerh.containsKey(player)) {
  50. player.sendMessage("1");
  51. Prog(intmaxhealth, inthealth);
  52. } else {
  53. player.sendMessage("2");
  54. playerh.put(player, player);
  55. Prog(intmaxhealth, inthealth);
  56. BossBar(intmaxhealth, inthealth).addPlayer(player);
  57. }
  58.  
  59. Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
  60. playerh.clear();
  61. rem(player);
  62. }, 40);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment