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 fc6f521..7dee2a2 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/mangage/BossManage.java @@ -14,13 +14,13 @@ public class BossManage { private boolean bossSurvive; private final List bossKeyList = new ArrayList<>(); // 获取boss名列表 private final List customNameList = new ArrayList<>(); // 获取boss名列表 - private final HashMap bossDataMap = new HashMap<>(); + 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"); + 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); } @@ -28,17 +28,17 @@ public class BossManage { } public BossData getBossData(String bossKey) { - if(bossDataMap.get(bossKey) == null){ + if (bossDataMap.get(bossKey) == null) { return null; } return bossDataMap.get(bossKey); } public BossData getNameToData(String customName) { - for (String bossKey : bossDataMap.keySet()){ + for (String bossKey : bossDataMap.keySet()) { BossData data = bossDataMap.get(bossKey); String bossName = data.getBossName(); - if(customName.contains(bossName)){ + if (customName.contains(bossName)) { return data; } } @@ -48,7 +48,8 @@ public class BossManage { public boolean isBossSurvive() { return bossSurvive; } - public void setBossSurvive(boolean butt){ + + public void setBossSurvive(boolean butt) { bossSurvive = butt; } @@ -56,14 +57,18 @@ public class BossManage { return bossKeyList; } - public boolean isCustomNameContains(String customName){ - for (String name : this.customNameList){ - if(customName.contains(name)){ + public boolean isCustomNameContains(String customName) { + // 检查 customName 是否为 null + if (customName == null) { + return false; + } + // 遍历 customNameList 检查是否有任何名称包含 customName + for (String name : this.customNameList) { + // 检查 name 是否为 null + if (name != null && customName.contains(name)) { return true; } } return false; } - - } diff --git a/src/main/java/com/io/yaohun/worldbosshurt/mangage/RewardManage.java b/src/main/java/com/io/yaohun/worldbosshurt/mangage/RewardManage.java index 580faed..b198dbd 100644 --- a/src/main/java/com/io/yaohun/worldbosshurt/mangage/RewardManage.java +++ b/src/main/java/com/io/yaohun/worldbosshurt/mangage/RewardManage.java @@ -1,14 +1,10 @@ package com.io.yaohun.worldbosshurt.mangage; -import com.io.yaohun.worldbosshurt.data.BossData; import com.io.yaohun.worldbosshurt.data.RewardData; -import com.sun.xml.internal.txw2.output.StreamSerializer; 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 {