Package net.citizensnpcs.api.scripting
Class ScriptCompiler
java.lang.Object
net.citizensnpcs.api.scripting.ScriptCompiler
Compiles files into
ScriptFactory
s. Intended for use as a separate thread - run(String, String)
will
block while waiting for new tasks to compile.
Works with all installed system ScriptEngine
s. By default compatible with js via Nashorn/Rhino.- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canCompile
(File file) Create a builder to compile the given files.Create a builder to compile the given source code.void
Cancel all running compile tasks.void
registerGlobalContextProvider
(ContextProvider provider) Registers a globalContextProvider
, which will be invoked on all scripts created by this ScriptCompiler.void
void
Run the given source code.
-
Constructor Details
-
ScriptCompiler
-
-
Method Details
-
canCompile
-
compile
Create a builder to compile the given files.- Parameters:
file
- The file to compile- Returns:
- The
ScriptCompiler.CompileTaskBuilder
-
compile
Create a builder to compile the given source code.- Parameters:
src
- The source code to compileidentifier
- A unique identifier of the source codeextension
- The source code externsion- Returns:
- The
ScriptCompiler.CompileTaskBuilder
-
interrupt
public void interrupt()Cancel all running compile tasks. -
registerGlobalContextProvider
Registers a globalContextProvider
, which will be invoked on all scripts created by this ScriptCompiler.- Parameters:
provider
- The global provider
-
run
- Throws:
ScriptException
- See Also:
-
run
Run the given source code.- Parameters:
code
- the source code to compile/runextension
- the code extension e.g. jsvars
- variables to pass to the script- Throws:
ScriptException
-