Class ConfigManager

java.lang.Object
com.ultikits.ultitools.manager.ConfigManager

public class ConfigManager extends Object
Version:
1.0.0
Author:
wisdomme
  • Field Details

  • 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

      private void addConfigEntity(UltiToolsPlugin ultiToolsPlugin, AbstractConfigEntity configEntity)
    • registerAll

      public void registerAll(UltiToolsPlugin plugin, String packageName, ClassLoader classLoader)
      Register all config entities in the specified package.
      注册指定包下的所有配置实体
      Parameters:
      plugin - UltiTools module
      UltiTools模块
      packageName - Package name
      包名
      classLoader - Class loader
      类加载器
    • getConfigEntity

      public <T extends AbstractConfigEntity> T getConfigEntity(UltiToolsPlugin plugin, Class<T> type)
      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

      public Map<String,AbstractConfigEntity> getAllConfigEntities(UltiToolsPlugin plugin)
      Get all config entities for a plugin.
      获取插件的所有配置实体
      Parameters:
      plugin - UltiTools module
      UltiTools模块
      Returns:
      All config entities
      所有配置实体
    • reloadConfigs

      public void reloadConfigs(UltiToolsPlugin plugin)
      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

      public final String getComments()
      Get all comments.
      获取所有注释
      Returns:
      all comments
      所有注释
    • toJson

      public final String toJson()
      Cast config to JSON format.
      将配置转换为JSON格式
      Returns:
      config in JSON format
      JSON格式的配置
    • loadFromJson

      public final void loadFromJson(String json) throws IOException
      Load config from JSON string.
      从JSON字符串加载配置
      Parameters:
      json - JSON string
      JSON字符串
      Throws:
      IOException - if an I/O error occurs
      如果发生I/O错误
    • loadFromJson

      public final void loadFromJson(String configFilePath, String json) throws IOException
      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