Class AddonManager

java.lang.Object
me.hsgamer.hscore.addon.AddonManager
Direct Known Subclasses:
SimpleAddonManager

public class AddonManager extends Object
A class that manages all addons in it
  • Field Details

    • addons

      protected final Map<String,Addon> addons
      The addon map keyed addon's id, valued addon itself
  • Constructor Details

    • AddonManager

      protected AddonManager(@NotNull @NotNull File addonsDir, @NotNull @NotNull Logger logger, @NotNull @NotNull AddonDescriptionLoader addonDescriptionLoader)
      Create a new addon manager
      Parameters:
      addonsDir - the directory to store addon files
      logger - the logger to use in every addon
      addonDescriptionLoader - the loader to load addon description
    • AddonManager

      public AddonManager(@NotNull @NotNull File addonsDir, @NotNull @NotNull Logger logger, @NotNull @NotNull AddonDescriptionLoader addonDescriptionLoader, @NotNull @NotNull ClassLoader parentClassLoader)
      Create a new addon manager
      Parameters:
      addonsDir - the directory to store addon files
      logger - the logger to use in every addon
      addonDescriptionLoader - the loader to load addon description
      parentClassLoader - the parent class loader to load all addons
  • Method Details

    • getAddonsDir

      @NotNull public final @NotNull File getAddonsDir()
      Get the addon directory
      Returns:
      the directory
    • getLogger

      @NotNull public final @NotNull Logger getLogger()
      Get the logger
      Returns:
      the logger
    • getAddonDescriptionLoader

      @NotNull public @NotNull AddonDescriptionLoader getAddonDescriptionLoader()
      Get the addon description loader
      Returns:
      the loader
    • loadAddons

      public void loadAddons()
      Load all addons from the addon directory. Also call Addon.onLoad()
    • enableAddon

      public boolean enableAddon(@NotNull @NotNull String name, boolean closeLoaderOnFailed)
      Enable (call Addon.onEnable()) the addon
      Parameters:
      name - the addon name
      closeLoaderOnFailed - close the class loader if failed
      Returns:
      whether it's enabled successfully
    • disableAddon

      public boolean disableAddon(@NotNull @NotNull String name, boolean closeLoaderOnFailed)
      Disable (call Addon.onDisable()) the addon
      Parameters:
      name - the addon name
      closeLoaderOnFailed - close the class loader if failed
      Returns:
      whether it's disabled successfully
    • enableAddons

      public void enableAddons()
      Enable all addons from the addon directory
    • callPostEnable

      public void callPostEnable()
      Call the Addon.onPostEnable() method of all enabled addons
    • callReload

      public void callReload()
      Call the Addon.onReload() method of all enabled addons
    • disableAddons

      public void disableAddons()
      Disable all enabled addons
    • getAddon

      @Nullable public @Nullable Addon getAddon(@NotNull @NotNull String name)
      Get the enabled addon
      Parameters:
      name - the name of the addon
      Returns:
      the addon, or null if it's not found
    • isAddonLoaded

      public boolean isAddonLoaded(@NotNull @NotNull String name)
      Check if the addon is loaded
      Parameters:
      name - the name of the addon
      Returns:
      whether it's loaded
    • getLoadedAddons

      @NotNull public @NotNull Map<String,Addon> getLoadedAddons()
      Get all loaded addons
      Returns:
      the loaded addons
    • findClass

      @Nullable public @Nullable Class<?> findClass(@NotNull @NotNull Addon addon, @NotNull @NotNull String name)
      Find a class for an addon
      Parameters:
      addon - the calling addon
      name - the class name
      Returns:
      the class, or null if it's not found
    • sortAndFilter

      @NotNull protected @NotNull Map<String,Addon> sortAndFilter(@NotNull @NotNull Map<String,Addon> original)
      Filter and sort the order of the addons
      Parameters:
      original - the original map
      Returns:
      the sorted and filtered map
    • onAddonLoading

      protected boolean onAddonLoading(@NotNull @NotNull Addon addon)
      Called when the addon is on loading
      Parameters:
      addon - the loading addon
      Returns:
      whether the addon is properly loaded
    • onAddonEnable

      protected void onAddonEnable(@NotNull @NotNull Addon addon)
      Called when the addon is on enable
      Parameters:
      addon - the enabling addon
    • onAddonEnabled

      protected void onAddonEnabled(@NotNull @NotNull Addon addon)
      Called when the addon is enabled
      Parameters:
      addon - the enabled addon
    • onAddonDisable

      protected void onAddonDisable(@NotNull @NotNull Addon addon)
      Called when the addon is on disabling
      Parameters:
      addon - the disabling addon
    • onAddonDisabled

      protected void onAddonDisabled(@NotNull @NotNull Addon addon)
      Called when the addon is disabled
      Parameters:
      addon - the disabled addon