Class ExpansionManager
java.lang.Object
me.hsgamer.hscore.expansion.common.ExpansionManager
A class that manages all
Expansions-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String,ExpansionClassLoader> The class loader map keyed expansion's id, valued expansion's class loaderstatic final Function<ExpansionClassLoader,Expansion> The default factory to create a new instance of the main class using the no-args constructor -
Constructor Summary
ConstructorsConstructorDescriptionExpansionManager(@NotNull File expansionsDir, @NotNull Function<JarFile, ExpansionDescription> descriptionFactory) Create a new expansion managerExpansionManager(@NotNull File expansionsDir, @NotNull Function<JarFile, ExpansionDescription> descriptionFactory, @NotNull ClassLoader parentClassLoader) Create a new expansion managerExpansionManager(@NotNull File expansionsDir, @NotNull Function<JarFile, ExpansionDescription> descriptionFactory, @NotNull Function<ExpansionClassLoader, Expansion> expansionFactory) Create a new expansion managerExpansionManager(@NotNull File expansionsDir, @NotNull Function<JarFile, ExpansionDescription> descriptionFactory, @NotNull Function<ExpansionClassLoader, Expansion> expansionFactory, @NotNull ClassLoader parentClassLoader) Create a new expansion manager -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStateListener(@NotNull BiConsumer<ExpansionClassLoader, ExpansionState> listener) Add a new state listener<T> voidCall the consumer for all enabled expansions that match the specific classvoidCall the consumer for all enabled expansionsvoidDisable all enabled expansionsvoidEnable all loaded expansionsGet all loaded expansion class loaders@NotNull Function<JarFile,ExpansionDescription> Get the description factoryGet all enabled expansionsgetExpansion(@NotNull String name) Get the loaded expansiongetExpansionClassLoader(@NotNull String name) Get the loaded expansion class loader@NotNull Function<ExpansionClassLoader,Expansion> Get the expansion factoryfinal @NotNull FileGet the expansion directory@NotNull ClassLoaderGet the parent class loadervoidLoad all expansions from the expansion directory.voidremoveStateListener(@NotNull BiConsumer<ExpansionClassLoader, ExpansionState> listener) Remove a state listenervoidsetExceptionHandler(Consumer<Throwable> exceptionHandler) Set the exception handlervoidsetSortAndFilterFunction(UnaryOperator<Map<String, ExpansionClassLoader>> sortAndFilterFunction) Set the function to sort and filter theExpansionClassLoaders
-
Field Details
-
DEFAULT_EXPANSION_FACTORY
The default factory to create a new instance of the main class using the no-args constructor -
classLoaders
The class loader map keyed expansion's id, valued expansion's class loader
-
-
Constructor Details
-
ExpansionManager
public ExpansionManager(@NotNull @NotNull File expansionsDir, @NotNull @NotNull Function<JarFile, ExpansionDescription> descriptionFactory, @NotNull @NotNull Function<ExpansionClassLoader, Expansion> expansionFactory, @NotNull @NotNull ClassLoader parentClassLoader) Create a new expansion manager- Parameters:
expansionsDir- the directory to store expansion filesdescriptionFactory- the factory to load descriptionexpansionFactory- the factory to load expansion instanceparentClassLoader- the parent class loader to load all expansions
-
ExpansionManager
public ExpansionManager(@NotNull @NotNull File expansionsDir, @NotNull @NotNull Function<JarFile, ExpansionDescription> descriptionFactory, @NotNull @NotNull Function<ExpansionClassLoader, Expansion> expansionFactory) Create a new expansion manager- Parameters:
expansionsDir- the directory to store expansion filesdescriptionFactory- the factory to load descriptionexpansionFactory- the factory to load expansion instance
-
ExpansionManager
public ExpansionManager(@NotNull @NotNull File expansionsDir, @NotNull @NotNull Function<JarFile, ExpansionDescription> descriptionFactory, @NotNull @NotNull ClassLoader parentClassLoader) Create a new expansion manager- Parameters:
expansionsDir- the directory to store expansion filesdescriptionFactory- the factory to load descriptionparentClassLoader- the parent class loader to load all expansions
-
ExpansionManager
public ExpansionManager(@NotNull @NotNull File expansionsDir, @NotNull @NotNull Function<JarFile, ExpansionDescription> descriptionFactory) Create a new expansion manager- Parameters:
expansionsDir- the directory to store expansion filesdescriptionFactory- the factory to load description
-
-
Method Details
-
getExpansionsDir
Get the expansion directory- Returns:
- the directory
-
getDescriptionFactory
Get the description factory- Returns:
- the factory
-
getExpansionFactory
Get the expansion factory- Returns:
- the factory
-
getParentClassLoader
Get the parent class loader- Returns:
- the parent class loader
-
addStateListener
public void addStateListener(@NotNull @NotNull BiConsumer<ExpansionClassLoader, ExpansionState> listener) Add a new state listener- Parameters:
listener- the listener
-
removeStateListener
public void removeStateListener(@NotNull @NotNull BiConsumer<ExpansionClassLoader, ExpansionState> listener) Remove a state listener- Parameters:
listener- the listener
-
getClassLoaders
Get all loaded expansion class loaders- Returns:
- the map of expansion class loaders
-
setExceptionHandler
Set the exception handler- Parameters:
exceptionHandler- the exception handler
-
setSortAndFilterFunction
public void setSortAndFilterFunction(UnaryOperator<Map<String, ExpansionClassLoader>> sortAndFilterFunction) Set the function to sort and filter theExpansionClassLoaders- Parameters:
sortAndFilterFunction- the function
-
loadExpansions
public void loadExpansions()Load all expansions from the expansion directory. Also callExpansion.onLoad() -
enableExpansions
public void enableExpansions()Enable all loaded expansions -
disableExpansions
public void disableExpansions()Disable all enabled expansions -
call
Call the consumer for all enabled expansions- Parameters:
consumer- the consumer
-
call
Call the consumer for all enabled expansions that match the specific class- Type Parameters:
T- the type of the class- Parameters:
clazz- the class to limit what expansion can be calledconsumer- the consumer to call the cast expansion
-
getExpansionClassLoader
Get the loaded expansion class loader- Parameters:
name- the name of the expansion- Returns:
- the expansion class loader
-
getExpansion
Get the loaded expansion- Parameters:
name- the name of the expansion- Returns:
- the expansion
-
getEnabledExpansions
Get all enabled expansions- Returns:
- the enabled expansions
-