From 8b7880a1b05d3bff869822e25eff8ee27c9f3498 Mon Sep 17 00:00:00 2001
From: yaohunya <31456652@qq.com>
Date: Sat, 13 Jul 2024 21:39:00 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 5 +
.../com/io/yaohun/worldbosshurt/BossUtil.java | 36 -------
.../com/io/yaohun/worldbosshurt/Main.java | 19 +++-
.../worldbosshurt/command/BossSpawnerCmd.java | 2 +-
.../yaohun/worldbosshurt/data/BossData.java | 68 ++++++++++++
.../worldbosshurt/listener/SpawnPut.java | 36 +++++++
.../worldbosshurt/mangage/BossManage.java | 36 +++++++
.../worldbosshurt/mangage/DamageManage.java | 92 ++++++++++++++++
.../yaohun/worldbosshurt/util/BossStack.java | 48 +++++++++
.../yaohun/worldbosshurt/util/BossUtil.java | 101 ++++++++++++++++++
10 files changed, 405 insertions(+), 38 deletions(-)
delete mode 100644 src/main/java/com/io/yaohun/worldbosshurt/BossUtil.java
create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/data/BossData.java
create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/listener/SpawnPut.java
create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java
create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java
create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/util/BossStack.java
create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java
diff --git a/pom.xml b/pom.xml
index 933813f..a7a780d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,11 @@
DemonBank
1.4
+
+ io.lumine.xikage.mythicmobs
+ MythicMobs
+ 1.12.2
+
\ No newline at end of file
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/BossUtil.java b/src/main/java/com/io/yaohun/worldbosshurt/BossUtil.java
deleted file mode 100644
index 8351985..0000000
--- a/src/main/java/com/io/yaohun/worldbosshurt/BossUtil.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.io.yaohun.worldbosshurt;
-
-import me.Demon.DemonPlugin.DemonAPI;
-import org.bukkit.configuration.file.FileConfiguration;
-
-public class BossUtil {
-
- /*
- * 获取每月数据刷新时间
- * */
- public static String getTimeMonthly(){
- FileConfiguration yml = Main.plugin.getConfig();
- if(yml.getString("Timemonth") != null){
- return yml.getString("Timemonth");
- }
- return "2022/04";
- }
-
- /*
- * 判断本月数据是否刷新
- * */
- public static boolean isTimeMonthly(){
- FileConfiguration yml = Main.plugin.getConfig();
- if(!getTimeMonthly().equalsIgnoreCase(DemonAPI.getTime("yyyy/MM"))){
- return true;
- }
- return false;
- }
-
- /*
- * 结算上月累积击杀十万年次数排行
- * */
- public static void settlementRankingRewards(){
-
- }
-}
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/Main.java b/src/main/java/com/io/yaohun/worldbosshurt/Main.java
index a25e693..e00d50b 100644
--- a/src/main/java/com/io/yaohun/worldbosshurt/Main.java
+++ b/src/main/java/com/io/yaohun/worldbosshurt/Main.java
@@ -1,16 +1,33 @@
package com.io.yaohun.worldbosshurt;
+import com.io.yaohun.worldbosshurt.listener.SpawnPut;
+import com.io.yaohun.worldbosshurt.mangage.BossManage;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
+import java.io.File;
+
public class Main extends JavaPlugin {
public static Main plugin;
+ public static BossManage bossManage;
@Override
public void onEnable() {
plugin = this;
- getCommand("bossspawner").setExecutor(new BossSpawnerCMD());
+ File Datafile = new File("plugins/WorldBossHurt", "MobData.yml");
+ bossManage = new BossManage(YamlConfiguration.loadConfiguration(Datafile));
+ getServer().getPluginManager().registerEvents(new SpawnPut(),this);
}
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) {
+ if(Command.equalsIgnoreCase("bosspz")){
+
+ }
+ return false;
+ }
}
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/command/BossSpawnerCmd.java b/src/main/java/com/io/yaohun/worldbosshurt/command/BossSpawnerCmd.java
index b6c22d7..97125c3 100644
--- a/src/main/java/com/io/yaohun/worldbosshurt/command/BossSpawnerCmd.java
+++ b/src/main/java/com/io/yaohun/worldbosshurt/command/BossSpawnerCmd.java
@@ -1,6 +1,6 @@
package com.io.yaohun.worldbosshurt.command;
-import com.io.yaohun.worldbosshurt.BossUtil;
+import com.io.yaohun.worldbosshurt.util.BossUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/data/BossData.java b/src/main/java/com/io/yaohun/worldbosshurt/data/BossData.java
new file mode 100644
index 0000000..8fb5c28
--- /dev/null
+++ b/src/main/java/com/io/yaohun/worldbosshurt/data/BossData.java
@@ -0,0 +1,68 @@
+package com.io.yaohun.worldbosshurt.data;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.configuration.file.FileConfiguration;
+
+public class BossData {
+ private String bossKey;
+ private String bossName;
+ private int bossArmor;
+ private String killsReward;
+ private String topReward;
+ private String locString;
+ private String bc;
+ private String bc_vv;
+
+ public BossData(String bossKey,FileConfiguration yml){
+ String str = "BossData."+bossKey+".";
+ this.bossKey = bossKey;
+ this.bossName = yml.getString(str+"name").replace("&","§");
+ this.bossArmor = yml.getInt(str+"boss_armor") * 10000;
+ this.killsReward = null;
+ if(yml.getString(str+"reward_kills") != null) {
+ this.killsReward = yml.getString(str + "reward_kills");
+ }
+ this.topReward = null;
+ if(yml.getString(str+"reward_top") != null){
+ this.topReward = yml.getString(str+"reward_top");
+ }
+ this.locString = yml.getString(str+"loc");
+ this.bc = yml.getString(str+"bc").replace("&","§");
+ this.bc_vv = yml.getString(str+"bc_vv").replace("&","§");
+ }
+
+ public Location getLocation() {
+ String[] sp = this.locString.split(",");
+ String worldName = sp[0];
+ World world = Bukkit.getWorld(worldName);
+ int x = Integer.parseInt(sp[1]);
+ int y = Integer.parseInt(sp[2]);
+ int z = Integer.parseInt(sp[3]);
+ return new Location(world,x,y,z);
+ }
+
+ public String getBossKey() {return bossKey;}
+
+ public int getBossArmor() {
+ return bossArmor;
+ }
+
+ public String getKillsReward() {
+ return killsReward;
+ }
+
+ public String getTopReward() {
+ return topReward;
+ }
+
+ public String getBossName() {return bossName;}
+
+ public String getLocString() {
+ return locString;
+ }
+
+ public String getBc() {return bc;}
+ public String getBc_vv() {return bc_vv;}
+}
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/listener/SpawnPut.java b/src/main/java/com/io/yaohun/worldbosshurt/listener/SpawnPut.java
new file mode 100644
index 0000000..a1ab677
--- /dev/null
+++ b/src/main/java/com/io/yaohun/worldbosshurt/listener/SpawnPut.java
@@ -0,0 +1,36 @@
+package com.io.yaohun.worldbosshurt.listener;
+
+import com.io.yaohun.worldbosshurt.Main;
+import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobSpawnEvent;
+import io.lumine.xikage.mythicmobs.mobs.MythicMob;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Entity;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public class SpawnPut implements Listener {
+
+ public static List WhiteBossList = new ArrayList<>();
+
+ @EventHandler
+ public void onSpawnBlockEvent(MythicMobSpawnEvent e) {
+ if (e.getEntity() instanceof org.bukkit.entity.LivingEntity) {
+ // 获取怪物
+ MythicMob mythicMob = e.getMobType();
+ // 获取怪物的名字
+ String customName = mythicMob.getDisplayName().get();
+ if(Main.bossManage.isCustomNameContains(customName)) {
+ Entity entity = e.getEntity();
+ // 获取BOSS的uuid
+ UUID uuid = entity.getUniqueId();
+ // 将Boss存入 HashMap 中
+ WhiteBossList.add(uuid);
+ Bukkit.getConsoleSender().sendMessage("[日志-UUID导入] Boss "+customName+" §r已被录入List");
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java b/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java
new file mode 100644
index 0000000..abba6c9
--- /dev/null
+++ b/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java
@@ -0,0 +1,36 @@
+package com.io.yaohun.worldbosshurt.mangage;
+
+import com.io.yaohun.worldbosshurt.Main;
+import com.io.yaohun.worldbosshurt.data.BossData;
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.FileConfiguration;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class BossManage {
+
+ private List customNameList; // 获取boss名列表
+ private final HashMap bossDataMap = new HashMap<>();
+
+ public BossManage(FileConfiguration yml) {
+ for (String bossKey : yml.getConfigurationSection("BossData").getKeys(false)){
+ bossDataMap.put(bossKey,new BossData(bossKey,yml));
+ String customName = yml.getString("BossData."+bossKey+".name");
+ customNameList.add(customName);
+ }
+ Bukkit.getConsoleSender().sendMessage("§b[BossHurt] §f已导入Boss: §a" + customNameList.size() + "只");
+ }
+
+
+ public boolean isCustomNameContains(String customName){
+ for (String name : this.customNameList){
+ if(customName.contains(name)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+}
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java b/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java
new file mode 100644
index 0000000..d1e6de0
--- /dev/null
+++ b/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java
@@ -0,0 +1,92 @@
+package com.io.yaohun.worldbosshurt.mangage;
+
+import com.io.yaohun.worldbosshurt.Main;
+import com.io.yaohun.worldbosshurt.listener.SpawnPut;
+import me.Demon.DemonPlugin.DemonAPI;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.entity.Projectile;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.plugin.Plugin;
+
+import java.text.DecimalFormat;
+import java.util.HashMap;
+import java.util.UUID;
+
+public class DamageManage implements Listener {
+
+ private HashMap damageMap = new HashMap<>();
+
+ private void addPlayerDamage(Player player,double damage){
+ double newDamage = damage / 1000;
+ if(damageMap.get(player) == null){
+ damageMap.put(player,newDamage);
+ return;
+ }
+ double addDamage = newDamage + damageMap.get(player);
+ damageMap.put(player,addDamage);
+ }
+
+ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
+ public void onEntityDamageByPlayer(EntityDamageByEntityEvent e) {
+ if(e.getDamager() instanceof Player){
+ Entity entity = e.getEntity();
+ String customName = entity.getCustomName();
+ if(customName != null && Main.bossManage.isCustomNameContains(customName)){
+ Player p = (Player) e.getDamager();
+ String worldName = p.getWorld().getName();
+ if(!worldName.equalsIgnoreCase("teamDungee")) {
+ if(customName.contains("§t§e§a§m")){
+ e.getEntity().remove();
+ Bukkit.getConsoleSender().sendMessage("[世界boss-日志] 因 "+customName+" §r离开团队副本,此Boss已清理.");
+ return;
+ }
+ UUID Mob_uuid = e.getEntity().getUniqueId();
+ if(!SpawnPut.WhiteBossList.contains(Mob_uuid)){
+ e.getEntity().remove();
+ Bukkit.broadcastMessage("§6[§4公告§6] §a"+customName+"§a被卷入了异次元时空.");
+ return;
+ }
+ double damage = e.getDamage();
+ DemonAPI.sendTitle(p, 5, 20, 5, "", "§c§l造成伤害: §a§l+" + new DecimalFormat("0.00").format(damage));
+ addPlayerDamage(p,e.getDamage());
+ }
+ }
+ }
+ }
+
+ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
+ public void onEntityDamageByProjectile(EntityDamageByEntityEvent e) {
+ if (e.getDamager() instanceof Projectile) {
+ Projectile projectile = (Projectile) e.getDamager();
+ if (projectile.getShooter() instanceof Player) {
+ Entity entity = e.getEntity();
+ String customName = entity.getCustomName();
+ if (customName != null && Main.bossManage.isCustomNameContains(customName)) {
+ Player p = (Player) projectile.getShooter();
+ String worldName = p.getWorld().getName();
+ if (!worldName.equalsIgnoreCase("teamDungee")) {
+ if (customName.contains("§t§e§a§m")) {
+ e.getEntity().remove();
+ Bukkit.getConsoleSender().sendMessage("[世界boss-日志] 因 " + customName + " §r离开团队副本,此Boss已清理.");
+ return;
+ }
+ UUID Mob_uuid = e.getEntity().getUniqueId();
+ if (!SpawnPut.WhiteBossList.contains(Mob_uuid)) {
+ e.getEntity().remove();
+ Bukkit.broadcastMessage("§6[§4公告§6] §a" + customName + "§a被卷入了异次元时空.");
+ return;
+ }
+ double damage = e.getDamage();
+ DemonAPI.sendTitle(p, 5, 20, 5, "", "§c§l造成伤害: §a§l+" + new DecimalFormat("0.00").format(damage));
+ addPlayerDamage(p, e.getDamage());
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/util/BossStack.java b/src/main/java/com/io/yaohun/worldbosshurt/util/BossStack.java
new file mode 100644
index 0000000..cb75a3c
--- /dev/null
+++ b/src/main/java/com/io/yaohun/worldbosshurt/util/BossStack.java
@@ -0,0 +1,48 @@
+package com.io.yaohun.worldbosshurt.util;
+
+import com.io.yaohun.worldbosshurt.Main;
+import me.Demon.DemonPlugin.DemonAPI;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import net.minecraft.server.v1_12_R1.NBTTagCompound;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class BossStack {
+
+
+ public static NBTTagCompound getNBT(ItemStack Equipment) {
+ net.minecraft.server.v1_12_R1.ItemStack nmsEquipment = CraftItemStack.asNMSCopy(Equipment);
+ return nmsEquipment.hasTag() && nmsEquipment.getTag() != null ? nmsEquipment.getTag() : new NBTTagCompound();
+ }
+
+ public static ItemStack setNBT(ItemStack item, NBTTagCompound nbtEquipment) {
+ net.minecraft.server.v1_12_R1.ItemStack nmsEquipment = CraftItemStack.asNMSCopy(item);
+ nmsEquipment.setTag(nbtEquipment);
+ return CraftItemStack.asBukkitCopy(nmsEquipment);
+ }
+
+ /*
+ * 增加玩家每月Boss击杀数
+ * */
+ public static ItemStack BossSlashProof(String bossName){
+ ItemStack item = new ItemStack(Material.PAPER,1);
+ ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName("§c§l猎杀凭证 §f("+bossName+")");
+ List lore = new ArrayList<>();
+ lore.add("§c§l★§7通过猎杀§c十万年级§7以上");
+ lore.add("§7灵兽§a掉落§7的凭证,§a集齐多张");
+ lore.add("§7可兑换§c十万年级§7以上灵环!");
+ lore.add("§b§l✪§7务必要妥善保管此凭证!");
+ meta.setLore(lore);
+ item.setItemMeta(meta);
+ NBTTagCompound nbt = getNBT(item);
+ nbt.setString("stex","cailiao_68");
+ return setNBT(item,nbt);
+ }
+}
diff --git a/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java b/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java
new file mode 100644
index 0000000..0cea46b
--- /dev/null
+++ b/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java
@@ -0,0 +1,101 @@
+package com.io.yaohun.worldbosshurt.util;
+
+import com.io.yaohun.worldbosshurt.Main;
+import me.Demon.DemonBanK.BankAPI;
+import me.Demon.DemonPlugin.DemonAPI;
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.FileConfiguration;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class BossUtil {
+
+ /*
+ * 增加玩家每月Boss击杀数
+ * */
+ public static void addMonthlyKillBoss(String name){
+ FileConfiguration yml = Main.plugin.getConfig();
+ int killAmount = yml.getInt("MonthlyKillsTop."+name);
+ yml.set("MonthlyKillsTop."+name,(killAmount+1));
+ Main.plugin.saveConfig();
+ }
+
+ /*
+ * 获取每月数据刷新时间
+ * */
+ public static String getTimeMonthly(){
+ FileConfiguration yml = Main.plugin.getConfig();
+ if(yml.getString("Timemonth") != null){
+ return yml.getString("Timemonth");
+ }
+ return "2022/04";
+ }
+
+ /*
+ * 判断本月数据是否刷新
+ * */
+ public static boolean isTimeMonthly(){
+ FileConfiguration yml = Main.plugin.getConfig();
+ if(!getTimeMonthly().equalsIgnoreCase(DemonAPI.getTime("yyyy/MM"))){
+ return true;
+ }
+ return false;
+ }
+
+ /*
+ * 结算上月累积击杀十万年次数排行
+ * */
+ public static void settlementRankingRewards() {
+ FileConfiguration yml = Main.plugin.getConfig();
+ yml.set("TimeMonth", DemonAPI.getTime("yyyy/MM")); // 设置本月时间
+ HashMap hashMap = new HashMap<>(); // 统计击杀boss次数
+ if (yml.getConfigurationSection("MonthlyKillsTop") != null) {
+ for (String name : yml.getConfigurationSection("MonthlyKillsTop").getKeys(false)){
+ int killAmount = yml.getInt("MonthlyKillsTop."+name); // 获取击杀boss次数
+ hashMap.put(name,killAmount); // put次数
+ }
+ // yml.set("MonthlyKillsTop",null); // 清理本地数据
+ }
+ if(hashMap.size() >= 1){
+ // 为HashMap中数值进行降序排序
+ LinkedHashMap sortedMap = hashMap.entrySet()
+ .stream()
+ .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
+ .collect(Collectors.toMap(
+ Map.Entry::getKey,
+ Map.Entry::getValue,
+ (e1, e2) -> e1,
+ LinkedHashMap::new
+ ));
+ // 遍历sortedMap中的数据
+ int rank = 1;
+ for (String name : sortedMap.keySet()){
+ int kill_amount = sortedMap.get(name);
+ if(rank == 1) {
+ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx1000");
+ // BankAPI.addPoints(name,1000);
+ }else if(rank == 2){
+ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx750");
+ // BankAPI.addPoints(name,750);
+ }else if(rank == 3){
+ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx500");
+ // BankAPI.addPoints(name,500);
+ }else if(rank == 4){
+ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx250");
+ // BankAPI.addPoints(name,250);
+ }else if(rank == 5){
+ Bukkit.broadcastMessage("§6[§4灵兽猎杀排行§6] §a玩家 §e" + name + " §a上月总计猎杀: §6" + kill_amount + "只 §a获得奖励: §d§l点券§fx100");
+ // BankAPI.addPoints(name,100);
+ break;
+ }
+ rank++;
+ }
+ }
+ Main.plugin.saveConfig(); // 保存本地数据
+ Bukkit.getConsoleSender().sendMessage("[日志 - 世界BOSS] 成功结算上月玩家的Boss总击杀榜.");
+ }
+}