Class TaskManager

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

@Internal public class TaskManager extends Object
Manages scheduled tasks for plugin modules.

Scans beans for Scheduled annotated methods and registers them as Bukkit tasks. Automatically cancels all tasks when a plugin is unloaded.

管理插件模块的定时任务。扫描 Bean 中标注 Scheduled 的方法并注册为 Bukkit 任务。 插件卸载时自动取消所有任务。

Since:
6.2.0
  • Field Details

    • pluginTasks

      private final Map<UltiToolsPlugin,List<org.bukkit.scheduler.BukkitTask>> pluginTasks
    • externalTasks

      private final Map<String,List<org.bukkit.scheduler.BukkitTask>> externalTasks
    • hostPlugin

      private final org.bukkit.plugin.java.JavaPlugin hostPlugin
  • Constructor Details

    • TaskManager

      public TaskManager(org.bukkit.plugin.java.JavaPlugin hostPlugin)
  • Method Details

    • registerScheduledMethods

      public void registerScheduledMethods(UltiToolsPlugin plugin, Object bean)
      Scan a bean for Scheduled methods and register them as Bukkit tasks.

      扫描 Bean 中的 Scheduled 方法并注册为 Bukkit 任务。

      Parameters:
      plugin - the owning plugin module
      bean - the bean instance to scan
    • cancelAll

      public void cancelAll(UltiToolsPlugin plugin)
      Cancel all scheduled tasks for a plugin.

      取消插件的所有定时任务。

      Parameters:
      plugin - the plugin to cancel tasks for
    • getTargetClass

      private Class<?> getTargetClass(Class<?> clazz)
      Get the original class, unwrapping CGLIB proxies. CGLIB proxy classes contain "$$" in their name.
    • registerScheduledMethodsExternal

      public void registerScheduledMethodsExternal(String pluginName, Object bean)
      Scan a bean for Scheduled methods and register them for an external plugin.

      扫描 Bean 中的 Scheduled 方法并为外部插件注册。

      Parameters:
      pluginName - the external plugin name (used as key)
      bean - the bean instance to scan
      Since:
      6.2.2
    • cancelAllExternal

      public void cancelAllExternal(String pluginName)
      Cancel all scheduled tasks for an external plugin.

      取消外部插件的所有定时任务。

      Parameters:
      pluginName - the external plugin name
      Since:
      6.2.2
    • getTaskCount

      int getTaskCount(UltiToolsPlugin plugin)
      Get the number of registered tasks for a plugin (for testing).
    • getExternalTaskCount

      int getExternalTaskCount(String pluginName)
      Get the number of registered tasks for an external plugin (for testing).