Package valorless.rarespawns.compilers
Class SoulPowerCompiler
java.lang.Object
valorless.rarespawns.compilers.Compiler
valorless.rarespawns.compilers.SoulPowerCompiler
Compiles, caches, and invokes Soul Power scripts located under the plugin's
data folder (soulpowers/).
Responsibilities:
- Discover .java source files in soulpowers/
- Compile them asynchronously and cache the resulting classes
- Expose reflective invocation for executing a power
isReady() to check
when the registry is available.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static BooleanIndicates whether the async compilation stage has finished and the registry is ready for lookups and execution.Fields inherited from class valorless.rarespawns.compilers.Compiler
bukkit, classpath, compiler, entityData, fileManager, nms, rarespawns, seperator, server, valorlessutils -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanAdds a compiled Soul Power class to the registry.static voidRemoves temporary .java files from the soulpowers/compiled directory.Gets the compiled class for a Soul Power by ID.Provides a shallow copy of the compiled powers registry.static BooleanisReady()Returns whether the async loading/compiling has completed.Retrieves the names (without extension) of all .java files in the soulpowers/ folder within the plugin's data directory.static StringReads a source file from the soulpowers/ folder into a single String.static voidreload()Clears and asynchronously recompiles all Soul Power scripts from the soulpowers/ directory, then updates the in-memory registry.static voidCreates an instance of the compiled power by ID and invokes its execute method with the provided item data and player.Methods inherited from class valorless.rarespawns.compilers.Compiler
compileAndCacheCode, getBukkit, getEntityData, getNMS, getPluginClasspath, getPluginJar
-
Field Details
-
ready
Indicates whether the async compilation stage has finished and the registry is ready for lookups and execution.
-
-
Constructor Details
-
SoulPowerCompiler
public SoulPowerCompiler()
-
-
Method Details
-
isReady
Returns whether the async loading/compiling has completed.- Returns:
- true if powers are compiled and cached; false otherwise
-
getPowers
Provides a shallow copy of the compiled powers registry.- Returns:
- a copy of the ID -> Class mapping
-
getPower
Gets the compiled class for a Soul Power by ID.- Parameters:
id- the power ID (typically the filename without extension)- Returns:
- the compiled class, or null if not present
-
addPower
Adds a compiled Soul Power class to the registry.- Parameters:
id- the power ID (must be non-empty)instance- the compiled class implementing SoulPower- Returns:
- true if added; false if duplicate or error
- Throws:
Exception- if validation fails (id null/empty) — errors are caught internally and false is returned
-
reload
public static void reload()Clears and asynchronously recompiles all Soul Power scripts from the soulpowers/ directory, then updates the in-memory registry. Logs load time and cleans up temp files afterward. -
readFile
Reads a source file from the soulpowers/ folder into a single String.- Parameters:
filename- the base name without .java extension- Returns:
- the file contents, or null if not found
-
listPowers
Retrieves the names (without extension) of all .java files in the soulpowers/ folder within the plugin's data directory.- Returns:
- a lexicographically sorted list of power file names
-
usePower
public static void usePower(String id, ItemData data, org.bukkit.entity.Player player) throws Exception Creates an instance of the compiled power by ID and invokes its execute method with the provided item data and player.- Parameters:
id- the power IDdata- the item's source data to pass to the powerplayer- the player context for execution- Throws:
Exception- if the class cannot be found/instantiated or reflection fails
-
cleanupTemporaryFiles
public static void cleanupTemporaryFiles()Removes temporary .java files from the soulpowers/compiled directory.
-