区域刷新,区域黑名单,世界黑名单完成

This commit is contained in:
yuyu 2024-07-15 20:54:59 +08:00
parent 3ca0f1f960
commit 14dbe32c26
23 changed files with 563 additions and 259 deletions

3
.idea/compiler.xml generated
View File

@ -9,8 +9,5 @@
<module name="SrWildEntity" /> <module name="SrWildEntity" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel>
<module name="SrWildEntity" target="1.8" />
</bytecodeTargetLevel>
</component> </component>
</project> </project>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: com.google.code.gson:gson:2.8.0">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/com/google/code/gson/gson/2.8.0/gson-2.8.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/com/google/code/gson/gson/2.8.0/gson-2.8.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/com/google/code/gson/gson/2.8.0/gson-2.8.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: com.google.guava:guava:21.0">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/com/google/guava/guava/21.0/guava-21.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/com/google/guava/guava/21.0/guava-21.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/com/google/guava/guava/21.0/guava-21.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: com.googlecode.json-simple:json-simple:1.1.1">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: commons-lang:commons-lang:2.6">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: junit:junit:4.10">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/junit/junit/4.10/junit-4.10.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/junit/junit/4.10/junit-4.10-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/junit/junit/4.10/junit-4.10-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180712.114550-97.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180712.114550-97-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180712.114550-97-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.hamcrest:hamcrest-core:1.1">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180712.012057-156.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180712.012057-156-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180712.012057-156-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.yaml:snakeyaml:1.19">
<CLASSES>
<root url="jar://$USER_HOME$/.m2/repository/org/yaml/snakeyaml/1.19/snakeyaml-1.19.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.m2/repository/org/yaml/snakeyaml/1.19/snakeyaml-1.19-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.m2/repository/org/yaml/snakeyaml/1.19/snakeyaml-1.19-sources.jar!/" />
</SOURCES>
</library>
</component>

1
.idea/misc.xml generated
View File

@ -5,6 +5,7 @@
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" /> <item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
</list> </list>
</component> </component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager"> <component name="MavenProjectsManager">
<option name="originalFiles"> <option name="originalFiles">
<list> <list>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module version="4">
<component name="FacetManager"> <component name="FacetManager">
<facet type="minecraft" name="Minecraft"> <facet type="minecraft" name="Minecraft">
<configuration> <configuration>
@ -9,25 +9,4 @@
</configuration> </configuration>
</facet> </facet>
</component> </component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" />
</component>
</module> </module>

View File

