Package valorless.rarespawns.builders
Class AbilityCreator
java.lang.Object
valorless.rarespawns.builders.AbilityCreator
AbilityCreator is responsible for loading, compiling, and managing custom abilities in the RareSpawns plugin.
It handles the creation, retrieval, and management of ability classes, including reading ability source files
and compiling them at runtime. Abilities are loaded from the plugin's 'abilities' folder and cached for efficient access.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddAbility(String id, Class<? extends Ability> abilityInstance) Adds a new ability to the collection with the provided ID.Returns a clone of the abilities map containing all compiled ability classes.getAbility(String id) Retrieves a compiled ability class by its unique ID.static BooleanisReady()Checks if the abilities are fully loaded and ready for use.
Set to true once all abilities are compiled and cached.
This may take some time to complete, especially if there are many abilities to process.Retrieves the names of all files (excluding their extensions) in the 'abilities' folder of the plugin's data directory.static StringReads a file from the plugin's data folder.static voidreload()Reloads all abilities from the 'abilities' folder, compiling and caching them.
-
Field Details
-
ready
Indicates whether the abilities have been fully loaded and are ready for use.
Set to true once all abilities are compiled and cached.
This may take some time to complete, especially if there are many abilities to process.
-
-
Constructor Details
-
AbilityCreator
public AbilityCreator()
-
-
Method Details
-
isReady
Checks if the abilities are fully loaded and ready for use.
Set to true once all abilities are compiled and cached.
This may take some time to complete, especially if there are many abilities to process.- Returns:
- True if abilities are ready; false otherwise.
-
getAbilities
Returns a clone of the abilities map containing all compiled ability classes.- Returns:
- A cloned HashMap of ability IDs to compiled ability classes.
-
getAbility
Retrieves a compiled ability class by its unique ID.- Parameters:
id- The unique ID of the ability.- Returns:
- The compiled ability class, or null if not found.
-
addAbility
public static boolean addAbility(String id, Class<? extends Ability> abilityInstance) throws Exception Adds a new ability to the collection with the provided ID. Validates the ID and ability before adding.- Parameters:
id- The unique ID of the ability to be added.abilityInstance- The compiled ability class to add.- Returns:
- True if the ability was successfully added; false if the ID already exists or if an error occurs.
- Throws:
Exception- If the ID is null or empty.
-
reload
public static void reload()Reloads all abilities from the 'abilities' folder, compiling and caching them. It will either add new abilities or update existing ones. This method runs asynchronously to avoid blocking the main server thread. -
readFile
Reads a file from the plugin's data folder.- Parameters:
filename- The name of the file to read from the "/abilities" folder.- Returns:
- The contents of the file as a string.
- Throws:
IOException- If an I/O error occurs while reading the file.
-
listAbilities
Retrieves the names of all files (excluding their extensions) in the 'abilities' folder of the plugin's data directory.- Returns:
- A List of file names without extensions.
-