Class AddonManager

java.lang.Object
de.craftsblock.craftsnet.addon.AddonManager

public final class AddonManager extends Object
The AddonManager class is responsible for managing addons in the application. It loads and unloads addons, and keeps track of registered addons in a ConcurrentHashMap. Addons can be registered and unregistered through this class.
Since:
1.0.0-SNAPSHOT
See Also:
  • Constructor Details

    • AddonManager

      public AddonManager(CraftsNet craftsNet)
      Constructor for the AddonManager class. It loads and initializes the addons present in the "./addons/" folder. It also adds a shutdown hook to handle cleanup when the application is shut down.
      Parameters:
      craftsNet - The CraftsNet instance which instantiates this addon manager.
  • Method Details

    • addDirectly

      public void addDirectly(Collection<AddonConfiguration> configurations)
      Adds AddonConfiguration directly to the configurations which will be loaded on startup.
      Parameters:
      configurations - The AddonConfiguration to add.
      Since:
      3.4.3
    • startup

      public void startup()
      Performs the startup of the addon system and loads all present addon configurations.
      Since:
      3.4.3
    • fromFiles

      public void fromFiles() throws IOException
      Load all addons from the addons folder.
      Throws:
      IOException - if there is an I/O error while accessing the addons folder.
    • stop

      public void stop()
      Method to stop the AddonManager. It is called during application shutdown.
    • register

      public void register(@NotNull @NotNull Addon addon)
      Registers an addon in the AddonManager.
      Parameters:
      addon - The addon to be registered.
    • unregister

      public void unregister(@NotNull @NotNull Addon addon)
      Unregisters an addon from the AddonManager.
      Parameters:
      addon - The addon to be unregistered.
    • getAddons

      @NotNull public @Unmodifiable @NotNull Map<String,Addon> getAddons()
      Returns a read-only view of the registered addons in the AddonManager.
      Returns:
      A read-only ConcurrentHashMap containing the registered addons.
    • getAddon

      @Nullable public <T extends Addon> T getAddon(@NotNull @NotNull Class<T> addon)
      Retrieves an addon of the specified type from the loaded addons.
      Type Parameters:
      T - The type of the addon to retrieve, extending the Addon class.
      Parameters:
      addon - The class object representing the type of the addon to be retrieved.
      Returns:
      An instance of the specified addon type if found, or null if not present.
    • getAddon

      @Nullable public <T extends Addon> T getAddon(String name)
      Retrieves an addon by its name from the loaded addons.
      Type Parameters:
      T - The type of the addon to retrieve, extending the Addon class.
      Parameters:
      name - The name of the addon to be retrieved.
      Returns:
      An instance of the specified addon type if found, or null if not present.
      Since:
      3.3.5-SNAPSHOT
    • isRegistered

      public boolean isRegistered(@NotNull @NotNull Class<? extends Addon> addon)
      Checks whether an Addon class is registered or not.
      Parameters:
      addon - The class of the Addon to check.
      Returns:
      true if the addon is registered, false otherwise.
      Since:
      3.3.5-SNAPSHOT
    • isRegistered

      public boolean isRegistered(@NotNull @NotNull String name)
      Checks whether an Addon is registered using its name.
      Parameters:
      name - The name of the Addon
      Returns:
      true if the addon is registered, false otherwise.
      Since:
      3.3.5-SNAPSHOT
    • getAddonLoader

      @Internal public AddonLoader getAddonLoader()
      Gets the underlying AddonLoader which is used for loading the addons.
      Returns:
      The AddonLoader
      Since:
      3.4.3