Package com.ultikits.ultitools.manager
Class ConfigManager
java.lang.Object
com.ultikits.ultitools.manager.ConfigManager
- Version:
- 1.0.0
- Author:
- wisdomme
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<UltiToolsPlugin, Map<String, AbstractConfigEntity>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddConfigEntity(UltiToolsPlugin ultiToolsPlugin, AbstractConfigEntity configEntity) private StringbuildJsonFromConfigs(Function<AbstractConfigEntity, com.google.gson.JsonObject> extractor) Builds a JSON string from all config entities using the provided extractor function.getAllConfigEntities(UltiToolsPlugin plugin) Get all config entities for a plugin.final StringGet all comments.<T extends AbstractConfigEntity>
List<T> getConfigEntities(UltiToolsPlugin plugin, Class<T> type) Get all config entities by type.<T extends AbstractConfigEntity>
TgetConfigEntity(UltiToolsPlugin plugin, Class<T> type) Get config entity.<T extends AbstractConfigEntity>
TgetConfigEntity(UltiToolsPlugin plugin, String path, Class<T> type) Get config entity by path.final voidloadFromJson(String json) Load config from JSON string.final voidloadFromJson(String configFilePath, String json) Load a single config file from a JSON string.voidregister(UltiToolsPlugin ultiToolsPlugin, AbstractConfigEntity configEntity) Register config entity.voidregisterAll(UltiToolsPlugin plugin, String packageName, ClassLoader classLoader) Register all config entities in the specified package.voidreloadConfigs(UltiToolsPlugin plugin) Reload all configs.voidsaveAll()Save all configs.final StringtoJson()Cast config to JSON format.
-
Field Details
-
pluginConfigMap
-
-
Constructor Details
-
ConfigManager
public ConfigManager()
-
-
Method Details
-
register
public void register(UltiToolsPlugin ultiToolsPlugin, AbstractConfigEntity configEntity) throws IOException Register config entity.
注册配置实体- Parameters:
ultiToolsPlugin- UltiTools module
UltiTools模块configEntity- Config entity
配置实体- Throws:
IOException
-
addConfigEntity
-
registerAll
Register all config entities in the specified package.
注册指定包下的所有配置实体- Parameters:
plugin- UltiTools module
UltiTools模块packageName- Package name
包名classLoader- Class loader
类加载器
-
getConfigEntity
Get config entity.
获取配置实体- Type Parameters:
T- Config entity type
配置实体类型- Parameters:
plugin- UltiTools module
UltiTools模块type- Config entity type
配置实体类型- Returns:
- Config entity
配置实体
-
getConfigEntity
public <T extends AbstractConfigEntity> T getConfigEntity(UltiToolsPlugin plugin, String path, Class<T> type) Get config entity by path.
通过路径获取配置实体- Type Parameters:
T- Config entity type
配置实体类型- Parameters:
plugin- UltiTools module
UltiTools模块path- Config entity path
配置实体路径type- Config entity type
配置实体类型- Returns:
- Config entity
配置实体
-
getConfigEntities
public <T extends AbstractConfigEntity> List<T> getConfigEntities(UltiToolsPlugin plugin, Class<T> type) Get all config entities by type.
通过类型获取所有配置实体- Type Parameters:
T- Config entity type
配置实体类型- Parameters:
plugin- UltiTools module
UltiTools模块type- Config entity type
配置实体类型- Returns:
- Config entity list
配置实体列表
-
getAllConfigEntities
Get all config entities for a plugin.
获取插件的所有配置实体- Parameters:
plugin- UltiTools module
UltiTools模块- Returns:
- All config entities
所有配置实体
-
reloadConfigs
Reload all configs.
重新加载所有配置- Parameters:
plugin- UltiTools module
UltiTools模块
-
saveAll
public void saveAll()Save all configs.
保存所有配置 -
buildJsonFromConfigs
private String buildJsonFromConfigs(Function<AbstractConfigEntity, com.google.gson.JsonObject> extractor) Builds a JSON string from all config entities using the provided extractor function.
使用提供的提取函数从所有配置实体构建JSON字符串- Parameters:
extractor- function to extract JsonObject from config entity
从配置实体提取JsonObject的函数- Returns:
- JSON string
JSON字符串
-
getComments
Get all comments.
获取所有注释- Returns:
- all comments
所有注释
-
toJson
Cast config to JSON format.
将配置转换为JSON格式- Returns:
- config in JSON format
JSON格式的配置
-
loadFromJson
Load config from JSON string.
从JSON字符串加载配置- Parameters:
json- JSON string
JSON字符串- Throws:
IOException- if an I/O error occurs
如果发生I/O错误
-
loadFromJson
Load a single config file from a JSON string.
从JSON字符串加载单个配置文件loadFromJson(String)接受的是{插件名: {配置路径: {配置项: 值}}}这样的全量嵌套结构,也就是toJson()的产物。本方法接受的是最里面那一层 ——某一个配置文件自己的{配置项: 值}——由configFilePath指定写到哪。 面板按文件名下发单个配置时用的是后一种形状,见 issue #236。配置路径在单个插件内唯一(
pluginConfigMap的内层 key 就是它), 跨插件则可能重名。找不到和命中多个都抛异常而不是静默跳过: 「调用方以为写了、实际什么也没发生」正是这条链路上原来的毛病。- Parameters:
configFilePath- config file path as registered, e.g.config/lang.yml
注册时使用的配置文件路径json- JSON object of that file's entries
该文件配置项的JSON对象- Throws:
IOException- if the path is blank, unknown, ambiguous, or the JSON is not an object, or if saving fails
路径为空、找不到、跨插件重名、JSON不是对象或保存失败- Since:
- 6.2.5
-