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);
- }
- HashMap<Player,Player> playerh = new HashMap<>();
- HashMap<Player,Player> playera = new HashMap<>();
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onDamage(EntityDamageByEntityEvent e) {
- if (e.getDamager() instanceof Player) {
- LivingEntity entity = (LivingEntity) e.getEntity();
- Player player = (Player) e.getDamager();
- double health = entity.getHealth() - e.getDamage();
- double maxhealth = entity.getMaxHealth();
- int inthealth = (int) health;
- int intmaxhealth = (int) maxhealth;
- if (health > 0) {
- if (!playerh.containsKey(player)) {
- if (entity.getCustomName() == null) {
- bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + entity.getType().toString().toLowerCase() + "'s Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
- } else {
- bar = Bukkit.createBossBar(ChatColor.LIGHT_PURPLE + entity.getCustomName() + "'s Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥" , BarColor.RED, BarStyle.SOLID);
- }
- playerh.put(player, player);
- if (health/maxhealth <= 1.0 && health/maxhealth >0.5) {
- bar.setColor(BarColor.GREEN);
- } else if (health/maxhealth <= 0.5 && health/maxhealth >0.3) {
- bar.setColor(BarColor.YELLOW);
- } else if (health/maxhealth <= 0.3 && health/maxhealth >0.0) {
- bar.setColor(BarColor.RED);
- }
- bar.setProgress(health/maxhealth);
- bar.addPlayer(player);
- } else {
- bar.setProgress(health/maxhealth);
- if (entity.getCustomName() == null ) {
- bar.setTitle(ChatColor.LIGHT_PURPLE + entity.getType().toString().toLowerCase() + "'s Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥");
- if (health/maxhealth <= 1.0 && health/maxhealth >0.5) {
- bar.setColor(BarColor.GREEN);
- } else if (health/maxhealth <= 0.5 && health/maxhealth >0.3) {
- bar.setColor(BarColor.YELLOW);
- } else if (health/maxhealth <= 0.3 && health/maxhealth >0.0) {
- bar.setColor(BarColor.RED);
- }
- } else {
- bar.setTitle(ChatColor.LIGHT_PURPLE + entity.getCustomName() + "'s Hp: " + ChatColor.RED + inthealth + "♥ / " + intmaxhealth + "♥");
- if (health/maxhealth <= 1.0 && health/maxhealth >0.5) {
- bar.setColor(BarColor.GREEN);
- } else if (health/maxhealth <= 0.5 && health/maxhealth >0.3) {
- bar.setColor(BarColor.YELLOW);
- } else if (health/maxhealth <= 0.3 && health/maxhealth >0.0) {
- bar.setColor(BarColor.RED);
- }
- }
- }
- Bukkit.getScheduler().cancelTasks(this);
- Bukkit.getScheduler().scheduleAsyncDelayedTask(this,() -> {
- bar.removePlayer(player);
- if (playerh.containsKey(player)) {
- playerh.clear();
- }
- }, 40);
- } else {
- bar.setProgress(0.0);
- playerh.clear();
- if (entity.getCustomName() == null ) {
- bar.setTitle(ChatColor.LIGHT_PURPLE + entity.getType().toString().toLowerCase() + "'s Hp: " + ChatColor.RED + 0 + "♥ / " + intmaxhealth + "♥");
- } else {
- bar.setTitle(ChatColor.LIGHT_PURPLE + entity.getCustomName() + "'s Hp: " + ChatColor.RED + 0 + "♥ / " + intmaxhealth + "♥");
- }
- bar.removePlayer(player);
- if (playerh.containsKey(player)) {
- playerh.clear();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment