Class UltiToolsPlugin

java.lang.Object
com.ultikits.ultitools.abstracts.UltiToolsPlugin
All Implemented Interfaces:
Configurable, IPlugin, Localized

public abstract class UltiToolsPlugin extends Object implements IPlugin, Localized, Configurable
Abstract class representing a plugin module.

插件模块抽象类

Version:
1.0.0
Author:
wisdomme
  • Field Details

    • language

      private Language language
    • version

      private final String version
    • pluginName

      private final String pluginName
    • authors

      private final List<String> authors
    • loadAfter

      private final List<String> loadAfter
    • minUltiToolsVersion

      private final int minUltiToolsVersion
    • mainClass

      private final String mainClass
    • identifyString

      private final String identifyString
    • resourceFolderPath

      private String resourceFolderPath
    • context

      private SimpleContainer context
  • Constructor Details

    • UltiToolsPlugin

      protected UltiToolsPlugin()
      Constructor for UltiToolsPlugin. For module development only.

      UltiToolsPlugin的构造函数。仅用于模块开发。

    • UltiToolsPlugin

      @Deprecated(since="6.0.8", forRemoval=true) public UltiToolsPlugin(String pluginName, String version, List<String> authors, List<String> loadAfter, int minUltiToolsVersion, String mainClass)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use the seven-argument constructor and pass resourceFolderPath explicitly. This overload hard-codes it to <dataFolder>/pluginConfig/<pluginName>.

      请改用七参数构造函数并显式传入 resourceFolderPath。 此重载把它硬编码成了 <dataFolder>/pluginConfig/<插件名>

      Constructor for UltiToolsPlugin. For plugin connector.

      UltiToolsPlugin的构造函数。用于插件连接器。

      Parameters:
      pluginName - the name of the plugin
      插件名称
      version - the version of the plugin
      插件版本
      authors - the authors of the plugin
      插件作者
      loadAfter - the plugins which should be loaded before this plugin
      在这个插件之前加载的插件
      minUltiToolsVersion - the minimum version of UltiTools required by this plugin
      这个插件所需的UltiTools最低版本
      mainClass - the main class of the plugin
      插件的主类
    • UltiToolsPlugin

      public UltiToolsPlugin(String pluginName, String version, List<String> authors, List<String> loadAfter, int minUltiToolsVersion, String mainClass, String resourceFolderPath)
      Constructor for UltiToolsPlugin. For plugin connector.

      UltiToolsPlugin的构造函数。用于插件连接器。

      Parameters:
      pluginName - the name of the plugin
      插件名称
      version - the version of the plugin
      插件版本
      authors - the authors of the plugin
      插件作者
      loadAfter - the plugins which should be loaded before this plugin
      在这个插件之前加载的插件
      minUltiToolsVersion - the minimum version of UltiTools required by this plugin
      这个插件所需的UltiTools最低版本
      mainClass - the main class of the plugin
      插件的主类
      resourceFolderPath - the path to the resource folder
      资源文件夹的路径
  • Method Details

    • initializeLanguage

      private Language initializeLanguage()
      Initializes the language object
      Returns:
      Language object
    • createLanguageFromPath

      private Language createLanguageFromPath(String folderPath)
      Creates a Language object from the given resource folder path
      Parameters:
      folderPath - the resource folder path
      Returns:
      Language object
    • loadPluginConfiguration

      private org.bukkit.configuration.file.YamlConfiguration loadPluginConfiguration()
      Loads the plugin configuration from plugin.yml
      Returns:
      YamlConfiguration object with default values if loading fails
    • setContext

      @Internal public void setContext(SimpleContainer context)
      Injects the IoC container created for this plugin.

      注入为本插件创建的 IoC 容器。

      Called by PluginManager while a module is being loaded, before registerSelf() runs. It is not part of the module-facing API — a module that calls it replaces the container the framework already wired up, losing every bean that was injected into it.

      PluginManager 在加载模块时调用,早于 registerSelf()。它不属于 面向模块的 API——模块自己调用它,等于把框架已经装配好的容器整个换掉,里面注入过的 bean 全部丢失。

      Deliberately still public: PluginManager lives in another package, so this cannot be narrowed to package-private, and deleting it outright would remove a public method, which the compatibility policy forbids in a PATCH release. The annotation is a signal to humans and IDEs; it enforces nothing at runtime.

      刻意保持 public:PluginManager 不在同一个包,降不成 package-private; 直接删掉则是移除一个 public 方法,兼容性策略不允许 PATCH 版本这么做。注解只是给人 和 IDE 看的信号,运行期不做任何强制。

      Parameters:
      context - the container created for this plugin
      为本插件创建的容器
    • getConfigManager

      public static ConfigManager getConfigManager()
      Returns:
      the config manager
      配置管理器
    • getListenerManager

      public static ListenerManager getListenerManager()
      Returns:
      the listener manager
      监听器管理器
    • getCommandManager

      public static CommandManager getCommandManager()
      Returns:
      the command manager
      指令管理器
    • getPluginManager

      public static PluginManager getPluginManager()
      Returns:
      the plugin manager
      插件管理器
    • getVersionWrapper

      @Deprecated(since="6.2.0", forRemoval=true) public static VersionWrapper getVersionWrapper()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use XVersionUtils instead.
      Returns:
      the version wrapper
      版本包装器
    • initConfig

      private void initConfig() throws IOException
      Initializes the configuration entity.

      初始化配置实体。

      Throws:
      IOException
    • getInputStream

      private InputStream getInputStream() throws IOException
      Throws:
      IOException
    • getConfigFolder

      protected final String getConfigFolder()
    • getConfigFile

      protected final File getConfigFile(String path)
    • getConfig

      public <T extends AbstractConfigEntity> T getConfig(Class<T> configType)
      Description copied from interface: Configurable
      Get config by config type.

      通过配置类型获取配置

      Specified by:
      getConfig in interface Configurable
      Type Parameters:
      T - Config type
      配置类型
      Parameters:
      configType - Config type
      配置类型
      Returns:
      Config
      配置
    • getConfig

      public <T extends AbstractConfigEntity> T getConfig(String path, Class<T> configType)
      Description copied from interface: Configurable
      Get config by config path and config type.

      通过配置路径和配置类型获取配置

      Specified by:
      getConfig in interface Configurable
      Type Parameters:
      T - Config type
      配置类型
      Parameters:
      path - Config path
      配置路径
      configType - Config type
      配置类型
      Returns:
      Config
      配置
    • getConfigs

      public <T extends AbstractConfigEntity> List<T> getConfigs(Class<T> configType)
    • saveConfig

      public <T extends AbstractConfigEntity> void saveConfig(String path, Class<T> configType) throws IOException
      Description copied from interface: Configurable
      Save config by config type.

      通过配置类型保存配置

      Specified by:
      saveConfig in interface Configurable
      Type Parameters:
      T - Config type
      配置类型
      Parameters:
      path - Config path
      配置路径
      configType - Config type
      配置类型
      Throws:
      IOException - IOException
      IO异常
    • saveResources

      private void saveResources()
    • getResource

      private InputStream getResource(String filename)
    • getDataOperator

      public final <T extends BaseDataEntity<String>> DataOperator<T> getDataOperator(Class<T> dataClazz)
      Gets data operator.

      获取数据操作器。

      Type Parameters:
      T - the type of the data entity
      数据实体的类型
      Parameters:
      dataClazz - the class of the data entity
      数据实体的类
      Returns:
      the data operator
      数据操作器
    • getLanguageCode

      public final String getLanguageCode()
      Returns:
      language code
      语言代码
    • getLanguage

      public final Language getLanguage()
      Returns:
      the language
      语言
    • i18n

      public String i18n(String str)
      Parameters:
      str - the string to be localized
      要本地化的字符串
      Returns:
      the localized string
      本地化后的字符串
    • i18n

      public final String i18n(String code, String str)
      Description copied from interface: Localized
      Returns a localized string that indicated by user. If the chosen language code is not presented in Localized.supported(), this method will return the text by default.

      通过指定的语言代码返回一个本地化的字符串。如果语言代码没有出现在Localized.supported()里面,则返回传入的原文。
      Specified by:
      i18n in interface Localized
      Parameters:
      code - language code
      语言代码
      str - default display text
      默认的显示文本
      Returns:
      A localized string, or the default text if the localization is not supported
      一个本地化的字符串,如果语言代码不被支持则返回原文
    • isNewerVersionThan

      public boolean isNewerVersionThan(UltiToolsPlugin plugin)
      Parameters:
      plugin - the plugin to be checked
      要检查的插件
      Returns:
      whether the plugin is newer than the given plugin
      插件是否比给定的插件新
    • unregisterSelf

      public void unregisterSelf()
      Description copied from interface: IPlugin
      UltiTools will call this method when unregistering this plugin module, similar to JavaPlugin.onDisable()
      卸载此插件模块时调用的方法,类比JavaPlugin.onDisable()
      Specified by:
      unregisterSelf in interface IPlugin
    • reloadSelf

      public void reloadSelf()
      Description copied from interface: IPlugin
      UltiTools will call this method when reloading this plugin module, similar to JavaPlugin.onDisable() and JavaPlugin.onEnable()
      重载此插件模块时调用的方法,此重载并非重启模块,不会调用IPlugin.registerSelf()IPlugin.unregisterSelf()
      Specified by:
      reloadSelf in interface IPlugin
    • getLogger

      public PluginLogger getLogger()
      Returns:
      plugin logger
      插件日志发送器