@ -1,6 +1,8 @@
package com.yuyu.srwildentity; package com.yuyu.srwildentity;
import com.yuyu.srwildentity.JDBC.JdbcSqlClass;
import com.yuyu.srwildentity.config.ConfigManager; import com.yuyu.srwildentity.config.ConfigManager;
import com.yuyu.srwildentity.listener.AreaRefershListener;
import com.yuyu.srwildentity.listener.EntityRefreshListener; import com.yuyu.srwildentity.listener.EntityRefreshListener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -21,18 +23,21 @@ import org.bukkit.plugin.java.JavaPlugin;
public final class SrWildEntity extends JavaPlugin implements CommandExecutor { public final class SrWildEntity extends JavaPlugin implements CommandExecutor {
private EntityRefreshListener entityRefreshListener; private EntityRefreshListener entityRefreshListener;
private AreaRefershListener areaRefershListener;
@Override @Override
public void onEnable() { public void onEnable() {
getLogger().info(ChatColor.AQUA+"SrWildEntity开始运行"); getLogger().info(ChatColor.AQUA+"SrWildEntity开始运行");
onload(); ConfigManager onload = onload();
//TODO(注册监听类,测试) //TODO(注册监听类,测试)
this.entityRefreshListener = new EntityRefreshListener(this.getLogger(),onload(),this); this.entityRefreshListener = new EntityRefreshListener(this.getLogger(),onload,this);
this.areaRefershListener = new AreaRefershListener(onload);
Bukkit.getPluginManager().registerEvents(entityRefreshListener,this); Bukkit.getPluginManager().registerEvents(entityRefreshListener,this);
Bukkit.getPluginManager().registerEvents(areaRefershListener,this);
//注册定时任务 //注册定时任务
this.getServer().getScheduler().scheduleSyncRepeatingTask this.getServer().getScheduler().scheduleSyncRepeatingTask
@ -58,6 +63,9 @@ public final class SrWildEntity extends JavaPlugin implements CommandExecutor {
@Override @Override
public void onDisable() { public void onDisable() {
//关闭时保存数据
JdbcSqlClass.deleteData();
JdbcSqlClass.saveData(areaRefershListener.getUuidStringHashMap());
} }
/** /**
@ -86,7 +94,9 @@ public final class SrWildEntity extends JavaPlugin implements CommandExecutor {
getLogger().info(ChatColor.AQUA+"SrWildEntity重新读取配置文件"); getLogger().info(ChatColor.AQUA+"SrWildEntity重新读取配置文件");
commandSender.sendMessage(ChatColor.YELLOW+"SrWildEntity重新读取配置文件"); commandSender.sendMessage(ChatColor.YELLOW+"SrWildEntity重新读取配置文件");
entityRefreshListener.setConfigManager(this.onload()); ConfigManager onload = this.onload();
entityRefreshListener.setConfigManager(onload);
areaRefershListener.setConfigManager(onload);
//注册定时任务 //注册定时任务
this.getServer().getScheduler().scheduleSyncRepeatingTask this.getServer().getScheduler().scheduleSyncRepeatingTask

View File

@ -7,6 +7,8 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import java.util.HashSet;
/** /**
* @BelongsProject: SrWildEntity * @BelongsProject: SrWildEntity
* @BelongsPackage: com.yuyu.srwildentity.conditionCheck * @BelongsPackage: com.yuyu.srwildentity.conditionCheck
@ -17,6 +19,11 @@ import org.bukkit.block.Block;
* @Description: 用于检查是否通过 * @Description: 用于检查是否通过
*/ */
public class ConditionCheck { public class ConditionCheck {
//实体碰撞
public static final HashSet<Material> noEntityCollision = new HashSet<>();
/** /**
* 检查entity生成位置是否符合 * 检查entity生成位置是否符合
* 1.位置 * 1.位置
@ -30,12 +37,31 @@ public class ConditionCheck {
*/ */
public static boolean checkEntityRefresh(World world, Location location, EntityCondition entityCondition){ public static boolean checkEntityRefresh(World world, Location location, EntityCondition entityCondition){
return checkLocation(world,location,entityCondition.getEntitySite()) return (checkLocation(world,location,entityCondition.getEntitySite())
&& checkLight(world,location,entityCondition.getLight()) && checkLight(world,location,entityCondition.getLight())
&& checkTimed(world,entityCondition.getStartTiming(), entityCondition.getEndTimeing()) && checkTimed(world,entityCondition.getStartTiming(), entityCondition.getEndTimeing())
&& checkY(location,entityCondition.getyMax(), entityCondition.getyMin()); && checkY(location,entityCondition.getyMax(), entityCondition.getyMin()));
} }
// private static boolean checkHeight(Location location, World world) {
// int blockY = location.getBlockY();
// for (int i = 1;i<2;i++){
// blockY+=2;
// location.setY(blockY);
// Block block = location.getBlock();
// if(block.getType() != Material.AIR
// && block.getType() != Material.WATER
// && block.getType() != Material.STATIONARY_WATER
// && block.getType() != Material.LONG_GRASS
// && block.getType() != Material.YELLOW_FLOWER
// && block.getType() != Material.FLOWER_POT
// && block.getType() != Material.CHORUS_FLOWER){
// return false;
// }
// }
// return true;
// }
/** /**
* 检查刷新位置 * 检查刷新位置
* @param world * @param world
@ -50,8 +76,17 @@ public class ConditionCheck {
} }
if (entitySite == EntitySite.ON_GROUND){ if (entitySite == EntitySite.ON_GROUND){
Block blockAt = world.getBlockAt(location); //实体的刷新位置
return blockAt.getType().name().equals(Material.AIR.name()); Block block = world.getBlockAt(location);
//实体的落脚点
Block blockAt = world.getBlockAt(new Location(world,location.getBlockX(),location.getBlockY() + 1,location.getBlockZ()));
Block blockAt0 = world.getBlockAt(new Location(world,location.getBlockX(),location.getBlockY() + 2,location.getBlockZ()));
Block blockAt1 = world.getBlockAt(new Location(world,location.getBlockX(),location.getBlockY() - 1,location.getBlockZ()));
return (noEntityCollision.contains(block.getType()) &&
noEntityCollision.contains(blockAt.getType()) &&
!noEntityCollision.contains(blockAt1.getType()) &&
noEntityCollision.contains(blockAt0.getType()));
} }
if (entitySite == EntitySite.NULL){ if (entitySite == EntitySite.NULL){

View File

@ -1,11 +1,24 @@
package com.yuyu.srwildentity.config; package com.yuyu.srwildentity.config;
import com.yuyu.srwildentity.JDBC.JdbcSqlClass;
import com.yuyu.srwildentity.conditionCheck.ConditionCheck;
import com.yuyu.srwildentity.config.condition.BiomeEntityRefreshSettings; import com.yuyu.srwildentity.config.condition.BiomeEntityRefreshSettings;
import com.yuyu.srwildentity.config.condition.EntityCondition;
import com.yuyu.srwildentity.config.condition.EntitySite;
import com.yuyu.srwildentity.config.condition.SpawnEntityType;
import com.yuyu.srwildentity.pojo.AreaRefresh;
import com.yuyu.srwildentity.pojo.BlackListArea;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
/** /**
* @BelongsProject: SrWildEntity * @BelongsProject: SrWildEntity
@ -21,19 +34,175 @@ public class ConfigManager {
private final int refreshTime; private final int refreshTime;
private final int total; private final int total;
private final int num; private final int num;
private final int attempts;
private final int LEVEL;
private final HashMap<String, List<BlackListArea>> blackListAreaMap;
private final HashSet<String> blacklistWorldSet;
private final HashMap<String, AreaRefresh> areaRefreshHashMap;
public ConfigManager(Plugin plugin) { public ConfigManager(Plugin plugin) {
//加载配置文件
this.biomeEntityRefreshSettings = new BiomeEntityRefreshSettings(plugin);
//保存配置文件 //保存配置文件
plugin.saveResource("config.yml",false); plugin.saveResource("config.yml",false);
FileConfiguration config; FileConfiguration config;
File file = new File(plugin.getDataFolder(), "config.yml"); File file = new File(plugin.getDataFolder(), "config.yml");
config = YamlConfiguration.loadConfiguration(file); config = YamlConfiguration.loadConfiguration(file);
this.refreshTime = config.getInt("RefreshTime"); this.refreshTime = config.getInt("RefreshTime");
this.total = config.getInt("total"); this.total = config.getInt("total");
this.num = config.getInt("num"); this.num = config.getInt("num");
this.LEVEL = config.getInt("LEVEL_MAX");
this.attempts = config.getInt("attempts");
this.blackListAreaMap = new HashMap<>();
this.blacklistWorldSet = new HashSet<>();
this.areaRefreshHashMap = new HashMap<>();
//加载配置文件
this.biomeEntityRefreshSettings = new BiomeEntityRefreshSettings(plugin,LEVEL);
this.loadEntityCheck();
this.loadBlacklistWorld(plugin);
this.loadBlacklistArea(plugin);
this.loadAreaRefresh(plugin);
this.loadDataBase(plugin);
JdbcSqlClass.initTable();
JdbcSqlClass.setChartseUtf8();
}
private void loadEntityCheck() {
ConditionCheck.noEntityCollision.add(Material.AIR);
ConditionCheck.noEntityCollision.add(Material.GRASS);
ConditionCheck.noEntityCollision.add(Material.SAPLING);
ConditionCheck.noEntityCollision.add(Material.WATER);
ConditionCheck.noEntityCollision.add(Material.STATIONARY_WATER);
ConditionCheck.noEntityCollision.add(Material.LAVA);
ConditionCheck.noEntityCollision.add(Material.STATIONARY_LAVA);
ConditionCheck.noEntityCollision.add(Material.POWERED_RAIL);
ConditionCheck.noEntityCollision.add(Material.DETECTOR_RAIL);
ConditionCheck.noEntityCollision.add(Material.WEB);
ConditionCheck.noEntityCollision.add(Material.LONG_GRASS);
ConditionCheck.noEntityCollision.add(Material.DEAD_BUSH);
ConditionCheck.noEntityCollision.add(Material.RED_ROSE);
ConditionCheck.noEntityCollision.add(Material.BROWN_MUSHROOM);
ConditionCheck.noEntityCollision.add(Material.RED_MUSHROOM);
ConditionCheck.noEntityCollision.add(Material.TORCH);
ConditionCheck.noEntityCollision.add(Material.FIRE);
ConditionCheck.noEntityCollision.add(Material.REDSTONE_WIRE);
ConditionCheck.noEntityCollision.add(Material.CROPS);
ConditionCheck.noEntityCollision.add(Material.SIGN_POST);
ConditionCheck.noEntityCollision.add(Material.LADDER);
ConditionCheck.noEntityCollision.add(Material.RAILS);
ConditionCheck.noEntityCollision.add(Material.WALL_SIGN);
ConditionCheck.noEntityCollision.add(Material.REDSTONE_TORCH_OFF);
ConditionCheck.noEntityCollision.add(Material.REDSTONE_TORCH_ON);
ConditionCheck.noEntityCollision.add(Material.STONE_BUTTON);
ConditionCheck.noEntityCollision.add(Material.SNOW);
ConditionCheck.noEntityCollision.add(Material.SUGAR_CANE_BLOCK);
ConditionCheck.noEntityCollision.add(Material.PUMPKIN_STEM);
ConditionCheck.noEntityCollision.add(Material.MELON_STEM);
ConditionCheck.noEntityCollision.add(Material.VINE);
ConditionCheck.noEntityCollision.add(Material.WATER_LILY);
ConditionCheck.noEntityCollision.add(Material.NETHER_WARTS);
ConditionCheck.noEntityCollision.add(Material.CARROT);
ConditionCheck.noEntityCollision.add(Material.POTATO);
ConditionCheck.noEntityCollision.add(Material.BEETROOT);
}
public void loadBlacklistArea(Plugin plugin){
plugin.saveResource("blacklistArea.yml",false);
FileConfiguration config;
File file = new File(plugin.getDataFolder(), "blacklistArea.yml");
config = YamlConfiguration.loadConfiguration(file);
int blacklistNums = config.getInt("blacklistNums");
for (int i = 1; i <= blacklistNums; i++) {
String locationX = "blacklist_"+i;
BlackListArea blackListArea = new BlackListArea(config.getString(
locationX + "." + "world_name"),
config.getInt(locationX +"." +"x1"),
config.getInt(locationX +"." +"z1"),
config.getInt(locationX +"." +"x2"),
config.getInt(locationX +"." +"z2"));
if (blackListAreaMap.containsKey(blackListArea.getWorldName())) {
blackListAreaMap.get(blackListArea.getWorldName()).add(blackListArea);
}else {
List<BlackListArea> blackListAreas = new ArrayList<>();
blackListAreas.add(blackListArea);
blackListAreaMap.put(blackListArea.getWorldName(), blackListAreas);
}
}
}
public void loadAreaRefresh(Plugin plugin) {
FileConfiguration config;
File file = new File(plugin.getDataFolder(), "areaRefresh.yml");
config = YamlConfiguration.loadConfiguration(file);
FileConfiguration configuration;
File file2 = new File(plugin.getDataFolder(), "area_Entity.yml");
configuration = YamlConfiguration.loadConfiguration(file2);
int areaNumber = config.getInt("Area_Number");
for (int i = 1; i <= areaNumber; i++) {
String areaName = "area_"+i;
List<String> entityList = config.getStringList(areaName + ".refreshList");
String worldName = config.getString(areaName + ".worldName");
int x1 = config.getInt(areaName + ".x1");
int z1 = config.getInt(areaName + ".z1");
int x2 = config.getInt(areaName + ".x2");
int z2 = config.getInt(areaName + ".z2");
int y1 = config.getInt(areaName + ".yMax");
int y2 = config.getInt(areaName + ".yMin");
HashMap<String,EntityCondition> entityConditions = new HashMap<>();
//获取刷新列表
for (String entity : entityList) {
SpawnEntityType spawnEntityType = SpawnEntityType.fromId(configuration.getInt(areaName + "." + entity + ".type"));
EntitySite entitySite = EntitySite.fromId(configuration.getInt(areaName + "." + entity + ".site"));
int light = configuration.getInt(areaName + "." + entity + ".light");
long refreshTime = configuration.getLong(areaName + "." + entity + ".refreshTime");
int nums = configuration.getInt(areaName + "." + entity + ".nums");
int yMax = configuration.getInt(areaName + "." + entity + ".yMax");
int yMin = configuration.getInt(areaName + "." + entity + ".yMin");
double weight = configuration.getDouble(areaName + "." + entity + ".weight");
EntityCondition entityCondition = new EntityCondition(entity, null,
spawnEntityType, entitySite, light, 0, 24000, nums, yMax, yMin, 50, 0, weight,refreshTime);
entityConditions.put(entity, entityCondition);
}
this.areaRefreshHashMap.put(areaName,new AreaRefresh(x1, z1, x2, z2, worldName, entityConditions,y1 , y2,areaName));
}
}
public void loadBlacklistWorld(Plugin plugin){
plugin.saveResource("blacklistWorld.yml",false);
FileConfiguration config;
File file = new File(plugin.getDataFolder(), "blacklistWorld.yml");
config = YamlConfiguration.loadConfiguration(file);
List<String> stringList = config.getStringList("blacklistWorld");
for (String string : stringList) {
this.blacklistWorldSet.add(string);
}
}
public HashSet<String> getBlacklistWorldSet() {
return blacklistWorldSet;
}
public int getAttempts() {
return attempts;
}
public int getLEVEL() {
return LEVEL;
} }
public BiomeEntityRefreshSettings getBiomeEntityRefreshSettings() { public BiomeEntityRefreshSettings getBiomeEntityRefreshSettings() {
@ -52,4 +221,31 @@ public class ConfigManager {
return total; return total;
} }
public HashMap<String, AreaRefresh> getAreaRefreshHashMap() {
return areaRefreshHashMap;
}
public void loadDataBase(Plugin plugin){
plugin.saveResource("datasource.yml",false);
File datasource = new File(plugin.getDataFolder(), "datasource.yml");
FileConfiguration datasourceConfig = YamlConfiguration.loadConfiguration(datasource);
JdbcSqlClass.setUser(datasourceConfig.getString("database.sql.username"));
JdbcSqlClass.setPassword(datasourceConfig.getString("database.sql.password"));
JdbcSqlClass.setDriver(datasourceConfig.getString("database.sql.driver"));
JdbcSqlClass.setUrl(datasourceConfig.getString("database.sql.url"));
plugin.getLogger().info(ChatColor.GREEN+"username:"+JdbcSqlClass.getUser()+"\npassword:"+JdbcSqlClass.getPassword()
+"\ndriver:"+JdbcSqlClass.getDriver()+"\nurl:"+JdbcSqlClass.getUrl());
JdbcSqlClass.initTable();
JdbcSqlClass.setChartseUtf8();
}
public HashMap<String, List<BlackListArea>> getBlackListAreaMap() {
return blackListAreaMap;
}
} }

View File

@ -6,6 +6,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -19,61 +20,26 @@ import java.util.List;
* @Description: 读取实体刷新的配置相关文件 * @Description: 读取实体刷新的配置相关文件
*/ */
public class BiomeEntityRefreshSettings { public class BiomeEntityRefreshSettings {
private final HashMap<String,List<String>> biomeEntityMap;//此集合储存了群系内需要刷新的怪物 // private final HashMap<String,List<String>> biomeEntityMap;//此集合储存了群系内需要刷新的怪物
//
private final HashMap<String,HashMap<String,EntityCondition>> biomeEntityConditionMap;//此集合储存需要刷新的怪物的相关配置 // private final HashMap<String,HashMap<String,EntityCondition>> biomeEntityConditionMap;//此集合储存需要刷新的怪物的相关配置
private final List<LevelRefresh> levelRefreshesList;
public BiomeEntityRefreshSettings(Plugin plugin) { public BiomeEntityRefreshSettings(Plugin plugin,int levelMax) {
this.biomeEntityMap = new HashMap<>(); // this.biomeEntityMap = new HashMap<>();
this.biomeEntityConditionMap = new HashMap<>(); // this.biomeEntityConditionMap = new HashMap<>();
this.levelRefreshesList = new ArrayList<>();
this.loadBiomeEntitiesConfig(plugin); // this.loadBiomeEntitiesConfig(plugin,levelMax);
//
// this.loadEntityConditionConfig(plugin,levelMax);
this.loadEntityConditionConfig(plugin); this.loadRefreshEntity(plugin,levelMax);
} }
private void loadEntityConditionConfig(Plugin plugin) { private void loadRefreshEntity(Plugin plugin,int level){
//保存文件
plugin.saveResource("entityCondition.yml",false);
FileConfiguration config;
File file = new File(plugin.getDataFolder(), "entityCondition.yml");
config = YamlConfiguration.loadConfiguration(file);
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){
//保存文件 //保存文件
plugin.saveResource("biomeEntity.yml",false); plugin.saveResource("biomeEntity.yml",false);
@ -94,26 +60,168 @@ public class BiomeEntityRefreshSettings {
plugin.getLogger().info("biomeEntity.yml或者 biome.yml文件读取失败!"); plugin.getLogger().info("biomeEntity.yml或者 biome.yml文件读取失败!");
return; return;
} }
// 等级 群系 实体列表
HashMap<String,HashMap<String,List<String>>> levelBiomeMap = new HashMap<>();
//遍历所有可能的生物群系 //按level循环
for (String section : biomeList){ for (int i = 1;i <= level;i++){
//判断是否存在 HashMap<String,List<String>> biomeMap = new HashMap<>();
if (config.contains(section)){ //按群系循环
List<String> entityList = config.getStringList(section+".ENTITY"); for (String biome : biomeList){
this.biomeEntityMap.put(section,entityList); //判断该群系是否存在该等级的配置
plugin.getLogger().info(ChatColor.MAGIC+section+ entityList.toString()); if (config.contains(biome)){
//获取到后保存
List<String> stringList = config.getStringList(biome + ".ENTITY_LEVEL_" + i);
if (stringList.size() > 0) {
biomeMap.put(biome, stringList);
}
}
} }
levelBiomeMap.put("level_"+i,biomeMap);
} }
plugin.getLogger().info("biomeEntity.读取完成"); 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<>();
for (String biome : stringListHashMap.keySet()){
List<EntityCondition> entityConditions = new ArrayList<>();
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());
}
//此处按群系储存list
listHashMap.put(biome,entityConditions);
}
//此处按等级储存对应等级的LevelRefresh对象
this.levelRefreshesList.add(new LevelRefresh(riskMax,riskMin,listHashMap));
}
} }
public HashMap<String, List<String>> getBiomeEntityMap() { // private void loadEntityConditionConfig(Plugin plugin,int levelMax) {
return biomeEntityMap; //
} // //保存文件
// 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 HashMap<String, HashMap<String, EntityCondition>> getBiomeEntityConditionMap() { // public HashMap<String, List<String>> getBiomeEntityMap() {
return biomeEntityConditionMap; // return biomeEntityMap;
} // }
//
// public HashMap<String, HashMap<String, EntityCondition>> getBiomeEntityConditionMap() {
// return biomeEntityConditionMap;
// }
public List<LevelRefresh> getLevelRefreshesList() {
return levelRefreshesList;
}
} }

View File

@ -23,7 +23,26 @@ public class EntityCondition {
private final int riskMax; private final int riskMax;
private final int riskMin; private final int riskMin;
private final double weight; private final double weight;
private long refreshTime;
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, long refreshTime) {
this.entityName = entityName;
this.biome = biome;
this.spawnEntityType = spawnEntityType;
this.entitySite = entitySite;
this.light = light;
this.startTiming = startTiming;
this.endTimeing = endTiming;
this.nums = nums;
this.yMax = yMax;
this.yMin = yMin;
this.riskMax = riskMax;
this.riskMin = riskMin;
this.weight = weight;
this.refreshTime = refreshTime;
}
public EntityCondition(String entityName, String biome, SpawnEntityType spawnEntityType, EntitySite entitySite, public EntityCondition(String entityName, String biome, SpawnEntityType spawnEntityType, EntitySite entitySite,
int light, long startTiming, long endTiming, int nums, int light, long startTiming, long endTiming, int nums,
int yMax, int yMin,int riskMax,int riskMin, double weight) { int yMax, int yMin,int riskMax,int riskMin, double weight) {
@ -98,6 +117,10 @@ public class EntityCondition {
return weight; return weight;
} }
public long getRefreshTime() {
return refreshTime;
}
@Override @Override
public String toString() { public String toString() {
return "EntityCondition{" + return "EntityCondition{" +

View File

@ -10,13 +10,16 @@ import com.yuyu.srwildentity.conditionCheck.ConditionCheck;
import com.yuyu.srwildentity.config.ConfigManager; import com.yuyu.srwildentity.config.ConfigManager;
import com.yuyu.srwildentity.config.condition.EntityCondition; import com.yuyu.srwildentity.config.condition.EntityCondition;
import com.yuyu.srwildentity.config.condition.EntitySite; import com.yuyu.srwildentity.config.condition.EntitySite;
import com.yuyu.srwildentity.config.condition.LevelRefresh;
import com.yuyu.srwildentity.config.condition.SpawnEntityType; import com.yuyu.srwildentity.config.condition.SpawnEntityType;
import com.yuyu.srwildentity.pojo.BlackListArea;
import com.yuyu.srwildentity.pojo.PlayerRefreshinfo; import com.yuyu.srwildentity.pojo.PlayerRefreshinfo;
import io.lumine.xikage.mythicmobs.MythicMobs; import io.lumine.xikage.mythicmobs.MythicMobs;
import io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException; import io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -132,7 +135,7 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
}else { }else {
String choice = strings[0];//只能是onoff或者clear String choice = strings[0];//只能是onoff或者clear
if (choice.equalsIgnoreCase("on") || choice.equalsIgnoreCase("off") if (choice.equalsIgnoreCase("on") || choice.equalsIgnoreCase("off")
|| choice.equalsIgnoreCase("clear")){ || choice.equalsIgnoreCase("clear") || choice.equalsIgnoreCase("location")){
if (choice.equalsIgnoreCase("on")){ if (choice.equalsIgnoreCase("on")){
Player player = plugin.getServer().getPlayer(strings[1]); Player player = plugin.getServer().getPlayer(strings[1]);
if (player == null){ if (player == null){
@ -157,12 +160,24 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
commandSender.sendMessage(ChatColor.YELLOW+strings[1]+"停止刷怪"); commandSender.sendMessage(ChatColor.YELLOW+strings[1]+"停止刷怪");
return true; return true;
} }
}else { }else if (choice.equalsIgnoreCase("clear")){
//清空刷新的怪物 //清空刷新的怪物
this.clearRefreshEntity(); this.clearRefreshEntity();
logger.info(ChatColor.GOLD+"SrWildEntity刷新的所有实体被清除!"); logger.info(ChatColor.GOLD+"SrWildEntity刷新的所有实体被清除!");
commandSender.sendMessage(ChatColor.GOLD+"SrWildEntity刷新的所有实体被清除!"); commandSender.sendMessage(ChatColor.GOLD+"SrWildEntity刷新的所有实体被清除!");
return true; return true;
}else if (choice.equalsIgnoreCase("location")){
if (commandSender instanceof Player){
Player player = (Player) commandSender;
Location location = player.getLocation();
player.sendMessage(ChatColor.GREEN+"x:"+location.getBlockX()+"\ty:"
+location.getBlockY()+"\tz:"+location.getBlockZ()+"\tworld:"+location.getWorld().getName());
logger.info(ChatColor.GREEN+"x:"+location.getBlockX()+"\ty:"
+location.getBlockY()+"\tz:"+location.getBlockZ()+"\tworld:"+location.getWorld().getName());
return true;
}else {
return false;
}
} }
} }
} }
@ -308,65 +323,102 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
public void timedRdfreshEneity(){ public void timedRdfreshEneity(){
if (flag) { if (flag) {
int num = configManager.getNum();//每次执行时刷新的总数 int num = configManager.getNum();//每次执行时刷新的总数
//遍历需要刷新的玩家
tag:
for (String name : refreshPlayer.keySet()) { for (String name : refreshPlayer.keySet()) {
if (noRefreshPlayer.contains(name)){ if (noRefreshPlayer.contains(name)){
continue; continue;
} }
int attempts = 0; int attempts = 0;
int sum = 0;//用于记录此次刷新生成的总数 int sum = 0;//用于记录此次刷新生成的总数
//获取玩家信息 //获取玩家信息
Player player = plugin.getServer().getPlayer(name); Player player = plugin.getServer().getPlayer(name);
PlayerRefreshinfo playerRefreshinfo = refreshPlayer.get(name); PlayerRefreshinfo playerRefreshinfo = refreshPlayer.get(name);
Location playerlocation = player.getLocation();
World world = playerlocation.getWorld();
String worldName = world.getName();
boolean pass = false;
//如果黑名单的set集合里面包含有该世界的名字则跳过该玩家
if (configManager.getBlacklistWorldSet().contains(worldName)){
continue;
}
if (configManager.getBlackListAreaMap().containsKey(worldName)){
List<BlackListArea> blackListAreas = configManager.getBlackListAreaMap().get(worldName);
for (BlackListArea blackListArea : blackListAreas){
int blockX = playerlocation.getBlockX();
int blockZ = playerlocation.getBlockZ();
if (blackListArea.getX1() >= blockX && blockX >= blackListArea.getX2()
&& blackListArea.getY1() >= blockZ && blockZ >= blackListArea.getY2()){
//tag为循环标志此处会直接结束tag标志处的循环
continue tag;
}
}
}
//玩家危险度,用于刷新实体的等级 //玩家危险度,用于刷新实体的等级
int level = this.prRisk(player); int riskLevel = this.prRisk(player);
//TODO(危险度提示,后续需要使用这个变量去控制怪物的参数等级`) if (riskLevel == 0){
logger.info(ChatColor.GREEN + "危险度为:" + level); //等于0不刷新怪物,直接跳过
continue;
}
LevelRefresh refreshList = null;
List<LevelRefresh> levelRefreshesList = configManager.getBiomeEntityRefreshSettings().getLevelRefreshesList();
for (LevelRefresh levelRefresh : levelRefreshesList){
if (riskLevel > levelRefresh.getRiskMin() && riskLevel <= levelRefresh.getRiskMax()){
refreshList = levelRefresh;
}
}
if (refreshList == null){
logger.info(ChatColor.MAGIC+name+"所在群系"+"没有危险度为:"+riskLevel+"时适配的刷新列表");
continue;
}
Location playerlocation = player.getLocation();
//获取玩家位置信息 //获取玩家位置信息
World world = playerlocation.getWorld();
int blockZ = playerlocation.getBlockZ(); int blockZ = playerlocation.getBlockZ();
int blockX = playerlocation.getBlockX(); int blockX = playerlocation.getBlockX();
int blockY = playerlocation.getBlockY(); int blockY = playerlocation.getBlockY();
Biome biome = world.getBiome(blockX, blockZ); Biome biome = world.getBiome(blockX, blockZ);
String biomeName = biome.name(); String biomeName = biome.name();
//需要刷新的entity列表 List<EntityCondition> entityConditionList = null;
List<String> entityList = configManager.getBiomeEntityRefreshSettings().getBiomeEntityMap().get(biomeName);
//entity条件配置
HashMap<String, EntityCondition> entityConditionHashMap =
configManager.getBiomeEntityRefreshSettings().getBiomeEntityConditionMap().get(biomeName);
if (entityList == null || entityConditionHashMap == null){ HashMap<String, List<EntityCondition>> entityConditionHashMap = refreshList.getEntityConditionHashMap();
for (String refreshBiome : entityConditionHashMap.keySet()){
if (biomeName.contains(refreshBiome)){
entityConditionList = entityConditionHashMap.get(refreshBiome);
}
}
if (entityConditionList == null){
logger.info(ChatColor.RED+"没有配置"+biomeName+"群系的实体刷新案例"); logger.info(ChatColor.RED+"没有配置"+biomeName+"群系的实体刷新案例");
continue; continue;
} }
for (String entityName : entityList){ for (EntityCondition entityCondition : entityConditionList){
//获取entity配置
EntityCondition entityCondition = entityConditionHashMap.get(entityName);
//危险度验证通过才能刷新
int riskMax = entityCondition.getRiskMax();
int riskMin = entityCondition.getRiskMin();
if (level >= riskMax || level < riskMin){
//不在范围内则跳过
continue;
}
int yMin = entityCondition.getyMin(); int yMin = entityCondition.getyMin();
int yMax = entityCondition.getyMax(); int yMax = entityCondition.getyMax();
//如果玩家所在位置不再设置的y轴高度内则不刷新此entity //如果玩家所在位置不再设置的y轴高度内则不刷新此entity
if (yMin > blockY || yMax < blockY){ if (yMin > blockY || yMax < blockY){
// logger.info(ChatColor.RED+"刷新高度不通过"+entityCondition.getEntityName());
continue; continue;
} }
float v = random.nextFloat();
if (random.nextFloat() > entityCondition.getWeight()){ if ( entityCondition.getWeight() < v){
//刷新不通过,进入下一个验证的实体 //刷新不通过,进入下一个验证的实体
// logger.info(ChatColor.RED+"刷新权重不通过"+entityCondition.getEntityName()+"权重:"+entityCondition.getWeight()+"\t"+v);
continue; continue;
} }
@ -374,17 +426,17 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
for (int i = 0;i<nums && for (int i = 0;i<nums &&
playerRefreshinfo.getEntityList().size() < configManager.getTotal() playerRefreshinfo.getEntityList().size() < configManager.getTotal()
&& sum <= num; i++) { && sum <= num
&& attempts <= configManager.getAttempts(); i++) {
// 生成x和y坐标,会随机在玩家方圆15个方块的距离内随机生成 // 生成x和y坐标,会随机在玩家方圆15个方块的距离内随机生成
int x =blockX + random.nextInt(30) - 15; // 生成0到60之间的随机数然后减去30得到-30到30的范围 int x =blockX + random.nextInt(30) - 15; // 生成0到60之间的随机数然后减去30得到-30到30的范围
int z =blockZ + random.nextInt(30) - 15; // 同上,在玩家附近随机位置生成 int z =blockZ + random.nextInt(30) - 15; // 同上,在玩家附近随机位置生成
int y; int y =blockY + random.nextInt(3) - 2; //在玩家Y轴上下3格尝试刷新
//刷新在地上直接获取最高的x z 最高处的坐标 //刷新在地上直接获取最高的x z 最高处的坐标
if (entityCondition.getEntitySite() == EntitySite.ON_GROUND) { if (entityCondition.getEntitySite() == EntitySite.ON_GROUND) {
y = world.getHighestBlockYAt(x, z);
Location location = new Location(world, x, y + 1, z); Location location = new Location(world, x, y , z);
//判断位置是否符合 //判断位置是否符合
if (ConditionCheck.checkEntityRefresh(world, location, entityCondition)) { if (ConditionCheck.checkEntityRefresh(world, location, entityCondition)) {
@ -397,14 +449,13 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
}else { }else {
//刷新MM怪物 //刷新MM怪物
try { try {
entity = mythicMobs.getAPIHelper().spawnMythicMob(entityName, location,level); entity = mythicMobs.getAPIHelper().spawnMythicMob(entityCondition.getEntityName(),location,riskLevel);
} catch (InvalidMobTypeException e) { } catch (InvalidMobTypeException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
logger.info(ChatColor.GOLD + "" + x + " " + y + " " + z + "位置刷新了" + entityCondition.getEntityName());
logger.info(ChatColor.GOLD + "" + x + " " + y + " " + z + "位置刷新了" + entityName);
UUID uniqueId = entity.getUniqueId(); UUID uniqueId = entity.getUniqueId();
//存入玩家对应的刷新的实体集合便于寻找 //存入玩家对应的刷新的实体集合便于寻找
@ -412,7 +463,7 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
//存入 //存入
playerRefreshinfo.addEntityList(uniqueId); playerRefreshinfo.addEntityList(uniqueId);
attempts++;
sum++; sum++;
} }
@ -422,9 +473,12 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
playerRefreshinfo.getEntityList().size() < configManager.getTotal(); playerRefreshinfo.getEntityList().size() < configManager.getTotal();
c++) { c++) {
//循环十次验证刷新位置 //循环十次验证刷新位置
y = blockY + random.nextInt(6) - 6;//在玩家所在高度的上下六格内生成便于当玩家在洞穴时定位洞穴 y = blockY + random.nextInt(3) - 3;//在玩家所在高度的上下三格内生成便于当玩家在洞穴时定位洞穴
x = blockX + random.nextInt(30) - 15; // 生成0到60之间的随机数然后减去30得到-30到30的范围 x = blockX + random.nextInt(30) - 15; // 生成0到60之间的随机数然后减去30得到-30到30的范围
z = blockZ + random.nextInt(30) - 15; // 同上,在玩家附近随机位置生成 z = blockZ + random.nextInt(30) - 15; // 同上,在玩家附近随机位置生成
if (entityCondition.getEntitySite() == EntitySite.ON_GROUND) {
y = world.getHighestBlockYAt(x,z);
}
Location location = new Location(world, x, y + 1, z); Location location = new Location(world, x, y + 1, z);
@ -438,13 +492,13 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
}else { }else {
//刷新MM怪物 //刷新MM怪物
try { try {
entity = mythicMobs.getAPIHelper().spawnMythicMob(entityName, location); entity = mythicMobs.getAPIHelper().spawnMythicMob(entityCondition.getEntityName(), location);
} catch (InvalidMobTypeException e) { } catch (InvalidMobTypeException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
logger.info(ChatColor.GOLD + "" + x + " " + y + " " + z + "位置刷新了" + entityName); logger.info(ChatColor.GOLD + "" + x + " " + y + " " + z + "位置刷新了" + entityCondition.getEntityName());
UUID uniqueId = entity.getUniqueId(); UUID uniqueId = entity.getUniqueId();
//存入玩家对应的刷新的实体集合便于寻找 //存入玩家对应的刷新的实体集合便于寻找
@ -454,11 +508,10 @@ public class EntityRefreshListener implements Listener, CommandExecutor {
playerRefreshinfo.addEntityList(uniqueId); playerRefreshinfo.addEntityList(uniqueId);
i++; i++;
sum++; sum++;
attempts++;
} }
} }
} }
} }
} }
} }

View File

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

View File

@ -1,3 +1,12 @@
RefreshTime: 10 #刷新时间单位为s RefreshTime: 10 #刷新时间单位为s
total: 12 #每个玩家每次刷新的实体数量 total: 12 #每个玩家最多刷新的实体数量
num: 4 #单次刷新的最大数量每RefreshTime秒刷新的数量 num: 4 #单次刷新的最大数量每RefreshTime秒刷新的数量
LEVEL_MAX: 2 #能够刷新的最高等级,便于读取文件
attempts: 6 #权重通过时,随机位置的最大次数
blacklistNums: 1 #黑名单区域的数量的数量
location_1: #黑名单区域
world_name: TravelersDreamCompact
x1: 100
z1: 100
x2: 200
z2: 200

View File

@ -23,7 +23,6 @@ ROOFED_FOREST:
yMin: 60 #最小刷新高度 yMin: 60 #最小刷新高度
riskMax: 10 #刷新危险度的范围 riskMax: 10 #刷新危险度的范围
riskMin: 0 riskMin: 0
PIG_ZOMBIE: #指出entity在该群系的刷新条件 PIG_ZOMBIE: #指出entity在该群系的刷新条件
type: 0 #0表示生成mc原生实体1表示生成MM怪物2表示生成萌芽怪物 type: 0 #0表示生成mc原生实体1表示生成MM怪物2表示生成萌芽怪物
site: 1 #刷新位置,数字代表不同的刷新位置 site: 1 #刷新位置,数字代表不同的刷新位置

View File

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

View File

@ -1,3 +1,12 @@
RefreshTime: 10 #刷新时间单位为s RefreshTime: 10 #刷新时间单位为s
total: 12 #每个玩家每次刷新的实体数量 total: 12 #每个玩家最多刷新的实体数量
num: 4 #单次刷新的最大数量每RefreshTime秒刷新的数量 num: 4 #单次刷新的最大数量每RefreshTime秒刷新的数量
LEVEL_MAX: 2 #能够刷新的最高等级,便于读取文件
attempts: 6 #权重通过时,随机位置的最大次数
blacklistNums: 1 #黑名单区域的数量的数量
location_1: #黑名单区域
world_name: TravelersDreamCompact
x1: 100
z1: 100
x2: 200
z2: 200