Initial commit

This commit is contained in:
2024-04-03 18:20:39 +08:00
commit 3d6a0e5a20
33 changed files with 696 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.yuyu.srwildentity;
import org.bukkit.plugin.java.JavaPlugin;
/**
* 1.在Towny内不刷新怪物(需要Towny依赖)
* 2.可以通过指令控制,例如 randspawn Player_Name, 那么插件会在这个玩家周围刷怪
* 3.不同的生物群系刷怪不同
* 4.要求不需要重启服务器就可以刷新配置(可以通过指令实现配置读取)
* 5.(对于玩家的)刷新速率, 比如每秒一次. 即上秒因为这个玩家而刷新了一个新的实体, 则不会在接下来的一秒内刷新(注册定时任务)
* 6.玩家周边生成的最大数量, 是否达到上限 (papi, 跟危险度相关,需要导入危险度插件,配置文件中定义最大生成等)
*/
public final class SrWildEntity extends JavaPlugin {
@Override
public void onEnable() {
// Plugin startup logic
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}

View File

@@ -0,0 +1,48 @@
package com.yuyu.srwildentity.config;
import com.yuyu.srwildentity.config.condition.BiomeEntityRefreshSettings;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import java.io.File;
/**
* @BelongsProject: SrWildEntity
* @BelongsPackage: com.yuyu.srwildentity.config
* @FileName: ConfigManager
* @Author: 峰。
* @Date: 2024/4/3-15:05
* @Version: 1.0
* @Description: 读取配置文件
*/
public class ConfigManager {
private final BiomeEntityRefreshSettings biomeEntityRefreshSettings;//读取了群系相关刷新条件和需要刷新方块
private final int refreshTime;
private final int total;
public ConfigManager(Plugin plugin) {
//加载配置文件
this.biomeEntityRefreshSettings = new BiomeEntityRefreshSettings(plugin);
//保存配置文件
plugin.saveResource("config.yml",false);
FileConfiguration config;
File file = new File(plugin.getDataFolder(), "config.yml");
config = YamlConfiguration.loadConfiguration(file);
this.refreshTime = config.getInt("RefreshTime");
this.total = config.getInt("total");
}
public BiomeEntityRefreshSettings getBiomeEntityRefreshSettings() {
return biomeEntityRefreshSettings;
}
public int getRefreshTime() {
return refreshTime;
}
public int getTotal() {
return total;
}
}

View File

@@ -0,0 +1,101 @@
package com.yuyu.srwildentity.config.condition;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.util.HashMap;
import java.util.List;
/**
* @BelongsProject: SrWildEntity
* @BelongsPackage: com.yuyu.srwildentity.config.condition
* @FileName: BiomeEntity
* @Author: 峰。
* @Date: 2024/4/3-15:06
* @Version: 1.0
* @Description: 读取实体刷新的配置相关文件
*/
public class BiomeEntityRefreshSettings {
private final HashMap<String,List<String>> biomeEntityMap;
private final HashMap<String,HashMap<String,EntityCondition>> biomeEntityConditionMap;
public BiomeEntityRefreshSettings(Plugin plugin) {
this.biomeEntityMap = new HashMap<>();
this.biomeEntityConditionMap = new HashMap<>();
loadBiomeEntitiesConfig(plugin);
loadEntityConditionConfig(plugin);
}
private void loadEntityConditionConfig(Plugin plugin) {
//保存文件
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()){
HashMap<String,EntityCondition> entityConditionHashMap = new HashMap<>();
List<String> entities = this.biomeEntityMap.get(biomeName);
for (String entityName : entities){
EntitySite entitySite = EntitySite.fromId(config.getInt(biomeName + "." + entityName + ".site"));
int light = config.getInt(biomeName+"."+entityName+".light");
long time = config.getLong(biomeName+"."+entityName+".timing");
int nums = config.getInt(biomeName+"."+entityName+".nums");
int yMax = config.getInt(biomeName+"."+entityName+".yMax");
int yMin = config.getInt(biomeName+"."+entityName+".yMin");
EntityCondition entityCondition = new EntityCondition(entityName, biomeName, entitySite, light, time, nums, yMax, yMin);
//存入单个群系刷新map
entityConditionHashMap.put(entityName, entityCondition);
}
//存入记录总群系的map
biomeEntityConditionMap.put(biomeName,entityConditionHashMap);
}
plugin.getLogger().info("群系刷新相关文件读取完毕");
}
public void loadBiomeEntitiesConfig(Plugin plugin){
//保存文件
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("biomeEntity.读取完成");
}
public HashMap<String, List<String>> getEntityMap() {
return biomeEntityMap;
}
}

View File

@@ -0,0 +1,64 @@
package com.yuyu.srwildentity.config.condition;
/**
* @BelongsProject: SrWildEntity
* @BelongsPackage: com.yuyu.srwildentity.config.condition
* @FileName: EntityCondition
* @Author: 峰。
* @Date: 2024/4/3-15:20
* @Version: 1.0
* @Description: 每个entity刷新需要的条件
*/
public class EntityCondition {
private final String entityName;//实体的名字
private final String biome;//实体刷新的群系
private final EntitySite entitySite;//刷新位置
private final int light;//刷新亮度
private final long timing;//刷新时间
private final int nums;//刷新的数量
private final int yMax;
private final int yMin;
public EntityCondition(String entityName, String biome, EntitySite entitySite, int light, long timing, int nums, int yMax, int yMin) {
this.entityName = entityName;
this.biome = biome;
this.entitySite = entitySite;
this.light = light;
this.timing = timing;
this.nums = nums;
this.yMax = yMax;
this.yMin = yMin;
}
public String getEntityName() {
return entityName;
}
public String getBiome() {
return biome;
}
public EntitySite getEntitySite() {
return entitySite;
}
public int getLight() {
return light;
}
public long getTiming() {
return timing;
}
public int getNums() {
return nums;
}
public int getyMax() {
return yMax;
}
public int getyMin() {
return yMin;
}
}

View File

@@ -0,0 +1,33 @@
package com.yuyu.srwildentity.config.condition;
/**
* 实体刷新的位置
*/
public enum EntitySite {
ON_GROUND(1), //在地上
ON_WATER(2), //在水上
ON_MAGMA(3), //在岩浆上
UNDER_GROUND(4);//在地下
private final int id;
public int getId() {
return id;
}
EntitySite( int id) {
this.id = id;
}
public static EntitySite fromId(int id) {
for (EntitySite type : EntitySite.values()) {
if (type.getId() == id) {
return type;
}
}
throw new IllegalArgumentException("No enum constant with id " + id);
}
}

View File

@@ -0,0 +1,22 @@
package com.yuyu.srwildentity.listener;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
/**
* @BelongsProject: SrWildEntity
* @BelongsPackage: com.yuyu.srwildentity.listener
* @FileName: EntityRefreshListener
* @Author: 峰。
* @Date: 2024/4/3-18:12
* @Version: 1.0
* @Description:监听类,控制怪物的刷新,同时注册指令,操控刷新
*/
public class EntityRefreshListener implements Listener, CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
return false;
}
}