Package me.hsgamer.hscore.addon
Class AddonManager
java.lang.Object
me.hsgamer.hscore.addon.AddonManager
- Direct Known Subclasses:
SimpleAddonManager
A class that manages all addons in it
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAddonManager(@NotNull File addonsDir, @NotNull Logger logger, @NotNull AddonDescriptionLoader addonDescriptionLoader) Create a new addon managerAddonManager(@NotNull File addonsDir, @NotNull Logger logger, @NotNull AddonDescriptionLoader addonDescriptionLoader, @NotNull ClassLoader parentClassLoader) Create a new addon manager -
Method Summary
Modifier and TypeMethodDescriptionvoidCall theAddon.onPostEnable()method of all enabled addonsvoidCall theAddon.onReload()method of all enabled addonsbooleandisableAddon(@NotNull String name, boolean closeLoaderOnFailed) Disable (callAddon.onDisable()) the addonvoidDisable all enabled addonsbooleanenableAddon(@NotNull String name, boolean closeLoaderOnFailed) Enable (callAddon.onEnable()) the addonvoidEnable all addons from the addon directory@Nullable Class<?>Find a class for an addon@Nullable AddonGet the enabled addon@NotNull AddonDescriptionLoaderGet the addon description loaderfinal @NotNull FileGet the addon directoryGet all loaded addonsfinal @NotNull LoggerGet the loggerbooleanisAddonLoaded(@NotNull String name) Check if the addon is loadedvoidLoad all addons from the addon directory.protected voidonAddonDisable(@NotNull Addon addon) Called when the addon is on disablingprotected voidonAddonDisabled(@NotNull Addon addon) Called when the addon is disabledprotected voidonAddonEnable(@NotNull Addon addon) Called when the addon is on enableprotected voidonAddonEnabled(@NotNull Addon addon) Called when the addon is enabledprotected booleanonAddonLoading(@NotNull Addon addon) Called when the addon is on loadingsortAndFilter(@NotNull Map<String, Addon> original) Filter and sort the order of the addons
-
Field Details
-
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 fileslogger- the logger to use in every addonaddonDescriptionLoader- 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 fileslogger- the logger to use in every addonaddonDescriptionLoader- the loader to load addon descriptionparentClassLoader- the parent class loader to load all addons
-
-
Method Details
-
getAddonsDir
Get the addon directory- Returns:
- the directory
-
getLogger
Get the logger- Returns:
- the logger
-
getAddonDescriptionLoader
Get the addon description loader- Returns:
- the loader
-
loadAddons
public void loadAddons()Load all addons from the addon directory. Also callAddon.onLoad() -
enableAddon
Enable (callAddon.onEnable()) the addon- Parameters:
name- the addon namecloseLoaderOnFailed- close the class loader if failed- Returns:
- whether it's enabled successfully
-
disableAddon
Disable (callAddon.onDisable()) the addon- Parameters:
name- the addon namecloseLoaderOnFailed- 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 theAddon.onPostEnable()method of all enabled addons -
callReload
public void callReload()Call theAddon.onReload()method of all enabled addons -
disableAddons
public void disableAddons()Disable all enabled addons -
getAddon
Get the enabled addon- Parameters:
name- the name of the addon- Returns:
- the addon, or null if it's not found
-
isAddonLoaded
Check if the addon is loaded- Parameters:
name- the name of the addon- Returns:
- whether it's loaded
-
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 addonname- 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
Called when the addon is on loading- Parameters:
addon- the loading addon- Returns:
- whether the addon is properly loaded
-
onAddonEnable
Called when the addon is on enable- Parameters:
addon- the enabling addon
-
onAddonEnabled
Called when the addon is enabled- Parameters:
addon- the enabled addon
-
onAddonDisable
Called when the addon is on disabling- Parameters:
addon- the disabling addon
-
onAddonDisabled
Called when the addon is disabled- Parameters:
addon- the disabled addon
-