From 3ca0f1f96060702a5925af2fffb0f488c08a89e6 Mon Sep 17 00:00:00 2001 From: yuyu <124714592@qq.com> Date: Sun, 14 Apr 2024 22:31:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=9D=83=E9=87=8D?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=EF=BC=8C=E5=B9=B6=E4=B8=94=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=86=E7=8E=A9=E5=AE=B6=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=90=8E=E5=86=8D=E7=99=BB=E5=BD=95=E5=90=8Edsp=20clear?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E4=BC=9A=E5=88=B7=E4=B8=8D=E6=8E=89=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=AE=9E=E4=BD=93=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../srwildentity/config/ConfigManager.java | 1 + .../condition/BiomeEntityRefreshSettings.java | 3 +- .../config/condition/EntityCondition.java | 11 ++++- .../listener/EntityRefreshListener.java | 45 ++++++++++++++----- src/main/resources/config.yml | 2 +- src/main/resources/entityCondition.yml | 1 + target/classes/config.yml | 2 +- 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/yuyu/srwildentity/config/ConfigManager.java b/src/main/java/com/yuyu/srwildentity/config/ConfigManager.java index f175dae..8d7c5a5 100644 --- a/src/main/java/com/yuyu/srwildentity/config/ConfigManager.java +++ b/src/main/java/com/yuyu/srwildentity/config/ConfigManager.java @@ -51,4 +51,5 @@ public class ConfigManager { public int getTotal() { return total; } + } diff --git a/src/main/java/com/yuyu/srwildentity/config/condition/BiomeEntityRefreshSettings.java b/src/main/java/com/yuyu/srwildentity/config/condition/BiomeEntityRefreshSettings.java index 05e7170..e821676 100644 --- a/src/main/java/com/yuyu/srwildentity/config/condition/BiomeEntityRefreshSettings.java +++ b/src/main/java/com/yuyu/srwildentity/config/condition/BiomeEntityRefreshSettings.java @@ -57,8 +57,9 @@ public class BiomeEntityRefreshSettings { 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); + spawnEntityType,entitySite, light, stime,etime, nums, yMax, yMin,riskMax,riskMin,weight); plugin.getLogger().info(ChatColor.AQUA+entityCondition.toString()); diff --git a/src/main/java/com/yuyu/srwildentity/config/condition/EntityCondition.java b/src/main/java/com/yuyu/srwildentity/config/condition/EntityCondition.java index 5d8b611..6b3b989 100644 --- a/src/main/java/com/yuyu/srwildentity/config/condition/EntityCondition.java +++ b/src/main/java/com/yuyu/srwildentity/config/condition/EntityCondition.java @@ -22,8 +22,11 @@ public class EntityCondition { private final int yMin; private final int riskMax; 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.biome = biome; this.spawnEntityType = spawnEntityType; @@ -36,6 +39,7 @@ public class EntityCondition { this.yMin = yMin; this.riskMax = riskMax; this.riskMin = riskMin; + this.weight = weight; } public SpawnEntityType getSpawnEntityType() { @@ -90,6 +94,10 @@ public class EntityCondition { return yMin; } + public double getWeight() { + return weight; + } + @Override public String toString() { return "EntityCondition{" + @@ -105,6 +113,7 @@ public class EntityCondition { ", yMin=" + yMin + ", riskMax=" + riskMax + ", riskMin=" + riskMin + + ", weight=" + weight + '}'; } } diff --git a/src/main/java/com/yuyu/srwildentity/listener/EntityRefreshListener.java b/src/main/java/com/yuyu/srwildentity/listener/EntityRefreshListener.java index 5488922..579bd57 100644 --- a/src/main/java/com/yuyu/srwildentity/listener/EntityRefreshListener.java +++ b/src/main/java/com/yuyu/srwildentity/listener/EntityRefreshListener.java @@ -243,20 +243,19 @@ public class EntityRefreshListener implements Listener, CommandExecutor { * @param event */ @EventHandler - public void onPlayerOffOnline(PlayerQuitEvent event){ - if (flag) { + public void onPlayerOffOnline(PlayerQuitEvent event) { + if (flag) { Player player = event.getPlayer(); String name = player.getName(); //下线后移出刷新列表 - if (refreshPlayer.get(name) != null) { - List entityList = refreshPlayer.get(name).getEntityList(); - for (UUID uuid : entityList){ - //删除储存的实体信息 - entityUUIDToPlayer.remove(uuid); - } - refreshPlayer.remove(name); - logger.info(ChatColor.GOLD + "玩家被移出刷新集合"); - } +// if (refreshPlayer.get(name) != null) { +// List entityList = refreshPlayer.get(name).getEntityList(); +// for (UUID uuid : entityList){ +// //删除储存的实体信息 +// entityUUIDToPlayer.remove(uuid); +// } + refreshPlayer.remove(name); + logger.info(ChatColor.GOLD + "玩家被移出刷新集合"); } } @@ -295,7 +294,9 @@ public class EntityRefreshListener implements Listener, CommandExecutor { //通过uuid获取对应的玩家姓名,然后通过玩家姓名获取对应的list集合 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)){ continue; } + int attempts = 0; int sum = 0;//用于记录此次刷新生成的总数 //获取玩家信息 Player player = plugin.getServer().getPlayer(name); @@ -363,6 +365,11 @@ public class EntityRefreshListener implements Listener, CommandExecutor { continue; } + if (random.nextFloat() > entityCondition.getWeight()){ + //刷新不通过,进入下一个验证的实体 + continue; + } + int nums = entityCondition.getNums();//当前实体需要刷新的数量 for (int i = 0;i()); } + + 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){ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 975d1d1..3a5708d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,3 +1,3 @@ RefreshTime: 10 #刷新时间,单位为s total: 12 #每个玩家每次刷新的实体数量 -num: 4 #单次刷新的最大数量,每RefreshTime秒刷新的数量 \ No newline at end of file +num: 4 #单次刷新的最大数量,每RefreshTime秒刷新的数量 diff --git a/src/main/resources/entityCondition.yml b/src/main/resources/entityCondition.yml index 61cb99b..71b619a 100644 --- a/src/main/resources/entityCondition.yml +++ b/src/main/resources/entityCondition.yml @@ -10,6 +10,7 @@ DESERT: yMin: 60 #最小刷新高度 riskMax: 10 #刷新危险度的范围 riskMin: 0 #条件是小于等于riskMin大于riskMax,即riskMin<= risklevel < riskMax 才会刷新 + weight: 1.0 #权重越高,刷新的概率越高,最高为1.0 ROOFED_FOREST: ZOMBIE: #指出entity在该群系的刷新条件 type: 0 #0表示生成mc原生实体,1表示生成MM怪物,2表示生成萌芽怪物 diff --git a/target/classes/config.yml b/target/classes/config.yml index 5779930..3a5708d 100644 --- a/target/classes/config.yml +++ b/target/classes/config.yml @@ -1,3 +1,3 @@ RefreshTime: 10 #刷新时间,单位为s total: 12 #每个玩家每次刷新的实体数量 -num: 4 #单次刷新的数量,每RefreshTime秒刷新的数量 \ No newline at end of file +num: 4 #单次刷新的最大数量,每RefreshTime秒刷新的数量