Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chickenstyle.bar;
- import java.util.HashMap;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.boss.BarColor;
- import org.bukkit.boss.BarStyle;
- import org.bukkit.boss.BossBar;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener {
- BossBar bar;
- public void onEnable() {
- System.out.print(ChatColor.GOLD + "BossBar+ Is Working!");
- Bukkit.getPluginManager().registerEvents(this, this);
- }
- public BossBar BossBar(int intmaxhealth,int inthealth) {
- bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + "Damaged Entity's Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
- return bar;
- }
- HashMap<Player,Player> playerh = new HashMap<>();
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onDamage(EntityDamageByEntityEvent e) {
- if (e.getDamager() instanceof Player) {
- Player player = (Player) e.getDamager();
- LivingEntity entity = (LivingEntity) e.getEntity();
- double health = entity.getHealth() - e.getDamage();
- double maxhealth = entity.getMaxHealth();
- int inthealth = (int) health;
- int intmaxhealth = (int) maxhealth;
- if (playerh.containsKey(player)) {
- BossBar(intmaxhealth, inthealth).setProgress(health/maxhealth);
- } else {
- player.sendMessage("2");
- playerh.put(player, player);
- BossBar(intmaxhealth, inthealth).setProgress(health/maxhealth);
- BossBar(intmaxhealth, inthealth).addPlayer(player);
- }
- Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
- playerh.clear();
- BossBar(intmaxhealth, inthealth).removePlayer(player);
- }, 40);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment