Package valorless.rarespawns.compilers
Class Compiler
java.lang.Object
valorless.rarespawns.compilers.Compiler
- Direct Known Subclasses:
AbilityCompiler,SoulPowerCompiler
Runtime Java source compiler and loader for RareSpawns scripts.
Compiles .java files located under the plugin data folder for different script types (e.g., abilities and soul powers), then loads the resulting class into memory using a dedicated class loader. The compiler configures a classpath that includes the plugin, server, Bukkit API, ValorlessUtils, EntityData, optional NMS (if present), and optionally additional entries from advanced.yml when the "i-understand" flag is true.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringBukkit classpath.protected static final StringCombined classpath for compilation.protected final JavaCompilerJava compiler instance for dynamic compilation.protected static final StringEntityData classpath.protected final StandardJavaFileManagerFile manager for handling Java source files.protected static final StringNMS (net.minecraft.server) classpath, if available.protected static final StringRareSpawns classpath.protected static final StringPath separator for the current operating system.protected static final StringServer classpath (java.class.path).protected static final StringValorlessUtils classpath. -
Constructor Summary
ConstructorsConstructorDescriptionCompiler()Creates a compiler instance backed by the system JDK compiler and a standard file manager. -
Method Summary
Modifier and TypeMethodDescriptionClass<?> compileAndCacheCode(String id, CompilerType type) Compiles the source associated with the provided id in the folder designated by the givenCompilerType, writes a temporary source file with additional imports, and loads the resulting class via a type-specific dynamic class loader.static FileGets the Bukkit JAR file location.static FileGets the EntityData JAR file location.static StringgetNMS()Gets the NMS (net.minecraft.server) JAR file location if available.static StringgetPluginClasspath(String plugin) Gets the classpath for a given plugin located in the plugins folder.static FileGets the plugin's JAR file location.
-
Field Details
-
compiler
Java compiler instance for dynamic compilation. -
fileManager
File manager for handling Java source files. -
seperator
Path separator for the current operating system. -
rarespawns
RareSpawns classpath. -
server
Server classpath (java.class.path). -
bukkit
Bukkit classpath. -
entityData
EntityData classpath. -
nms
NMS (net.minecraft.server) classpath, if available. -
valorlessutils
ValorlessUtils classpath. -
classpath
Combined classpath for compilation.
-
-
Constructor Details
-
Compiler
public Compiler()Creates a compiler instance backed by the system JDK compiler and a standard file manager. Requires the server to run on a JDK (not a JRE).
-
-
Method Details
-
compileAndCacheCode
Compiles the source associated with the provided id in the folder designated by the givenCompilerType, writes a temporary source file with additional imports, and loads the resulting class via a type-specific dynamic class loader.The compilation classpath is built from internal paths (plugin/server/Bukkit/etc.) and may be extended from advanced.yml if "i-understand" is true.
- Parameters:
id- filename without extension under the type path (e.g. "Fireball")type- which script category to compile (determines subfolder and loader)- Returns:
- the loaded Class if compilation and loading succeed; otherwise null
- Throws:
Exception- if the Java compiler is unavailable or compilation fails
-
getPluginJar
Gets the plugin's JAR file location.- Returns:
- The File object representing the plugin JAR.
-
getBukkit
Gets the Bukkit JAR file location.- Returns:
- The File object representing the Bukkit JAR.
-
getNMS
Gets the NMS (net.minecraft.server) JAR file location if available.- Returns:
- The absolute path to the NMS JAR, or empty string if not found.
-
getEntityData
Gets the EntityData JAR file location.- Returns:
- The File object representing the EntityData JAR.
-
getPluginClasspath
Gets the classpath for a given plugin located in the plugins folder.- Parameters:
plugin- The name of the plugin (e.g., "SomePlugin.jar").- Returns:
- The absolute path to the plugin JAR, or null if an error occurs.
-