From 6eb47724365a26aedda50bb317ae1affcff4f2ca Mon Sep 17 00:00:00 2001 From: yaohunya <31456652@qq.com> Date: Sat, 13 Jul 2024 22:47:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=96=E7=95=8CBOSS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/io/yaohun/worldbosshurt/Main.java | 29 ++++- .../worldbosshurt/command/BossSpawnerCmd.java | 9 +- .../yaohun/worldbosshurt/data/RewardData.java | 90 ++++++++++++++++ .../event/WorldBossDeathEvent.java | 30 ++++++ .../worldbosshurt/listener/BossArmor.java | 101 ++++++++++++++++++ .../BossDamageByPlayer.java} | 10 +- .../listener/BossKillsDeath.java | 6 ++ .../worldbosshurt/listener/BossSpawnLogs.java | 21 ++++ .../worldbosshurt/listener/SpawnPut.java | 36 ------- .../worldbosshurt/mangage/BossManage.java | 11 ++ .../worldbosshurt/mangage/RewardManage.java | 23 ++++ src/main/resources/plugin.yml | 1 + 12 files changed, 314 insertions(+), 53 deletions(-) create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/data/RewardData.java create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossDeathEvent.java create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/listener/BossArmor.java rename src/main/java/com/io/yaohun/worldbosshurt/{mangage/DamageManage.java => listener/BossDamageByPlayer.java} (92%) create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/listener/BossKillsDeath.java create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/listener/BossSpawnLogs.java delete mode 100644 src/main/java/com/io/yaohun/worldbosshurt/listener/SpawnPut.java create mode 100644 src/main/java/com/io/yaohun/worldbosshurt/mangage/RewardManage.java diff --git a/src/main/java/com/io/yaohun/worldbosshurt/Main.java b/src/main/java/com/io/yaohun/worldbosshurt/Main.java index e00d50b..906ef59 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/Main.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/Main.java @@ -1,7 +1,13 @@ package com.io.yaohun.worldbosshurt; -import com.io.yaohun.worldbosshurt.listener.SpawnPut; +import com.io.yaohun.worldbosshurt.listener.BossArmor; +import com.io.yaohun.worldbosshurt.listener.BossDamageByPlayer; +import com.io.yaohun.worldbosshurt.listener.BossKillsDeath; +import com.io.yaohun.worldbosshurt.listener.BossSpawnLogs; import com.io.yaohun.worldbosshurt.mangage.BossManage; +import com.io.yaohun.worldbosshurt.mangage.RewardManage; +import me.Demon.DemonPlugin.DemonAPI; +import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.YamlConfiguration; @@ -13,18 +19,33 @@ public class Main extends JavaPlugin { public static Main plugin; public static BossManage bossManage; + public static RewardManage rewardManage; @Override public void onEnable() { plugin = this; - File Datafile = new File("plugins/WorldBossHurt", "MobData.yml"); - bossManage = new BossManage(YamlConfiguration.loadConfiguration(Datafile)); - getServer().getPluginManager().registerEvents(new SpawnPut(),this); + reloadMobDataYml(); + getServer().getPluginManager().registerEvents(new BossSpawnLogs(),this); + getServer().getPluginManager().registerEvents(new BossArmor(),this); + getServer().getPluginManager().registerEvents(new BossDamageByPlayer(),this); + getServer().getPluginManager().registerEvents(new BossKillsDeath(),this); + Bukkit.getConsoleSender().sendMessage("§b[BossHurt] §f插件成功载入Server!"); + Bukkit.getConsoleSender().sendMessage("§b[BossHurt] §f妖魂QQ:1763917516"); } + public void reloadMobDataYml(){ + File Datafile = new File("plugins/WorldBossHurt", "MobData.yml"); + bossManage = new BossManage(YamlConfiguration.loadConfiguration(Datafile)); + rewardManage = new RewardManage(YamlConfiguration.loadConfiguration(Datafile)); + } @Override public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) { + if(Command.equalsIgnoreCase("bossreload")){ + reloadMobDataYml(); + DemonAPI.sendMessage(sender,"配置文件已重载."); + return true; + } if(Command.equalsIgnoreCase("bosspz")){ } 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 8d14e7d..1d6bf73 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/command/BossSpawnerCmd.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/command/BossSpawnerCmd.java @@ -4,7 +4,7 @@ import com.io.yaohun.worldbosshurt.Main; import com.io.yaohun.worldbosshurt.data.BossData; import com.io.yaohun.worldbosshurt.event.WorldBossSpawnEvent; import com.io.yaohun.worldbosshurt.mangage.BossManage; -import com.io.yaohun.worldbosshurt.mangage.DamageManage; +import com.io.yaohun.worldbosshurt.listener.BossDamageByPlayer; import com.io.yaohun.worldbosshurt.util.BossSpawnUtil; import com.io.yaohun.worldbosshurt.util.BossUtil; import lk.vexview.api.VexViewAPI; @@ -18,15 +18,10 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.util.StringUtil; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import static net.minecraft.server.v1_12_R1.SoundEffects.bc; -import static net.minecraft.server.v1_12_R1.SoundEffects.fa; - public class BossSpawnerCmd implements CommandExecutor , TabCompleter { @Override @@ -48,7 +43,7 @@ public class BossSpawnerCmd implements CommandExecutor , TabCompleter { Bukkit.getConsoleSender().sendMessage("[日志-世界Boss] 系统尝试多次执行召唤boss已被拦截."); return true; } - DamageManage.damageMap.clear(); // 清理之前的伤害数据缓存 + BossDamageByPlayer.damageMap.clear(); // 清理之前的伤害数据缓存 String stats_type = BossSpawnUtil.getTheCurrentServerPlayerStatus(); if(stats_type.equalsIgnoreCase("NoPlayer")){ diff --git a/src/main/java/com/io/yaohun/worldbosshurt/data/RewardData.java b/src/main/java/com/io/yaohun/worldbosshurt/data/RewardData.java new file mode 100644 index 0000000..d4836ee --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/data/RewardData.java @@ -0,0 +1,90 @@ +package com.io.yaohun.worldbosshurt.data; + +import me.Demon.DemonPlugin.DemonAPI; +import org.bukkit.configuration.file.FileConfiguration; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +public class RewardData { + + private String rewardKey; + + private List killsList; + + private List damageList; + + private HashMap> topList; + + public RewardData(String rewardKey,FileConfiguration yml){ + this.rewardKey = rewardKey; + String str = "RewardGroup."+rewardKey+"."; + this.killsList = new ArrayList<>(); + if(yml.getString(str+"kills") != null){ + List stringList = yml.getStringList(str+"kills"); + for (String s : stringList){ + if(s.contains(";")){ + this.killsList.add(s); + }else { + this.killsList.add(s); + this.killsList.add(s); + this.killsList.add(s); + } + } + } + this.damageList = new ArrayList<>(); + if(yml.getString(str+"damage") != null){ + this.damageList = yml.getStringList(str+"damage"); + } + HashMap> hashMap = new HashMap<>(); + if(yml.getConfigurationSection(str+"top") != null) { + for (String top : yml.getConfigurationSection(str + "top").getKeys(false)) { + List stringList = yml.getStringList(str + "top." + top); + hashMap.put(top, stringList); + } + } + this.topList = hashMap; + } + + public String getRewardKey() { + if(rewardKey != null) { + return rewardKey; + } + return "无奖励"; + } + + // 获取最终击杀命令 + public List getKillsCmdList(){ + int suijishu = (DemonAPI.getRandomInt(killsList.size(), 1) - 1); + String cmdsp = killsList.get(suijishu); + List commands = Collections.singletonList(cmdsp); + if(cmdsp.contains(";")) { + commands = DemonAPI.StringConvertStringList(cmdsp, ";"); + } + /*for (String s : commands){ + Bukkit.getConsoleSender().sendMessage("#Text = "+s); + }*/ + return commands; + } + + // 获取排名奖励 + public List getTopCmdList(int top){ + String topKey = String.valueOf(top); + if(this.topList.get(topKey) != null) { + return this.topList.get(topKey); + } + return new ArrayList<>(); + } + + // 获取排名奖励数量 + public int getTopCmdSize(){ + return this.topList.size(); + } + + // 获取累积伤害奖励 + public List getDamageCmdList(){ + return this.damageList; + } +} diff --git a/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossDeathEvent.java b/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossDeathEvent.java new file mode 100644 index 0000000..47a2826 --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossDeathEvent.java @@ -0,0 +1,30 @@ +package com.io.yaohun.worldbosshurt.event; + +import com.io.yaohun.worldbosshurt.data.BossData; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class WorldBossDeathEvent extends Event { + + private static HandlerList handlers = new HandlerList(); + private BossData bossData; + + @Override + public HandlerList getHandlers() { + return handlers; + } + public static HandlerList getHandlerList() { + return handlers; + } + public WorldBossDeathEvent(BossData bossData) { + this.bossData = bossData; + } + + public String getBossKey(){ + return bossData.getBossKey(); + } + + public String getMobName() { + return bossData.getBossName(); + } +} diff --git a/src/main/java/com/io/yaohun/worldbosshurt/listener/BossArmor.java b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossArmor.java new file mode 100644 index 0000000..2e0c2b1 --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossArmor.java @@ -0,0 +1,101 @@ +package com.io.yaohun.worldbosshurt.listener; + +import com.io.yaohun.worldbosshurt.Main; +import com.io.yaohun.worldbosshurt.data.BossData; +import com.io.yaohun.worldbosshurt.mangage.BossManage; +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 java.util.HashMap; +import java.util.UUID; + +public class BossArmor implements Listener { + + private HashMap bossHurtMap = new HashMap<>(); + + private double getBossHurtDamage(UUID uuid){ + if(bossHurtMap.get(uuid) == null){ + return 0.0; + } + return bossHurtMap.get(uuid); + } + + private void addPlayerDamage(UUID uuid, double damage){ + if(bossHurtMap.get(uuid) == null){ + bossHurtMap.put(uuid,damage); + return; + } + double newDamage = damage + bossHurtMap.get(uuid); + bossHurtMap.put(uuid,newDamage); + } + + public static boolean butt_hurt = false; + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void EntityDamageByEntity(EntityDamageByEntityEvent e) { + if(!(e.getEntity() instanceof Player)) { + Entity entity = e.getEntity(); // 获取受伤生物 + String customName = entity.getCustomName(); // 获取生物自定义名 + BossManage bossManage = Main.bossManage; // 获取boss管理 + if (customName != null && bossManage.isCustomNameContains(customName)) { + BossData bossData = bossManage.getNameToData(customName); + DamageEvent(e, bossData); + } + } + } + + public void DamageEvent(EntityDamageByEntityEvent e, BossData dataAPI){ + double damage = e.getDamage(); + if(butt_hurt){ + int start_armor_boss = dataAPI.getBossArmor(); + int damage_limit_1 = (int) (start_armor_boss * 0.1); // 200W + int damage_limit_2 = (int) (start_armor_boss * 0.01); // 20W + int damage_limit_3 = (int) (start_armor_boss * 0.001); // 2W + if(damage >= damage_limit_1){ + int rand_damage = DemonAPI.getRandomInt((damage_limit_2*5), damage_limit_2); + e.setDamage(rand_damage); + }else if(damage >= damage_limit_2){ + int rand_damage = DemonAPI.getRandomInt(damage_limit_2*3, damage_limit_3); + e.setDamage(rand_damage); + } + return; + } + if(damage <= dataAPI.getBossArmor()) { + Entity entity = e.getEntity(); + UUID uuid = entity.getUniqueId(); + if (bossHurtMap.get(entity.getUniqueId()) != null) { + addPlayerDamage(uuid,damage); + double boss_armonr = getBossHurtDamage(uuid); + if (boss_armonr >= dataAPI.getBossArmor()) { + StartBossArmor("累伤触发"); + } + } else { + addPlayerDamage(uuid,damage); + } + } else { + StartBossArmor("瞬伤触发"); + e.setCancelled(true); + } + } + + public void StartBossArmor(String type){ + butt_hurt = true; + int s = DemonAPI.getRandomInt(25, 10); + Bukkit.getConsoleSender().sendMessage("开启保护 开启保护 开启保护 开启保护#"+s+"s || "+type); + Bukkit.getScheduler().runTaskLater(Main.plugin, (Runnable) new Runnable() { + @Override + public void run() { + butt_hurt = false; + bossHurtMap.clear(); + Bukkit.getConsoleSender().sendMessage("关闭保护 关闭保护 关闭保护 关闭保护 "); + } + }, (long) 20*s); + } +} diff --git a/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossDamageByPlayer.java similarity index 92% rename from src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java rename to src/main/java/com/io/yaohun/worldbosshurt/listener/BossDamageByPlayer.java index 99cc742..00d16be 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossDamageByPlayer.java @@ -1,7 +1,6 @@ -package com.io.yaohun.worldbosshurt.mangage; +package com.io.yaohun.worldbosshurt.listener; 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; @@ -11,13 +10,12 @@ 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 { +public class BossDamageByPlayer implements Listener { public static HashMap damageMap = new HashMap<>(); @@ -46,7 +44,7 @@ public class DamageManage implements Listener { return; } UUID Mob_uuid = e.getEntity().getUniqueId(); - if(!SpawnPut.WhiteBossList.contains(Mob_uuid)){ + if(!BossSpawnLogs.WhiteBossList.contains(Mob_uuid)){ e.getEntity().remove(); Bukkit.broadcastMessage("§6[§4公告§6] §a"+customName+"§a被卷入了异次元时空."); return; @@ -76,7 +74,7 @@ public class DamageManage implements Listener { return; } UUID Mob_uuid = e.getEntity().getUniqueId(); - if (!SpawnPut.WhiteBossList.contains(Mob_uuid)) { + if (!BossSpawnLogs.WhiteBossList.contains(Mob_uuid)) { e.getEntity().remove(); Bukkit.broadcastMessage("§6[§4公告§6] §a" + customName + "§a被卷入了异次元时空."); return; diff --git a/src/main/java/com/io/yaohun/worldbosshurt/listener/BossKillsDeath.java b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossKillsDeath.java new file mode 100644 index 0000000..ab04463 --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossKillsDeath.java @@ -0,0 +1,6 @@ +package com.io.yaohun.worldbosshurt.listener; + +import org.bukkit.event.Listener; + +public class BossKillsDeath implements Listener { +} diff --git a/src/main/java/com/io/yaohun/worldbosshurt/listener/BossSpawnLogs.java b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossSpawnLogs.java new file mode 100644 index 0000000..914af49 --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/listener/BossSpawnLogs.java @@ -0,0 +1,21 @@ +package com.io.yaohun.worldbosshurt.listener; + +import com.io.yaohun.worldbosshurt.event.WorldBossSpawnEvent; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.ArrayList; +import java.util.List; + +public class BossSpawnLogs implements Listener { + + public static List WhiteBossList = new ArrayList<>(); + @EventHandler + public void onSpawnBlockEvent(WorldBossSpawnEvent e) { + String customName = e.getMobName(); + WhiteBossList.add(customName); + Bukkit.getConsoleSender().sendMessage("[日志-UUID导入] Boss "+customName+" §r已被录入List"); + } + +} diff --git a/src/main/java/com/io/yaohun/worldbosshurt/listener/SpawnPut.java b/src/main/java/com/io/yaohun/worldbosshurt/listener/SpawnPut.java deleted file mode 100644 index a1ab677..0000000 --- a/src/main/java/com/io/yaohun/worldbosshurt/listener/SpawnPut.java +++ /dev/null @@ -1,36 +0,0 @@ -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 index c8305b2..fc6f521 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java @@ -34,6 +34,17 @@ public class BossManage { return bossDataMap.get(bossKey); } + public BossData getNameToData(String customName) { + for (String bossKey : bossDataMap.keySet()){ + BossData data = bossDataMap.get(bossKey); + String bossName = data.getBossName(); + if(customName.contains(bossName)){ + return data; + } + } + return null; + } + public boolean isBossSurvive() { return bossSurvive; } diff --git a/src/main/java/com/io/yaohun/worldbosshurt/mangage/RewardManage.java b/src/main/java/com/io/yaohun/worldbosshurt/mangage/RewardManage.java new file mode 100644 index 0000000..1317737 --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/mangage/RewardManage.java @@ -0,0 +1,23 @@ +package com.io.yaohun.worldbosshurt.mangage; + +import com.io.yaohun.worldbosshurt.data.BossData; +import com.io.yaohun.worldbosshurt.data.RewardData; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class RewardManage { + + private final HashMap rewardDataMap = new HashMap<>(); + public RewardManage(FileConfiguration yml) { + if(yml.getConfigurationSection("RewardGroup") != null) { + for (String rewardKey : yml.getConfigurationSection("RewardGroup").getKeys(false)){ + rewardDataMap.put(rewardKey,new RewardData(rewardKey,yml)); + } + } + Bukkit.getConsoleSender().sendMessage("§b[BossHurt] §f已导入奖励方案: §a" + rewardDataMap.size() + "个"); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7e9711a..0f7c27f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,4 +3,5 @@ main: com.io.yaohun.worldbosshurt.main version: 1.0.0 commands: bosspz: + bossreload: bossspawner: \ No newline at end of file