diff --git a/pom.xml b/pom.xml index a7a780d..3ca214f 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,16 @@ MythicMobs 1.12.2 + + me.Demon.DemonLevels + DemonLevels + 1.0.0 + + + com.vexview.api + vexview + 1.12.2 + \ No newline at end of file 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 97125c3..8d14e7d 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/command/BossSpawnerCmd.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/command/BossSpawnerCmd.java @@ -1,27 +1,124 @@ package com.io.yaohun.worldbosshurt.command; +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.util.BossSpawnUtil; import com.io.yaohun.worldbosshurt.util.BossUtil; +import lk.vexview.api.VexViewAPI; +import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; +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 - public boolean onCommand(CommandSender sender, Command command, String label, String[] arge) { + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(BossUtil.isTimeMonthly()){ + BossUtil.settlementRankingRewards(); + } + if(args.length == 0 && sender.isOp()){ + sender.sendMessage("§r"); + sender.sendMessage("§e------- ======= §6世界BOSS §e======= -------"); + sender.sendMessage("§2/bossspawner §e[代号] §f- §2生成Boss"); + sender.sendMessage("§e------- ======= §6世界BOSS §e======= -------"); + sender.sendMessage("§r"); + return true; + } + if(args.length == 1){ + BossManage bossManage = Main.bossManage; + if(bossManage.isBossSurvive()){ + Bukkit.getConsoleSender().sendMessage("[日志-世界Boss] 系统尝试多次执行召唤boss已被拦截."); + return true; + } + DamageManage.damageMap.clear(); // 清理之前的伤害数据缓存 + String stats_type = BossSpawnUtil.getTheCurrentServerPlayerStatus(); + if(stats_type.equalsIgnoreCase("NoPlayer")){ + Bukkit.broadcastMessage("§6[§4公告§6] §a世界BOSS召唤失败,在线器师人数过低无法挑战."); + return true; + } + if(stats_type.equalsIgnoreCase("NoLevel")){ + Bukkit.broadcastMessage("§6[§4公告§6] §a世界BOSS召唤失败,在线器师无一人达到90级封号斗魂."); + return true; + } + if(stats_type.equalsIgnoreCase("Start")) { + String bossKey = args[0]; + BossData bossData = bossManage.getBossData(bossKey); + if(bossData != null){ + Location spawnLoc = bossData.getLocation();// 获取生成点坐标 + // 获取坐标周围30格范围内是否存在生物,若存在则清除 + List stringList = new ArrayList<>(); + for (Entity entity : spawnLoc.getWorld().getNearbyEntities(spawnLoc,30,25,30)){ + if(!(entity instanceof Item)) { + if(!(entity instanceof Player)){ + if(entity.getCustomName() != null) { + stringList.add(entity.getCustomName()); + entity.remove(); + } + } + } + } + if(stringList.size() >= 1){ + Bukkit.getConsoleSender().sendMessage("[日志-世界Boss] 清理周边怪物: "+stringList); + } + bossManage.setBossSurvive(true); + String bossName = bossData.getBossName();// 获取boss的自定义名字 + String broadcast = bossData.getBc().replace("%mobs%",bossName); // 获取bc公告信息 + Bukkit.broadcastMessage(broadcast); + Bukkit.broadcastMessage(broadcast); + // 发送VexViewAPI的信息 + for (Player allp : Bukkit.getOnlinePlayers()) { + if (allp.getLevel() >= 40) { + // 发送Vex信息 + String bc_vv = bossData.getBc_vv().replace("%mobs%", bossName); + VexViewAPI.sendFlowView(allp, bc_vv, 16, true); + } + } + new BukkitRunnable() { + private int seconds = 0; + public void run() { + if(seconds == 2){ + bossManage.setBossSurvive(false); + } + if(seconds >= 20){ + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mythicmobs mobs spawn " + bossKey + " 1 " + bossData.getLocString()); + cancel(); + } + seconds++; + } + }.runTaskTimer(Main.plugin,0, 20L); + WorldBossSpawnEvent event = new WorldBossSpawnEvent(bossName); + Bukkit.getPluginManager().callEvent(event); + } + } } return false; } @Override - public List onTabComplete(CommandSender sender, Command command, String label, String[] arge) { - List stringList = new ArrayList<>(); - return null; + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + List completions = new ArrayList<>(); + if(args.length == 1){ + completions.addAll(Main.bossManage.getBossKeyList()); + } + return completions; } } diff --git a/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossSpawnEvent.java b/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossSpawnEvent.java new file mode 100644 index 0000000..a61d846 --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/event/WorldBossSpawnEvent.java @@ -0,0 +1,25 @@ +package com.io.yaohun.worldbosshurt.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class WorldBossSpawnEvent extends Event { + + private static HandlerList handlers = new HandlerList(); + private String mobName; + + @Override + public HandlerList getHandlers() { + return handlers; + } + public static HandlerList getHandlerList() { + return handlers; + } + public WorldBossSpawnEvent(String mobName) { + this.mobName = mobName; + } + + public String getMobName() { + return mobName; + } +} 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 abba6c9..c8305b2 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java @@ -5,23 +5,45 @@ import com.io.yaohun.worldbosshurt.data.BossData; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class BossManage { - private List customNameList; // 获取boss名列表 + private boolean bossSurvive; + private final List bossKeyList = new ArrayList<>(); // 获取boss名列表 + private final List customNameList = new ArrayList<>(); // 获取boss名列表 private final HashMap bossDataMap = new HashMap<>(); public BossManage(FileConfiguration yml) { + this.bossSurvive = false; 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); + bossKeyList.add(bossKey); } Bukkit.getConsoleSender().sendMessage("§b[BossHurt] §f已导入Boss: §a" + customNameList.size() + "只"); } + public BossData getBossData(String bossKey) { + if(bossDataMap.get(bossKey) == null){ + return null; + } + return bossDataMap.get(bossKey); + } + + public boolean isBossSurvive() { + return bossSurvive; + } + public void setBossSurvive(boolean butt){ + bossSurvive = butt; + } + + public List getBossKeyList() { + return bossKeyList; + } public boolean isCustomNameContains(String customName){ for (String name : this.customNameList){ diff --git a/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java b/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java index d1e6de0..99cc742 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/mangage/DamageManage.java @@ -19,7 +19,7 @@ import java.util.UUID; public class DamageManage implements Listener { - private HashMap damageMap = new HashMap<>(); + public static HashMap damageMap = new HashMap<>(); private void addPlayerDamage(Player player,double damage){ double newDamage = damage / 1000; diff --git a/src/main/java/com/io/yaohun/worldbosshurt/util/BossSpawnUtil.java b/src/main/java/com/io/yaohun/worldbosshurt/util/BossSpawnUtil.java new file mode 100644 index 0000000..b441fd9 --- /dev/null +++ b/src/main/java/com/io/yaohun/worldbosshurt/util/BossSpawnUtil.java @@ -0,0 +1,31 @@ +package com.io.yaohun.worldbosshurt.util; + +import me.Demon.DemonLevels.api.DLevelAPI; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class BossSpawnUtil { + + public static String getTheCurrentServerPlayerStatus(){ + // 如果服务器没有玩家在线则无法召唤 + int online_size = Bukkit.getOnlinePlayers().size(); + if(online_size <= 0){ + return "NoPlayer"; + } + // 在线人数大于15人 可召唤 + if (online_size > 15) { + return "Start"; + } + // 在线人数小于5人 但有90级玩家 可召唤 + if (online_size < 15) { + for (Player p : Bukkit.getOnlinePlayers()){ + double level = DLevelAPI.getOffPlayer_Level(p.getName()); + Bukkit.getConsoleSender().sendMessage("[世界BOSS-输出日志] 玩家 "+p.getName()+" 等级: "+level+" 需求等级: 90级"); + if(level >= 90) { + return "Start"; + } + } + } + return "NoLevel"; + } +} diff --git a/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java b/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java index 0cea46b..266bd05 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/util/BossUtil.java @@ -39,7 +39,6 @@ public class BossUtil { * 判断本月数据是否刷新 * */ public static boolean isTimeMonthly(){ - FileConfiguration yml = Main.plugin.getConfig(); if(!getTimeMonthly().equalsIgnoreCase(DemonAPI.getTime("yyyy/MM"))){ return true; }