测试版
This commit is contained in:
commit
a27e5f3a26
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
|
@ -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/
|
42
pom.xml
Normal file
42
pom.xml
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.example</groupId>
|
||||||
|
<artifactId>DemonShowHealth</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>public-rpg</id>
|
||||||
|
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.12.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.Demon.DemonPlugin</groupId>
|
||||||
|
<artifactId>DemonAPI</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hamster3.cdapi</groupId>
|
||||||
|
<artifactId>CDTimeAPI</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
92
src/main/java/me/Demon/DemonShowHealth/HpBars.java
Normal file
92
src/main/java/me/Demon/DemonShowHealth/HpBars.java
Normal file
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
5
src/main/resources/plugin.yml
Normal file
5
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
name: DemonShowHealth
|
||||||
|
main: me.Demon.DemonShowHealth.HpBars
|
||||||
|
version: 1.0
|
||||||
|
commands:
|
||||||
|
hheal:
|
Loading…
Reference in New Issue
Block a user