Package de.craftsblock.craftsnet.addon
Class AddonManager
java.lang.Object
de.craftsblock.craftsnet.addon.AddonManager
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDirectly(Collection<AddonConfiguration> configurations) AddsAddonConfigurationdirectly to the configurations which will be loaded on startup.voidLoad all addons from the addons folder.<T extends Addon>
TRetrieves an addon of the specified type from the loaded addons.<T extends Addon>
TRetrieves an addon by its name from the loaded addons.Gets the underlyingAddonLoaderwhich is used for loading the addons.Returns a read-only view of the registered addons in the AddonManager.booleanisRegistered(@NotNull Class<? extends Addon> addon) Checks whether anAddonclass is registered or not.booleanisRegistered(@NotNull String name) Checks whether anAddonis registered using its name.voidRegisters an addon in the AddonManager.voidstartup()Performs the startup of the addon system and loads all present addon configurations.voidstop()Method to stop the AddonManager.voidunregister(@NotNull Addon addon) Unregisters an addon from the AddonManager.
-
Constructor Details
-
AddonManager
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
AddsAddonConfigurationdirectly to the configurations which will be loaded on startup.- Parameters:
configurations- TheAddonConfigurationto 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
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
Registers an addon in the AddonManager.- Parameters:
addon- The addon to be registered.
-
unregister
Unregisters an addon from the AddonManager.- Parameters:
addon- The addon to be unregistered.
-
getAddons
Returns a read-only view of the registered addons in the AddonManager.- Returns:
- A read-only ConcurrentHashMap containing the registered addons.
-
getAddon
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
nullif not present.
-
getAddon
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
nullif not present. - Since:
- 3.3.5-SNAPSHOT
-
isRegistered
Checks whether anAddonclass is registered or not.- Parameters:
addon- The class of theAddonto check.- Returns:
trueif the addon is registered,falseotherwise.- Since:
- 3.3.5-SNAPSHOT
-
isRegistered
Checks whether anAddonis registered using its name.- Parameters:
name- The name of theAddon- Returns:
trueif the addon is registered,falseotherwise.- Since:
- 3.3.5-SNAPSHOT
-
getAddonLoader
Gets the underlyingAddonLoaderwhich is used for loading the addons.- Returns:
- The
AddonLoader - Since:
- 3.4.3
-