世界BOSS

This commit is contained in:
yaohunya 2024-07-13 22:47:00 +08:00
parent 242a88c99d
commit 6eb4772436
12 changed files with 314 additions and 53 deletions

View File

@ -1,7 +1,13 @@
package com.io.yaohun.worldbosshurt; 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.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.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -13,18 +19,33 @@ public class Main extends JavaPlugin {
public static Main plugin; public static Main plugin;
public static BossManage bossManage; public static BossManage bossManage;
public static RewardManage rewardManage;
@Override @Override
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
File Datafile = new File("plugins/WorldBossHurt", "MobData.yml"); reloadMobDataYml();
bossManage = new BossManage(YamlConfiguration.loadConfiguration(Datafile)); getServer().getPluginManager().registerEvents(new BossSpawnLogs(),this);
getServer().getPluginManager().registerEvents(new SpawnPut(),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 @Override
public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) { 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")){ if(Command.equalsIgnoreCase("bosspz")){
} }

View File

@ -4,7 +4,7 @@ import com.io.yaohun.worldbosshurt.Main;
import com.io.yaohun.worldbosshurt.data.BossData; import com.io.yaohun.worldbosshurt.data.BossData;
import com.io.yaohun.worldbosshurt.event.WorldBossSpawnEvent; import com.io.yaohun.worldbosshurt.event.WorldBossSpawnEvent;
import com.io.yaohun.worldbosshurt.mangage.BossManage; 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.BossSpawnUtil;
import com.io.yaohun.worldbosshurt.util.BossUtil; import com.io.yaohun.worldbosshurt.util.BossUtil;
import lk.vexview.api.VexViewAPI; import lk.vexview.api.VexViewAPI;
@ -18,15 +18,10 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.StringUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; 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 { public class BossSpawnerCmd implements CommandExecutor , TabCompleter {
@Override @Override
@ -48,7 +43,7 @@ public class BossSpawnerCmd implements CommandExecutor , TabCompleter {
Bukkit.getConsoleSender().sendMessage("[日志-世界Boss] 系统尝试多次执行召唤boss已被拦截."); Bukkit.getConsoleSender().sendMessage("[日志-世界Boss] 系统尝试多次执行召唤boss已被拦截.");
return true; return true;
} }
DamageManage.damageMap.clear(); // 清理之前的伤害数据缓存 BossDamageByPlayer.damageMap.clear(); // 清理之前的伤害数据缓存
String stats_type = BossSpawnUtil.getTheCurrentServerPlayerStatus(); String stats_type = BossSpawnUtil.getTheCurrentServerPlayerStatus();
if(stats_type.equalsIgnoreCase("NoPlayer")){ if(stats_type.equalsIgnoreCase("NoPlayer")){

View File

@ -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<String> killsList;
private List<String> damageList;
private HashMap<String,List<String>> 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<String> 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<String,List<String>> hashMap = new HashMap<>();
if(yml.getConfigurationSection(str+"top") != null) {
for (String top : yml.getConfigurationSection(str + "top").getKeys(false)) {
List<String> stringList = yml.getStringList(str + "top." + top);
hashMap.put(top, stringList);
}
}
this.topList = hashMap;
}
public String getRewardKey() {
if(rewardKey != null) {
return rewardKey;
}
return "无奖励";
}
// 获取最终击杀命令
public List<String> getKillsCmdList(){
int suijishu = (DemonAPI.getRandomInt(killsList.size(), 1) - 1);
String cmdsp = killsList.get(suijishu);
List<String> commands = Collections.singletonList(cmdsp);
if(cmdsp.contains(";")) {
commands = DemonAPI.StringConvertStringList(cmdsp, ";");
}
/*for (String s : commands){
Bukkit.getConsoleSender().sendMessage("#Text = "+s);
}*/
return commands;
}
// 获取排名奖励
public List<String> 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<String> getDamageCmdList(){
return this.damageList;
}
}

View File

@ -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();
}
}

View File

@ -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<UUID,Double> 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);
}
}

View File

@ -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.Main;
import com.io.yaohun.worldbosshurt.listener.SpawnPut;
import me.Demon.DemonPlugin.DemonAPI; import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -11,13 +10,12 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.plugin.Plugin;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class DamageManage implements Listener { public class BossDamageByPlayer implements Listener {
public static HashMap<Player,Double> damageMap = new HashMap<>(); public static HashMap<Player,Double> damageMap = new HashMap<>();
@ -46,7 +44,7 @@ public class DamageManage implements Listener {
return; return;
} }
UUID Mob_uuid = e.getEntity().getUniqueId(); UUID Mob_uuid = e.getEntity().getUniqueId();
if(!SpawnPut.WhiteBossList.contains(Mob_uuid)){ if(!BossSpawnLogs.WhiteBossList.contains(Mob_uuid)){
e.getEntity().remove(); e.getEntity().remove();
Bukkit.broadcastMessage("§6[§4公告§6] §a"+customName+"§a被卷入了异次元时空."); Bukkit.broadcastMessage("§6[§4公告§6] §a"+customName+"§a被卷入了异次元时空.");
return; return;
@ -76,7 +74,7 @@ public class DamageManage implements Listener {
return; return;
} }
UUID Mob_uuid = e.getEntity().getUniqueId(); UUID Mob_uuid = e.getEntity().getUniqueId();
if (!SpawnPut.WhiteBossList.contains(Mob_uuid)) { if (!BossSpawnLogs.WhiteBossList.contains(Mob_uuid)) {
e.getEntity().remove(); e.getEntity().remove();
Bukkit.broadcastMessage("§6[§4公告§6] §a" + customName + "§a被卷入了异次元时空."); Bukkit.broadcastMessage("§6[§4公告§6] §a" + customName + "§a被卷入了异次元时空.");
return; return;

View File

@ -0,0 +1,6 @@
package com.io.yaohun.worldbosshurt.listener;
import org.bukkit.event.Listener;
public class BossKillsDeath implements Listener {
}

View File

@ -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<String> WhiteBossList = new ArrayList<>();
@EventHandler
public void onSpawnBlockEvent(WorldBossSpawnEvent e) {
String customName = e.getMobName();
WhiteBossList.add(customName);
Bukkit.getConsoleSender().sendMessage("[日志-UUID导入] Boss "+customName+" §r已被录入List");
}
}

View File

@ -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<UUID> 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");
}
}
}
}

View File

@ -34,6 +34,17 @@ public class BossManage {
return bossDataMap.get(bossKey); 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() { public boolean isBossSurvive() {
return bossSurvive; return bossSurvive;
} }

View File

@ -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<String, RewardData> 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() + "");
}
}

View File

@ -3,4 +3,5 @@ main: com.io.yaohun.worldbosshurt.main
version: 1.0.0 version: 1.0.0
commands: commands:
bosspz: bosspz:
bossreload:
bossspawner: bossspawner: