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 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 expansionsvoidClear all expansionsvoidDisable all enabled expansionsvoidEnable 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 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(@NotNull Consumer<Throwable> exceptionHandler) Set the exception handlervoidsetExpansionFactory(@NotNull Function<ExpansionClassLoader, Expansion> expansionFactory) Set the factory to createExpansionfromExpansionClassLoadervoidsetRemapper(BiFunction<File, ExpansionDescription, Optional<File>> remapper) Get the function to remap the expansion filevoidsetSortAndFilterFunction(@NotNull 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 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 theExpansionClassLoaders- Parameters:
sortAndFilterFunction- the function
-
setExpansionFactory
public void setExpansionFactory(@NotNull @NotNull Function<ExpansionClassLoader, Expansion> expansionFactory) Set the factory to createExpansionfromExpansionClassLoader- Parameters:
expansionFactory- the factory
-
setRemapper
Get the function to remap the expansion file- Parameters:
remapper- the remapper
-
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
-