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;
}
}

View File

@@ -0,0 +1,63 @@
biome:
- OCEAN
- PLAINS
- DESERT
- EXTREME_HILLS
- FOREST
- TAIGA
- SWAMPLAND
- RIVER
- HELL
- SKY
- FROZEN_OCEAN
- FROZEN_RIVER
- ICE_FLATS
- ICE_MOUNTAINS
- MUSHROOM_ISLAND
- MUSHROOM_ISLAND_SHORE
- BEACHES
- DESERT_HILLS
- FOREST_HILLS
- TAIGA_HILLS
- SMALLER_EXTREME_HILLS
- JUNGLE
- JUNGLE_HILLS
- JUNGLE_EDGE
- DEEP_OCEAN
- STONE_BEACH
- COLD_BEACH
- BIRCH_FOREST
- BIRCH_FOREST_HILLS
- ROOFED_FOREST
- TAIGA_COLD
- TAIGA_COLD_HILLS
- REDWOOD_TAIGA
- REDWOOD_TAIGA_HILLS
- EXTREME_HILLS_WITH_TREES
- SAVANNA
- SAVANNA_ROCK
- MESA
- MESA_ROCK
- MESA_CLEAR_ROCK
- VOID
- MUTATED_PLAINS
- MUTATED_DESERT
- MUTATED_EXTREME_HILLS
- MUTATED_FOREST
- MUTATED_TAIGA
- MUTATED_SWAMPLAND
- MUTATED_ICE_FLATS
- MUTATED_JUNGLE
- MUTATED_JUNGLE_EDGE
- MUTATED_BIRCH_FOREST
- MUTATED_BIRCH_FOREST_HILLS
- MUTATED_ROOFED_FOREST
- MUTATED_TAIGA_COLD
- MUTATED_REDWOOD_TAIGA
- MUTATED_REDWOOD_TAIGA_HILLS
- MUTATED_EXTREME_HILLS_WITH_TREES
- MUTATED_SAVANNA
- MUTATED_SAVANNA_ROCK
- MUTATED_MESA
- MUTATED_MESA_ROCK
- MUTATED_MESA_CLEAR_ROCK

View File

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

View File

@@ -0,0 +1,2 @@
RefreshTime: 100 #刷新时间单位为s
total: 10 #每个玩家身边刷新的总数

View File

@@ -0,0 +1,8 @@
DESERT:
ZOMBIE: #指出entity在该群系的刷新条件
site: 1 #刷新位置,数字代表不同的刷新位置
light: 100 #刷新亮度
timing: 4086 #刷新怪物的时间注意这里需要用mc中的时间格式来表示而不是现实中的时间
nums: 2 #entity的刷新数量注意这里的数量会和通群系中其他entity相关总数不会超过config.yml中的定义
yMax: 150 #极限刷新高度
yMin: 60 #最小刷新高度

View File

@@ -0,0 +1,3 @@
name: SrWildEntity
version: '${project.version}'
main: com.yuyu.srwildentity.SrWildEntity