增加了权重判定,并且修复了玩家退出登录后再登录后dsp clear实体会刷不掉一些实体的bug

This commit is contained in:
yuyu 2024-04-14 22:31:39 +08:00
parent 29da41875e
commit 3ca0f1f960
7 changed files with 49 additions and 16 deletions

View File

@ -51,4 +51,5 @@ public class ConfigManager {
public int getTotal() { public int getTotal() {
return total; return total;
} }
} }

View File

@ -57,8 +57,9 @@ public class BiomeEntityRefreshSettings {
int yMin = config.getInt(biomeName+"."+entityName+".yMin"); int yMin = config.getInt(biomeName+"."+entityName+".yMin");
int riskMax = config.getInt(biomeName+"."+entityName+".riskMax"); int riskMax = config.getInt(biomeName+"."+entityName+".riskMax");
int riskMin = config.getInt(biomeName+"."+entityName+".riskMin"); int riskMin = config.getInt(biomeName+"."+entityName+".riskMin");
double weight = config.getDouble(biomeName+"."+entityName+".weight");
EntityCondition entityCondition = new EntityCondition(entityName, biomeName, EntityCondition entityCondition = new EntityCondition(entityName, biomeName,
spawnEntityType,entitySite, light, stime,etime, nums, yMax, yMin,riskMax,riskMin); spawnEntityType,entitySite, light, stime,etime, nums, yMax, yMin,riskMax,riskMin,weight);
plugin.getLogger().info(ChatColor.AQUA+entityCondition.toString()); plugin.getLogger().info(ChatColor.AQUA+entityCondition.toString());

View File

@ -22,8 +22,11 @@ public class EntityCondition {
private final int yMin; private final int yMin;
private final int riskMax; private final int riskMax;
private final int riskMin; private final int riskMin;
private final double weight;
public EntityCondition(String entityName, String biome, SpawnEntityType spawnEntityType, EntitySite entitySite, int light, long startTiming, long endTiming, int nums, int yMax, int yMin,int riskMax,int riskMin) { public EntityCondition(String entityName, String biome, SpawnEntityType spawnEntityType, EntitySite entitySite,
int light, long startTiming, long endTiming, int nums,
int yMax, int yMin,int riskMax,int riskMin, double weight) {
this.entityName = entityName; this.entityName = entityName;
this.biome = biome; this.biome = biome;
this.spawnEntityType = spawnEntityType; this.spawnEntityType = spawnEntityType;
@ -36,6 +39,7 @@ public class EntityCondition {
this.yMin = yMin; this.yMin = yMin;
this.riskMax = riskMax; this.riskMax = riskMax;
this.riskMin = riskMin; this.riskMin = riskMin;
this.weight = weight;
} }
public SpawnEntityType getSpawnEntityType() { public SpawnEntityType getSpawnEntityType() {
@ -90,6 +94,10 @@ public class EntityCondition {
return yMin; return yMin;
} }
public double getWeight() {
return weight;
}
@Override @Override
public String toString() { public String toString() {
return "EntityCondition{" + return "EntityCondition{" +
@ -105,6 +113,7 @@ public class EntityCondition {
", yMin=" + yMin + ", yMin=" + yMin +
", riskMax=" + riskMax + ", riskMax=" + riskMax +
", riskMin=" + riskMin + ", riskMin=" + riskMin +
", weight=" + weight +
'}'; '}';
} }
} }

View File

@ -243,20 +243,19 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
* @param event * @param event
*/ */
@EventHandler @EventHandler
public void onPlayerOffOnline(PlayerQuitEvent event){ public void onPlayerOffOnline(PlayerQuitEvent event) {
if (flag) { if (flag) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String name = player.getName(); String name = player.getName();
//下线后移出刷新列表 //下线后移出刷新列表
if (refreshPlayer.get(name) != null) { // if (refreshPlayer.get(name) != null) {
List<UUID> entityList = refreshPlayer.get(name).getEntityList(); // List<UUID> entityList = refreshPlayer.get(name).getEntityList();
for (UUID uuid : entityList){ // for (UUID uuid : entityList){
//删除储存的实体信息 // //删除储存的实体信息
entityUUIDToPlayer.remove(uuid); // entityUUIDToPlayer.remove(uuid);
} // }
refreshPlayer.remove(name); refreshPlayer.remove(name);
logger.info(ChatColor.GOLD + "玩家被移出刷新集合"); logger.info(ChatColor.GOLD + "玩家被移出刷新集合");
}
} }
} }
@ -295,7 +294,9 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
//通过uuid获取对应的玩家姓名,然后通过玩家姓名获取对应的list集合 //通过uuid获取对应的玩家姓名,然后通过玩家姓名获取对应的list集合
String name = entityUUIDToPlayer.get(uniqueId); String name = entityUUIDToPlayer.get(uniqueId);
refreshPlayer.get(name).delEntityList(uniqueId); if (refreshPlayer.containsKey(name)) {
refreshPlayer.get(name).delEntityList(uniqueId);
}
} }
} }
} }
@ -311,6 +312,7 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
if (noRefreshPlayer.contains(name)){ if (noRefreshPlayer.contains(name)){
continue; continue;
} }
int attempts = 0;
int sum = 0;//用于记录此次刷新生成的总数 int sum = 0;//用于记录此次刷新生成的总数
//获取玩家信息 //获取玩家信息
Player player = plugin.getServer().getPlayer(name); Player player = plugin.getServer().getPlayer(name);
@ -363,6 +365,11 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
continue; continue;
} }
if (random.nextFloat() > entityCondition.getWeight()){
//刷新不通过,进入下一个验证的实体
continue;
}
int nums = entityCondition.getNums();//当前实体需要刷新的数量 int nums = entityCondition.getNums();//当前实体需要刷新的数量
for (int i = 0;i<nums && for (int i = 0;i<nums &&
@ -488,11 +495,25 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
if (entityUUIDToPlayer.containsKey(uuid)){ if (entityUUIDToPlayer.containsKey(uuid)){
entityUUIDToPlayer.remove(uuid); entityUUIDToPlayer.remove(uuid);
} }
}else {
if (entityUUIDToPlayer.containsKey(uuid)){
entityUUIDToPlayer.remove(uuid);
}
} }
} }
//entity清除完后 //entity清除完后
refreshPlayer.get(name).setEntityList(new ArrayList<>()); refreshPlayer.get(name).setEntityList(new ArrayList<>());
} }
for (UUID uuid : entityUUIDToPlayer.keySet()){
Entity entity = plugin.getServer().getEntity(uuid);
if (entity != null){
entity.remove();
entityUUIDToPlayer.remove(uuid);
}else {
entityUUIDToPlayer.remove(uuid);
}
}
} }
public void playerRefreshEntiyt(String name){ public void playerRefreshEntiyt(String name){

View File

@ -1,3 +1,3 @@
RefreshTime: 10 #刷新时间单位为s RefreshTime: 10 #刷新时间单位为s
total: 12 #每个玩家每次刷新的实体数量 total: 12 #每个玩家每次刷新的实体数量
num: 4 #单次刷新的最大数量每RefreshTime秒刷新的数量 num: 4 #单次刷新的最大数量每RefreshTime秒刷新的数量

View File

@ -10,6 +10,7 @@ DESERT:
yMin: 60 #最小刷新高度 yMin: 60 #最小刷新高度
riskMax: 10 #刷新危险度的范围 riskMax: 10 #刷新危险度的范围
riskMin: 0 #条件是小于等于riskMin大于riskMax即riskMin<= risklevel < riskMax 才会刷新 riskMin: 0 #条件是小于等于riskMin大于riskMax即riskMin<= risklevel < riskMax 才会刷新
weight: 1.0 #权重越高刷新的概率越高最高为1.0
ROOFED_FOREST: ROOFED_FOREST:
ZOMBIE: #指出entity在该群系的刷新条件 ZOMBIE: #指出entity在该群系的刷新条件
type: 0 #0表示生成mc原生实体1表示生成MM怪物2表示生成萌芽怪物 type: 0 #0表示生成mc原生实体1表示生成MM怪物2表示生成萌芽怪物

View File

@ -1,3 +1,3 @@
RefreshTime: 10 #刷新时间单位为s RefreshTime: 10 #刷新时间单位为s
total: 12 #每个玩家每次刷新的实体数量 total: 12 #每个玩家每次刷新的实体数量
num: 4 #单次刷新的数量每RefreshTime秒刷新的数量 num: 4 #单次刷新的最大数量每RefreshTime秒刷新的数量