Class ExpansionManager
java.lang.Object
me.hsgamer.hscore.expansion.common.ExpansionManager
A class that manages all
Expansion
s-
Field Summary
Modifier 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
ConstructorDescriptionExpansionManager
(@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 manager -
Method Summary
Modifier and TypeMethodDescriptionvoid
addStateListener
(@NotNull BiConsumer<ExpansionClassLoader, ExpansionState> listener) Add a new state listener<T> void
Call the consumer for all enabled expansions that match the specific classvoid
Call the consumer for all enabled expansionsvoid
Clear all expansionsvoid
Disable all enabled expansionsvoid
Enable all loaded expansionsGet all loaded expansion class loadersGet all enabled expansionsgetExpansion
(@NotNull String name) Get the loaded expansiongetExpansionClassLoader
(@NotNull String name) Get the loaded expansion class loaderfinal @NotNull File
Get the expansion directory@NotNull ClassLoader
Get the parent class loadervoid
Load all expansions from the expansion directory.void
removeStateListener
(@NotNull BiConsumer<ExpansionClassLoader, ExpansionState> listener) Remove a state listenervoid
setExceptionHandler
(@NotNull Consumer<Throwable> exceptionHandler) Set the exception handlervoid
setExpansionFactory
(@NotNull Function<ExpansionClassLoader, Expansion> expansionFactory) Set the factory to createExpansion
fromExpansionClassLoader
void
setSortAndFilterFunction
(@NotNull UnaryOperator<Map<String, ExpansionClassLoader>> sortAndFilterFunction) Set the function to sort and filter theExpansionClassLoader
s
-
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 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
-
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(@NotNull @NotNull UnaryOperator<Map<String, ExpansionClassLoader>> sortAndFilterFunction) Set the function to sort and filter theExpansionClassLoader
s- Parameters:
sortAndFilterFunction
- the function
-
setExpansionFactory
public void setExpansionFactory(@NotNull @NotNull Function<ExpansionClassLoader, Expansion> expansionFactory) Set the factory to createExpansion
fromExpansionClassLoader
- Parameters:
expansionFactory
- the factory
-
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 -
clearExpansions
public void clearExpansions()Clear all 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
-