commit a27e5f3a2615284ba0bcc845be7cd13c55039110 Author: tianyu <32282861@qq.com> Date: Sat Jul 27 23:46:35 2024 +0800 测试版 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c037f46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store +/.idea/ +/out/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..90b97f9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + org.example + DemonShowHealth + 1.0-SNAPSHOT + + + 8 + 8 + UTF-8 + + + + + public-rpg + https://repo.aurora-pixels.com/repository/public-rpg/ + + + + + + org.spigotmc + spigot-api + 1.12.2 + + + me.Demon.DemonPlugin + DemonAPI + 1.2.0 + + + cn.hamster3.cdapi + CDTimeAPI + 1.0 + + + + \ No newline at end of file diff --git a/src/main/java/me/Demon/DemonShowHealth/HpBars.java b/src/main/java/me/Demon/DemonShowHealth/HpBars.java new file mode 100644 index 0000000..96442bf --- /dev/null +++ b/src/main/java/me/Demon/DemonShowHealth/HpBars.java @@ -0,0 +1,92 @@ +package me.Demon.DemonShowHealth; + +import cn.hamster3.cdapi.CDTimeAPI; +import me.Demon.DemonPlugin.DemonAPI; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import java.text.DecimalFormat; + +public class HpBars extends JavaPlugin implements Listener { + + private final int time = 2; + + public void onEnable() { + getServer().getPluginManager().registerEvents(this, (Plugin) this); + } + + @EventHandler + public void onjoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + p.setHealthScale(40); + } + + public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) { + if (Command.equalsIgnoreCase("hheal") && sender.isOp()) { + Player p = (Player) sender; + if (CDTimeAPI.getCD(p.getUniqueId(), "hheal_Cmd") >= 0) { + return true; + } + p.setHealth(p.getMaxHealth()); + p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 0.5F, 1.5F); + p.sendMessage("§6已治疗."); + CDTimeAPI.setPlayerCD(p.getUniqueId(), "hheal_Cmd", 1000 * 5); + } + return false; + } + + + @EventHandler + public void onEntityDamage(EntityDamageByEntityEvent e) { + if (e.getDamager() instanceof Player && e.getEntity() instanceof LivingEntity) { + boolean isCitizensNPC = e.getEntity().hasMetadata("NPC"); + if (isCitizensNPC) { + return; + } + if (e.getEntity().getCustomName() != null) { + String MobsName = e.getEntity().getCustomName(); + if (e.getDamager() instanceof Player) { + Player p = (Player) e.getDamager(); + double damage = e.getDamage(); + String message = getHealthBar((LivingEntity) e.getEntity()); + DemonAPI.sendActionBar(p, message); + DemonAPI.sendTitle(p, 5, 20, 5, "", "§c§l造成伤害: §a§l+" + new DecimalFormat("0.00").format(damage)); + } + if (e.getDamager() instanceof Projectile) { + Projectile projectile = (Projectile) e.getDamager(); + if (projectile.getShooter() instanceof Player) { + Player p = (Player) projectile.getShooter(); + double damage = e.getDamage(); + String message = getHealthBar((LivingEntity) e.getEntity()); + DemonAPI.sendActionBar(p, message); + DemonAPI.sendTitle(p, 5, 20, 5, "", "§c§l造成伤害: §a§l+" + new DecimalFormat("0.00").format(damage)); + } + } + } + } + } + + private String getHealthBar(LivingEntity entity) { + String heath = String.valueOf(getHealth(entity)); + String max_health = String.valueOf(Math.ceil(entity.getMaxHealth())); + if (getHealth(entity) >= 1000000) { + heath = (Math.round((getHealth(entity) * 0.001) * 100.0) / 100.0) + "k"; + max_health = (Math.round(((entity.getMaxHealth()) * 0.001) * 100.0) / 100.0) + "k"; + } + return "§8§l[§c§l!§8§l] §7目标生物: " + entity.getName() + " §7血量: §c§l" + heath + "§7/§c§l" + max_health + "♥"; + } + + private int getHealth(LivingEntity entity) { + return (int) Math.ceil(entity.getHealth()); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..62e3070 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: DemonShowHealth +main: me.Demon.DemonShowHealth.HpBars +version: 1.0 +commands: + hheal: \ No newline at end of file