This commit is contained in:
yuyu 2024-08-15 20:05:13 +08:00
parent 9c23f5fc3d
commit ce3d0c1bac
9 changed files with 179 additions and 150 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.yuyu</groupId>
<artifactId>SrWildEntity</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SrWildEntity</name>

View File

@ -1,14 +1,17 @@
package com.yuyu.srwildentity.config.condition;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import javax.swing.text.html.parser.Entity;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
/**
* @BelongsProject: SrWildEntity
@ -24,16 +27,16 @@ public class BiomeEntityRefreshSettings {
//
// private final HashMap<String,HashMap<String,EntityCondition>> biomeEntityConditionMap;//此集合储存需要刷新的怪物的相关配置
private final List<LevelRefresh> levelRefreshesList;
private final HashMap<String,EntityCondition> generalEntityConditions;
private int levelMax;
public BiomeEntityRefreshSettings(Plugin plugin,int levelMax) {
// this.biomeEntityMap = new HashMap<>();
// this.biomeEntityConditionMap = new HashMap<>();
this.levelRefreshesList = new ArrayList<>();
// this.loadBiomeEntitiesConfig(plugin,levelMax);
//
// this.loadEntityConditionConfig(plugin,levelMax);
this.levelRefreshesList = new ArrayList<>();
this.levelMax = levelMax;
this.generalEntityConditions = new HashMap<>();
this.loadRefreshEntity(plugin,levelMax);
@ -47,11 +50,25 @@ public class BiomeEntityRefreshSettings {
File file = new File(plugin.getDataFolder(), "biomeEntity.yml");
config = YamlConfiguration.loadConfiguration(file);
HashMap<String,HashMap<String,Integer>> riskMap = new HashMap<>();
for (int i = 1;i <= levelMax;i++){
String risk = config.getString("risk_" + i);
String[] split = risk.split("\\|");
int min = Integer.parseInt(split[0]);
int max = Integer.parseInt(split[1]);
HashMap<String,Integer> map = new HashMap<>();
map.put("min",min);
map.put("max",max);
riskMap.put("risk_" + i,map);
}
//获取所有生物群系
plugin.saveResource("biome.yml",false);
FileConfiguration biomeconfig = null;
File biomeName = new File(plugin.getDataFolder(),"biome.yml");
biomeconfig = YamlConfiguration.loadConfiguration(biomeName);
//群系列表
List<String> biomeList = biomeconfig.getStringList("biome");
@ -77,49 +94,56 @@ public class BiomeEntityRefreshSettings {
}
}
}
//按level_i 储存刷新的怪物列表
levelBiomeMap.put("level_"+i,biomeMap);
}
FileConfiguration levelConfig = null;
File levelFile = new File(plugin.getDataFolder(), "entityCondition.yml");
levelConfig = YamlConfiguration.loadConfiguration(levelFile);
for (int i = 1;i <= level;i++){
//读取对应的等级文件
// plugin.saveResource("LEVEL_"+i+".yml",false);
FileConfiguration levelConfig = null;
File levelFile = new File(plugin.getDataFolder(), "LEVEL_"+i+".yml");
levelConfig = YamlConfiguration.loadConfiguration(levelFile);
//获取对应等级的怪物刷新列表
HashMap<String, List<String>> stringListHashMap = levelBiomeMap.get("level_" + i);
//获取最大,最小危险度
int riskMax = levelConfig.getInt("RISK_MAX");
int riskMin = levelConfig.getInt("RISK_MIN");
HashMap<String,List<EntityCondition>> listHashMap = new HashMap<>();
//获取最大,最小危险度 todo(这里放到config.yml里面)
// int riskMax = levelConfig.getInt("RISK_MAX");
// int riskMin = levelConfig.getInt("RISK_MIN");
// 群系 实体列表
HashMap<String,HashMap<String,EntityCondition>> listHashMap = new HashMap<>();
for (String biome : stringListHashMap.keySet()){
List<EntityCondition> entityConditions = new ArrayList<>();
// List<EntityCondition> entityConditions = new ArrayList<>();
HashMap<String,EntityCondition> entityConditions = new HashMap<>();
List<String> strings = stringListHashMap.get(biome);
for (String entityName : strings){
SpawnEntityType spawnEntityType = SpawnEntityType.fromId(levelConfig.getInt(biome + "." + entityName + ".type"));
EntitySite entitySite = EntitySite.fromId(levelConfig.getInt(biome + "." + entityName + ".site"));
int light = levelConfig.getInt(biome + "." + entityName + ".light");
long stime = levelConfig.getLong(biome + "." + entityName + ".startTiming");
long etime = levelConfig.getLong(biome + "." + entityName + ".endTiming");
int nums = levelConfig.getInt(biome + "." + entityName + ".nums");
int yMax = levelConfig.getInt(biome + "." + entityName + ".yMax");
int yMin = levelConfig.getInt(biome + "." + entityName + ".yMin");
// int riskMax = levelConfig.getInt(biome + "." + entityName + ".riskMax");
// int riskMin = levelConfig.getInt(biome + "." + entityName + ".riskMin");
double weight = levelConfig.getDouble(biome + "." + entityName + ".weight");
EntityCondition entityCondition = new EntityCondition(entityName, biome,
spawnEntityType, entitySite, light, stime, etime, nums, yMax, yMin, 50, 0, weight);
entityConditions.add(entityCondition);
plugin.getLogger().info(ChatColor.AQUA +"Level:"+i +"\t"+ entityCondition.toString());
String matching_direction = levelConfig.getString(biome + "." + entityName + ".Matching_direction");
if (matching_direction != null){
String[] split = matching_direction.split("\\|");
String formation = split[0];
String entity = split[1];
EntityCondition entityCondition = makeEntityCondition(entity, formation, levelConfig);
entityConditions.put(entityName,entityCondition);
plugin.getLogger().info(ChatColor.AQUA +"Level:"+i +"\t"+ entityCondition.toString());
continue;
}
EntityCondition entityCondition = makeEntityCondition(entityName, biome, levelConfig);
entityConditions.put(entityName,entityCondition);
if (entityCondition == null){
plugin.getLogger().info(ChatColor.AQUA +"Level:"+i +"\t"+ entityCondition);
}else {
plugin.getLogger().info(ChatColor.AQUA + "Level:" + i + "\t" + entityCondition.toString());
}
}
//此处按群系储存list
@ -127,101 +151,79 @@ public class BiomeEntityRefreshSettings {
}
//此处按等级储存对应等级的LevelRefresh对象
this.levelRefreshesList.add(new LevelRefresh(riskMax,riskMin,listHashMap));
this.levelRefreshesList.add(new LevelRefresh(riskMap.get("risk_"+i).get("max"),riskMap.get("risk_"+i).get("min"),listHashMap,"等级"+i));
}
//循环通用的
plugin.saveResource("generalCondition.yml",false);
FileConfiguration generalCondition;
File generalFile = new File(plugin.getDataFolder(), "generalCondition.yml");
generalCondition = YamlConfiguration.loadConfiguration(generalFile);
Set<String> keys = generalCondition.getKeys(false);
for (String key : keys){
EntityCondition entityCondition = makeGeneralEntityCondition(key, generalCondition);
this.generalEntityConditions.put(key,entityCondition);
}
}
// private void loadEntityConditionConfig(Plugin plugin,int levelMax) {
//
// //保存文件
// plugin.saveResource("entityCondition.yml",false);
//
// FileConfiguration config;
// File file = new File(plugin.getDataFolder(), "entityCondition.yml");
// config = YamlConfiguration.loadConfiguration(file);
//
//
// for (int i = 1;i<levelMax;i++) {
// for (String biomeName : this.biomeEntityMap.keySet()) {
// plugin.getLogger().info(ChatColor.GOLD + biomeName);
// HashMap<String, EntityCondition> entityConditionHashMap = new HashMap<>();
//
// List<String> entities = this.biomeEntityMap.get(biomeName);
// for (String entityName : entities) {
// SpawnEntityType spawnEntityType = SpawnEntityType.fromId(config.getInt(biomeName + "." + entityName + ".type"));
// EntitySite entitySite = EntitySite.fromId(config.getInt(biomeName + "." + entityName + ".site"));
// int light = config.getInt(biomeName + "." + entityName + ".light");
// long stime = config.getLong(biomeName + "." + entityName + ".startTiming");
// long etime = config.getLong(biomeName + "." + entityName + ".endTiming");
// int nums = config.getInt(biomeName + "." + entityName + ".nums");
// int yMax = config.getInt(biomeName + "." + entityName + ".yMax");
// int yMin = config.getInt(biomeName + "." + entityName + ".yMin");
// int riskMax = config.getInt(biomeName + "." + entityName + ".riskMax");
// int riskMin = config.getInt(biomeName + "." + entityName + ".riskMin");
// double weight = config.getDouble(biomeName + "." + entityName + ".weight");
// EntityCondition entityCondition = new EntityCondition(entityName, biomeName,
// spawnEntityType, entitySite, light, stime, etime, nums, yMax, yMin, riskMax, riskMin, weight);
//
// plugin.getLogger().info(ChatColor.AQUA + entityCondition.toString());
//
// //存入单个群系刷新map
// entityConditionHashMap.put(entityName, entityCondition);
// }
// //存入记录总群系的map
// biomeEntityConditionMap.put(biomeName, entityConditionHashMap);
// }
// }
//
// plugin.getLogger().info("群系刷新相关文件读取完毕");
// }
//
// public void loadBiomeEntitiesConfig(Plugin plugin,int levelMax){
// //保存文件
// plugin.saveResource("biomeEntity.yml",false);
//
// FileConfiguration config;
// File file = new File(plugin.getDataFolder(), "biomeEntity.yml");
// config = YamlConfiguration.loadConfiguration(file);
//
// //获取所有生物群系
// plugin.saveResource("biome.yml",false);
// FileConfiguration biomeconfig = null;
// File biomeName = new File(plugin.getDataFolder(),"biome.yml");
// biomeconfig = YamlConfiguration.loadConfiguration(biomeName);
// List<String> biomeList = biomeconfig.getStringList("biome");
//
//
//
// if (config == null || biomeconfig == null){
// plugin.getLogger().info("biomeEntity.yml或者 biome.yml文件读取失败!");
// return;
// }
//
// //遍历所有可能的生物群系
// for (String section : biomeList){
// //判断是否存在
// if (config.contains(section)){
// List<String> entityList = config.getStringList(section+".ENTITY");
// this.biomeEntityMap.put(section,entityList);
// plugin.getLogger().info(ChatColor.MAGIC+section+ entityList.toString());
// }
// }
//
// plugin.getLogger().info("biomeEntity.读取完成");
// }
public EntityCondition makeEntityCondition(String entityName,String biome,FileConfiguration levelConfig){
SpawnEntityType spawnEntityType = SpawnEntityType.fromId(levelConfig.getInt(biome + "." + entityName + ".type"));
EntitySite entitySite = EntitySite.fromId(levelConfig.getInt(biome + "." + entityName + ".site"));
int light = levelConfig.getInt(biome + "." + entityName + ".light");
long stime = levelConfig.getLong(biome + "." + entityName + ".startTiming");
long etime = levelConfig.getLong(biome + "." + entityName + ".endTiming");
int nums = levelConfig.getInt(biome + "." + entityName + ".nums");
int yMax = levelConfig.getInt(biome + "." + entityName + ".yMax");
int yMin = levelConfig.getInt(biome + "." + entityName + ".yMin");
double weight = levelConfig.getDouble(biome + "." + entityName + ".weight");
EntityCondition entityCondition = new EntityCondition(entityName, biome,
spawnEntityType, entitySite, light, stime, etime, nums, yMax, yMin, 50, 0, weight);
if (entityCondition.getNums()==0){
Bukkit.getServer().getPluginManager().getPlugin("SrWildEntity").getLogger().info(ChatColor.RED+biome+"."+entityName+".No_Condition");
return null;
}
return entityCondition;
}
public EntityCondition makeGeneralEntityCondition(String entityName,FileConfiguration levelConfig){
SpawnEntityType spawnEntityType = SpawnEntityType.fromId(levelConfig.getInt(entityName + ".type"));
EntitySite entitySite = EntitySite.fromId(levelConfig.getInt( entityName + ".site"));
int light = levelConfig.getInt( entityName + ".light");
long stime = levelConfig.getLong( entityName + ".startTiming");
long etime = levelConfig.getLong(entityName + ".endTiming");
int nums = levelConfig.getInt( entityName + ".nums");
int yMax = levelConfig.getInt(entityName + ".yMax");
int yMin = levelConfig.getInt( entityName + ".yMin");
double weight = levelConfig.getDouble( entityName + ".weight");
EntityCondition entityCondition = new EntityCondition(entityName, null,
spawnEntityType, entitySite, light, stime, etime, nums, yMax, yMin, 50, 0, weight);
if (entityCondition.getNums()==0){
Bukkit.getServer().getPluginManager().getPlugin("SrWildEntity").getLogger().info(ChatColor.RED+"."+entityName+".No_Condition");
return null;
}
return entityCondition;
}
// public HashMap<String, List<String>> getBiomeEntityMap() {
// return biomeEntityMap;
// }
//
// public HashMap<String, HashMap<String, EntityCondition>> getBiomeEntityConditionMap() {
// return biomeEntityConditionMap;
// }
public List<LevelRefresh> getLevelRefreshesList() {
return levelRefreshesList;
}
public HashMap<String, EntityCondition> getGeneralEntityConditions() {
return generalEntityConditions;
}
public int getLevelMax() {
return levelMax;
}
public void setLevelMax(int levelMax) {
this.levelMax = levelMax;
}
}

View File

@ -1,5 +1,7 @@
package com.yuyu.srwildentity.config.condition;
import java.util.List;
/**
* @BelongsProject: SrWildEntity
* @BelongsPackage: com.yuyu.srwildentity.config.condition
@ -20,10 +22,9 @@ public class EntityCondition {
private final int nums;//刷新的数量
private final int yMax;
private final int yMin;
private final int riskMax;
private final int riskMin;
private final double weight;
private long refreshTime;
private List<String> refreshAreas;
public EntityCondition(String entityName, String biome, SpawnEntityType spawnEntityType, EntitySite entitySite,
int light, long startTiming, long endTiming, int nums,
@ -38,8 +39,6 @@ public class EntityCondition {
this.nums = nums;
this.yMax = yMax;
this.yMin = yMin;
this.riskMax = riskMax;
this.riskMin = riskMin;
this.weight = weight;
this.refreshTime = refreshTime;
}
@ -56,8 +55,7 @@ public class EntityCondition {
this.nums = nums;
this.yMax = yMax;
this.yMin = yMin;
this.riskMax = riskMax;
this.riskMin = riskMin;
this.weight = weight;
}
@ -65,14 +63,6 @@ public class EntityCondition {
return spawnEntityType;
}
public int getRiskMax() {
return riskMax;
}
public int getRiskMin() {
return riskMin;
}
public SpawnEntityType getEntityType() {
return spawnEntityType;
}
@ -123,6 +113,11 @@ public class EntityCondition {
@Override
public String toString() {
if (nums == 0){
return "EntityName = " + entityName + ", biome = " + biome + ", spawnEntityType = ";
}
return "EntityCondition{" +
"entityName='" + entityName + '\'' +
", biome='" + biome + '\'' +
@ -134,8 +129,6 @@ public class EntityCondition {
", nums=" + nums +
", yMax=" + yMax +
", yMin=" + yMin +
", riskMax=" + riskMax +
", riskMin=" + riskMin +
", weight=" + weight +
'}';
}

View File

@ -16,7 +16,8 @@ public class LevelRefresh {
private final int riskMax;
private final int riskMin;
// 群系名
private final HashMap<String, List<EntityCondition>> entityConditionHashMap;
private final HashMap<String, HashMap<String,EntityCondition>> entityConditionHashMap;
private final String levelStr;
public int getRiskMax() {
return riskMax;
@ -26,13 +27,18 @@ public class LevelRefresh {
return riskMin;
}
public HashMap<String, List<EntityCondition>> getEntityConditionHashMap() {
public HashMap<String, HashMap<String, EntityCondition>> getEntityConditionHashMap() {
return entityConditionHashMap;
}
public LevelRefresh(int riskMax, int riskMin, HashMap<String, List<EntityCondition>> entityConditionHashMap) {
public LevelRefresh(int riskMax, int riskMin, HashMap<String, HashMap<String,EntityCondition>> entityConditionHashMap, String levelStr) {
this.riskMax = riskMax;
this.riskMin = riskMin;
this.entityConditionHashMap = entityConditionHashMap;
this.levelStr = levelStr;
}
public String getLevelStr() {
return levelStr;
}
}

View File

@ -130,8 +130,12 @@ public class PlayerRefreshLintener {
}
return;
}
String levelStr;
if (refreshList.getLevelStr().contains("1")){
levelStr = "";
}else {
levelStr = refreshList.getLevelStr();
}
//获取玩家位置信息
int blockZ = playerlocation.getBlockZ();
@ -140,9 +144,9 @@ public class PlayerRefreshLintener {
Biome biome = world.getBiome(blockX, blockZ);
String biomeName = biome.name();
List<EntityCondition> entityConditionList = null;
HashMap<String,EntityCondition> entityConditionList = null;
HashMap<String, List<EntityCondition>> entityConditionHashMap = refreshList.getEntityConditionHashMap();
HashMap<String, HashMap<String,EntityCondition>> entityConditionHashMap = refreshList.getEntityConditionHashMap();
for (String refreshBiome : entityConditionHashMap.keySet()){
if (biomeName.contains(refreshBiome)){
entityConditionList = entityConditionHashMap.get(refreshBiome);
@ -157,8 +161,18 @@ public class PlayerRefreshLintener {
return;
}
for (EntityCondition entityCondition : entityConditionList){
for (String entityName : entityConditionList.keySet()){
EntityCondition entityCondition = entityConditionList.get(entityName);
//如果为空,则去通用刷新寻找
if (entityCondition == null){
HashMap<String, EntityCondition> generalEntityConditions = configManager.getBiomeEntityRefreshSettings().getGeneralEntityConditions();
if (generalEntityConditions.containsKey(entityName)){
entityCondition = generalEntityConditions.get(entityName);
}else {
EntityRefreshListener.log.info(ChatColor.RED + "没有配置" + entityName + "的刷新配置");
continue;
}
}
int yMin = entityCondition.getyMin();
int yMax = entityCondition.getyMax();
@ -206,7 +220,7 @@ public class PlayerRefreshLintener {
}else {
//刷新MM怪物
try {
entity = mythicMobs.getAPIHelper().spawnMythicMob(entityCondition.getEntityName(),location,riskLevel);
entity = mythicMobs.getAPIHelper().spawnMythicMob(entityCondition.getEntityName()+levelStr,location,riskLevel);
} catch (InvalidMobTypeException e) {
throw new RuntimeException(e);
}
@ -251,7 +265,7 @@ public class PlayerRefreshLintener {
}else {
//刷新MM怪物
try {
entity = MythicMobs.inst().getAPIHelper().spawnMythicMob(entityCondition.getEntityName(), location);
entity = MythicMobs.inst().getAPIHelper().spawnMythicMob(entityCondition.getEntityName()+levelStr, location);
} catch (InvalidMobTypeException e) {
throw new RuntimeException(e);
}

View File

@ -1,3 +1,6 @@
risk_1: 0|20
risk_2: 20|30
DESERT: #群系名称,下方标出该群系需要刷新的entity
ENTITY_LEVEL_1: [ZOMBIE,PIG_ZOMBIE] #该群系刷新的entity,具体的怪物刷新配置需要去entityConfig.yml中配置,!!注意此处的实体配置一定要在实体配置文件中存在,否则会不会刷新!

View File

@ -1,8 +1,6 @@
#RISK_MAX: 10 #当最大危险度为多少时读取这个yml文件10的时候会读取
#RISK_MIN: 0 #当最小危险度为多少时读取这个yml文件0的时候不会读取
DESERT:
ZOMBIE: #指出entity在该群系的刷新条件
Matching_direction: ROOFED_FOREST_ZOMBIE #群系_怪物 会直接读取该实体的刷新配置
Matching_direction: ROOFED|ZOMBIE #群系_怪物 会直接读取该实体的刷新配置
ROOFED_FOREST:
ZOMBIE: #指出entity在该群系的刷新条件
type: 0 #0表示生成mc原生实体1表示生成MM怪物2表示生成萌芽怪物

View File

@ -0,0 +1,13 @@
#通用
PIG_ZOMBIE:
weight: 0.6
type: 0 #0表示生成mc原生实体1表示生成MM怪物2表示生成萌芽怪物
site: 1 #刷新位置,数字代表不同的刷新位置
light: 15 #刷新亮度
startTiming: 0 #刷新怪物的时间注意这里需要用mc中的时间格式来表示而不是现实中的时间
endTiming: 24000 #结束刷新的时间,怪物会在这个区间内刷新
nums: 2 #entity的刷新数量注意这里的数量会和通群系中其他entity相关总数不会超过config.yml中的定义
yMax: 150 #极限刷新高度
yMin: 60 #最小刷新高度
riskMax: 10 #刷新危险度的范围
riskMin: 0