Skript
Class
This class is the entry-point for any program or library using ByteSkript. Programs looking to implement Skript can create an instance of this with custom (or default) compilers, thread managers, etc. Programs looking to interact with Skript can compile, load, unload and trigger events from here. Some resources are available in the static state, but these will relate to an arbitrary Skript instance that may not be running, present, etc.
Object
public final
Constructors
new Skript (ModifiableCompiler)
ConstructorCreate a Skript runtime with a custom (non-default) Skript compiler. This is used by the Jar-form script loader, which has no compiler.
Some compilers may offer only partial support, such as ByteSkriptQuery's page compiler.
This is different from the BridgeCompiler which is included in all distributions.
The thread this is created from is treated as the 'main' thread.
Index | Type | Name |
---|---|---|
1 | ModifiableCompiler | compiler |
Skript
public
// Randomly-generated example
final Skript skript = new Skript(compiler);
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);
new Skript ()
ConstructorCreate a default Skript runtime with all basic features present. The thread this is created from is treated as the 'main' thread.
Skript
public
// Randomly-generated example
final Skript skript = new Skript();
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);
new Skript (SkriptThreadProvider, ModifiableCompiler, Thread)
ConstructorCreate a custom Skript runtime with altered providers. The thread provider needs to provide ScriptThread for most features to work.
Index | Type | Name |
---|---|---|
1 | SkriptThreadProvider | provider |
2 | ModifiableCompiler | compiler |
3 | Thread | thread |
Skript
public
// Randomly-generated example
final Skript skript = new Skript(provider, compiler, thread);
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);
Fields
THREAD_GROUP
ConstantThe script thread group.
If you are implementing a special thread provider that script code will use, it should use this group to for more accurate clean-up and profiling.
ThreadGroup
public static final
// Randomly-generated example
final ThreadGroup group = Skript.THREAD_GROUP;
group.getName();
group.toString();
assert group.list() == null;
VARIABLES
ConstantThe global variable map. This is obtainable through the getter method.
GlobalVariableMap
static final
// Randomly-generated example
final GlobalVariableMap map = Skript.VARIABLES;
Methods
getCompiler ()
MethodReturns the provided script compiler.
ModifiableCompiler
public
// Randomly-generated example
final ModifiableCompiler compiler = skript.getCompiler();
compiler.clone();
compiler.load(b, string);
compiler.compile(stream, string);
println (Object)
MethodIndex | Type | Name |
---|---|---|
1 | Object | object |
void
public
getClass (String)
MethodThis searches the app class loader and all library class loaders for the given class. This does not search script class loaders.
Index | Type | Name |
---|---|---|
1 | String | name |
Class
public
// Randomly-generated example
final Class clazz = skript.getClass(name);
clazz.getName();
clazz.forName(name, initialize, loader);
clazz.forName(className);
convert (Object, Class, boolean)
MethodIndex | Type | Name |
---|---|---|
1 | Object | from |
2 | Class | to |
3 | boolean | fail |
Object
public static
convert (Object, Class)
MethodIndex | Type | Name |
---|---|---|
1 | Object | from |
2 | Class | to |
Object
public static
print (Object)
MethodIndex | Type | Name |
---|---|---|
1 | Object | object |
void
public
getLoader ()
MethodGets the parent class-loader attached to this Skript runtime. This is used to search available libraries and scripts for classes.
RuntimeClassLoader
public
// Randomly-generated example
final RuntimeClassLoader loader = skript.getLoader();
loader.loadClass(name, bytecode);
loader.loadClass(aClass, name, bytecode);
loader.loadClass(name);
findLoader ()
MethodAttempts to find the parent class-loader. This will look for a local loader but default to the most-recently-created. This is designed for internal use.
RuntimeClassLoader
public static
// Randomly-generated example
final RuntimeClassLoader loader = Skript.findLoader();
loader.loadClass(name, bytecode);
loader.loadClass(aClass, name, bytecode);
loader.loadClass(name);
getScript (Class)
MethodIndex | Type | Name |
---|---|---|
1 | Class | part |
Script
public
currentLoader ()
MethodFinds an arbitrary parent class-loader. This will use the most recently-created Skript runtime.
This is unsafe, since it is unlikely to be the required loader.
RuntimeClassLoader
public static
// Randomly-generated example
final RuntimeClassLoader loader = Skript.currentLoader();
loader.loadClass(name, bytecode);
loader.loadClass(aClass, name, bytecode);
loader.loadClass(name);
getExecutor ()
MethodThe executor service this runtime uses. This is separate from the scheduler so that threads can be re-used more efficiently.
ExecutorService
public
// Randomly-generated example
final ExecutorService service = skript.getExecutor();
assert service.shutdown() == null;
assert service.isShutdown();
service.submit(runnable);
registerConverter (Class, Class, Converter)
MethodIndex | Type | Name |
---|---|---|
1 | Class | from |
2 | Class | to |
3 | Converter | converter |
void
public
runEvent (Event, Script)
MethodTrigger all event handlers that can deal with this event. Each handler will spawn its own process. This will trigger only the given script.
Index | Type | Name |
---|---|---|
1 | Event | event |
2 | Script | script |
boolean
public
// Randomly-generated example
assert skript.runEvent(event, script);
runEvent (Event)
MethodTrigger all event handlers that can deal with this event. Each handler will spawn its own process.
Index | Type | Name |
---|---|---|
1 | Event | event |
boolean
public
// Randomly-generated example
assert skript.runEvent(event);
currentInstance ()
MethodThis returns the most recently-created Skript runtime. It is designed to be an entry-point for programs that attach in an unusual way, and have no other way of getting the current Skript instance.
Multiple or zero runtimes may exist - this should not be depended upon.
Skript
public static
// Randomly-generated example
final Skript skript = Skript.currentInstance();
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);
getConverter (Class, Class)
MethodIndex | Type | Name |
---|---|---|
1 | Class | from |
2 | Class | to |
Converter
public
runScript (ScriptRunner, Event)
MethodRuns a script with a completing future. This is designed for use in places like JUnit tests that require throttling.
This is not designed for throttling the main thread, since the airlock queue will already do this!
Index | Type | Name |
---|---|---|
1 | ScriptRunner | runner |
2 | Event | event |
Future
public
// Randomly-generated example
final Future future = skript.runScript(runner, event);
future.get(j, unit);
future.get();
assert future.cancel(z);
runScript (ScriptRunner)
MethodRuns a script with a completing future. This is designed for use in places like JUnit tests that require throttling.
This is not designed for throttling the main thread, since the airlock queue will already do this!
Index | Type | Name |
---|---|---|
1 | ScriptRunner | runner |
Future
public
// Randomly-generated example
final Future future = skript.runScript(runner);
future.get(j, unit);
future.get();
assert future.cancel(z);
runScript (Runnable)
MethodRuns a runnable on a script thread. This is designed for running anonymous script chunks.
This can also be used to run code that did not originate from a script as though it did.
Index | Type | Name |
---|---|---|
1 | Runnable | executable |
Future
public
// Randomly-generated example
final Future future = skript.runScript(executable);
future.get(j, unit);
future.get();
assert future.cancel(z);
unregisterConverter (Class, Class)
MethodIndex | Type | Name |
---|---|---|
1 | Class | from |
2 | Class | to |
void
public
hasCompiler ()
MethodWhether this Skript runtime has a compiler.
boolean
public
// Randomly-generated example
assert skript.hasCompiler();
compileComplexScript (InputStream, String, File)
MethodCompiles a complex script to multiple class files in the output directory.
Index | Type | Name |
---|---|---|
1 | InputStream | input |
2 | String | name |
3 | File | outputDirectory |
Collection
public
// Randomly-generated example
final Collection collection = skript.compileComplexScript(input, name, outputDirectory);
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);
compileComplexScript (InputStream, String)
MethodCompiles a single script to its class files. This method may be unavailable in some distributions.
Index | Type | Name |
---|---|---|
1 | InputStream | stream |
2 | String | name |
PostCompileClass[]
public
// Randomly-generated example
final PostCompileClass[] class = skript.compileComplexScript(stream, name);
compileScript (String, String)
MethodCompiles a simple script from its string source to a memory class. This method may be unavailable in some distributions.
Index | Type | Name |
---|---|---|
1 | String | code |
2 | String | name |
PostCompileClass
public
// Randomly-generated example
final PostCompileClass class = skript.compileScript(code, name);
class.name();
assert class.equals(o);
class.toString();
compileScript (InputStream, String, OutputStream)
MethodCompiles a source input stream and writes it to a target output stream. This can compile only simple scripts (which create a single class file.)
Index | Type | Name |
---|---|---|
1 | InputStream | input |
2 | String | name |
3 | OutputStream | target |
void
public
// Randomly-generated example
skript.compileScript(input, name, target);
compileScript (InputStream, String)
MethodCompiles a simple script from its source to a memory class. This method may be unavailable in some distributions.
Index | Type | Name |
---|---|---|
1 | InputStream | stream |
2 | String | name |
PostCompileClass
public
// Randomly-generated example
final PostCompileClass class = skript.compileScript(stream, name);
class.name();
assert class.equals(o);
class.toString();
compileComplexScriptAsync (InputStream, String)
MethodCompiles a single script to its class files. This version runs in the background and returns a promise This method may be unavailable in some distributions.
Index | Type | Name |
---|---|---|
1 | InputStream | stream |
2 | String | name |
Promise
public
// Randomly-generated example
final Promise promise = skript.compileComplexScriptAsync(stream, name);
promise.get();
promise.get(timeout, unit);
assert promise.cancel(mayInterruptIfRunning);
unloadScript (Class)
MethodUnloads a script by its main class. This is a destructive operation.
Index | Type | Name |
---|---|---|
1 | Class | main |
void
public
// Randomly-generated example
skript.unloadScript(main);
unloadScript (Script)
MethodUnloads a script. This is a destructive operation. All metadata for the script will be 'graveyarded' - its memory address will be erased. Anything keeping a reference to the script will prevent it being garbage-collected.
Index | Type | Name |
---|---|---|
1 | Script | script |
void
public
// Randomly-generated example
skript.unloadScript(script);
compileLoad (File, String)
MethodThis is designed for internal use.
Index | Type | Name |
---|---|---|
1 | File | file |
2 | String | name |
Script
public
compileLoad (InputStream, String)
MethodThis is designed for internal use.
Index | Type | Name |
---|---|---|
1 | InputStream | stream |
2 | String | name |
Script
public
loadScript (byte[], String)
MethodLoads a script from its compiled bytecode and class name.
Index | Type | Name |
---|---|---|
1 | byte[] | bytecode |
2 | String | name |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(bytecode, name);
script.toString();
script.getSimpleName();
script.classes();
loadScript (File)
MethodLoads a script from its compiled class file.
Index | Type | Name |
---|---|---|
1 | File | source |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(source);
script.toString();
script.getSimpleName();
script.classes();
loadScript (InputStream, String)
MethodLoads a script from a stream of its compiled bytecode.
Index | Type | Name |
---|---|---|
1 | InputStream | stream |
2 | String | name |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(stream, name);
script.toString();
script.getSimpleName();
script.classes();
loadScript (File, String)
MethodLoads a script from its compiled class file.
Index | Type | Name |
---|---|---|
1 | File | source |
2 | String | name |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(source, name);
script.toString();
script.getSimpleName();
script.classes();
loadScript (PostCompileClass[])
MethodLoads a script from compiled source code.
Index | Type | Name |
---|---|---|
1 | PostCompileClass[] | data |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(data);
script.toString();
script.getSimpleName();
script.classes();
loadScript (Class[])
MethodLoads a script from defined classes.
Index | Type | Name |
---|---|---|
1 | Class[] | loaded |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(loaded);
script.toString();
script.getSimpleName();
script.classes();
loadScript (InputStream)
MethodLoads a script from a stream of its compiled bytecode.
Index | Type | Name |
---|---|---|
1 | InputStream | stream |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(stream);
script.toString();
script.getSimpleName();
script.classes();
loadScript (Class)
MethodLoads a script from a defined class.
Index | Type | Name |
---|---|---|
1 | Class | loaded |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(loaded);
script.toString();
script.getSimpleName();
script.classes();
loadScript (PostCompileClass)
MethodLoads a script from compiled source code.
Index | Type | Name |
---|---|---|
1 | PostCompileClass | datum |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(datum);
script.toString();
script.getSimpleName();
script.classes();
loadScript (byte[])
MethodLoads a script from its compiled bytecode. The name is determined by reading the class name entry from the code.
Index | Type | Name |
---|---|---|
1 | byte[] | bytecode |
Script
public
// Randomly-generated example
final Script script = skript.loadScript(bytecode);
script.toString();
script.getSimpleName();
script.classes();
assembleScript (Class...)
MethodAssembles a script from defined classes.
Index | Type | Name |
---|---|---|
1 | Class[] | loaded |
Script
public varargs
// Randomly-generated example
final Script script = skript.assembleScript(loaded);
script.toString();
script.getSimpleName();
script.classes();
assembleScript (PostCompileClass...)
MethodAssembles a script in memory without loading it. It is not safe to assume this script will never be triggered or loaded. This registers the event handlers, which will be triggered if an event occurs in the meantime.
Index | Type | Name |
---|---|---|
1 | PostCompileClass[] | data |
Script
public varargs
// Randomly-generated example
final Script script = skript.assembleScript(data);
script.toString();
script.getSimpleName();
script.classes();
schedule (Runnable, long)
MethodSchedules a task to be run at some point in the future.
Index | Type | Name |
---|---|---|
1 | Runnable | runnable |
2 | long | millis |
Future
public
// Randomly-generated example
final Future future = skript.schedule(runnable, millis);
future.get(j, unit);
future.get();
assert future.cancel(z);
localLoader ()
MethodGets the parent class-loader local to this thread. This is only usable from a script thread.
RuntimeClassLoader
public static
// Randomly-generated example
final RuntimeClassLoader loader = Skript.localLoader();
loader.loadClass(name, bytecode);
loader.loadClass(aClass, name, bytecode);
loader.loadClass(name);
getVariables ()
MethodThis is the map of global {!var}
variables.
This is a modifiable and atomic map.
Destroying this map's contents without warning is not advised.
The global map is kept in the static state so that it can be truly 'global' and runtime-independent. This also solves some problems with locking during atomic access.
GlobalVariableMap
public static
// Randomly-generated example
final GlobalVariableMap map = Skript.getVariables();
assert map.setVariable(name, value) == null;
assert map.deleteVariable(name) == null;
assert map.addVariable(name, value) == null;
localInstance ()
MethodThis returns the Skript instance that launched the current thread. This is available only to scripts.
Skript
public static
// Randomly-generated example
final Skript skript = Skript.localInstance();
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);
findAnyClass (String)
MethodIndex | Type | Name |
---|---|---|
1 | String | name |
Class
public static
getOperatorFunction (Type, Class, Class)
MethodIndex | Type | Name |
---|---|---|
1 | Type | type |
2 | Class | first |
3 | Class | second |
OperatorFunction
public
runOnAsyncThread (Runnable)
MethodSubmits this instruction to a background thread. Background threads are safe for blocking.
Index | Type | Name |
---|---|---|
1 | Runnable | runnable |
void
public
// Randomly-generated example
skript.runOnAsyncThread(runnable);
runOnAsyncThread (Instruction)
MethodSubmits this instruction to a background thread. Background threads are safe for blocking.
Index | Type | Name |
---|---|---|
1 | Instruction | runnable |
void
public
// Randomly-generated example
skript.runOnAsyncThread(runnable);
getOnAsyncThread (Instruction)
MethodSubmits this future to a background thread. Background threads are safe for blocking.
Index | Type | Name |
---|---|---|
1 | Instruction | runnable |
Future
public
// Randomly-generated example
final Future future = skript.getOnAsyncThread(runnable);
future.get(j, unit);
future.get();
assert future.cancel(z);
getScripts ()
MethodGets a copy of the handles for all loaded scripts. Storing a strong reference to these will prevent them being unloaded safely. These can be graveyarded (annulled in memory) without warning.
This is designed for looping and discarding.
Script[]
public
// Randomly-generated example
final Script[] script = skript.getScripts();
getProcesses ()
MethodA collection of the operation controllers for script processes. These should not be stored unless necessary - they hold a strong reference to the Skript runtime which could prevent garbage collection.
Collection
public
// Randomly-generated example
final Collection collection = skript.getProcesses();
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);
registerEventHandler (Class, ScriptRunner)
MethodRegisters an event handler for a particular event. Internally, this is used only during script loading. It has been made available in case a program wants to be notified about a Skript event.
Index | Type | Name |
---|---|---|
1 | Class | event |
2 | ScriptRunner | runner |
void
public
// Randomly-generated example
skript.registerEventHandler(event, runner);
registerLibraryClass (byte[])
MethodRegisters a single class library, typically compiled from a script to load custom syntax. Classes in this loader do not need to be reached post-loading - the script that provides the actual implementation for the syntax will be used instead.
Index | Type | Name |
---|---|---|
1 | byte[] | bytecode |
void
public
// Randomly-generated example
skript.registerLibraryClass(bytecode);
registerLibrary (Library)
MethodRegisters a library instance to the current compiler.
Index | Type | Name |
---|---|---|
1 | Library | library |
boolean
public
// Randomly-generated example
assert skript.registerLibrary(library);
unregisterLibrary (Library)
MethodRemoves a library instance from the current compiler.
Index | Type | Name |
---|---|---|
1 | Library | library |
boolean
public
// Randomly-generated example
assert skript.unregisterLibrary(library);
getLoadedLibraries ()
MethodReturns an array of all registered libraries.
Library[]
public
// Randomly-generated example
final Library[] library = skript.getLoadedLibraries();
compileScripts (File)
MethodCompiles all scripts in the root file to code representations. These representations may be loaded, written to files or otherwise used.
Index | Type | Name |
---|---|---|
1 | File | root |
PostCompileClass[]
public
// Randomly-generated example
final PostCompileClass[] class = skript.compileScripts(root);
compileScripts (File, File)
MethodCompiles all scripts in the root directory to the output directory. This is used by the 'compile' goal. This is designed for use by compiler apps rather than programs.
Index | Type | Name |
---|---|---|
1 | File | root |
2 | File | outputDirectory |
Collection
public
// Randomly-generated example
final Collection collection = skript.compileScripts(root, outputDirectory);
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);
compileScriptAsync (String, String)
MethodCompiles a simple script from its string source to a memory class. This method may be unavailable in some distributions.
Index | Type | Name |
---|---|---|
1 | String | code |
2 | String | name |
Promise
public
// Randomly-generated example
final Promise promise = skript.compileScriptAsync(code, name);
promise.get();
promise.get(timeout, unit);
assert promise.cancel(mayInterruptIfRunning);
loadScripts (File)
MethodLoads all compiled classes from the given root file as scripts. This is not a safe operation - not all compiled classes are suitable to be loaded in this way.
Index | Type | Name |
---|---|---|
1 | File | root |
Collection
public
// Randomly-generated example
final Collection collection = skript.loadScripts(root);
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);
loadScripts (PostCompileClass[])
MethodLoads scripts from compiled source code.
Index | Type | Name |
---|---|---|
1 | PostCompileClass[] | data |
Collection
public
// Randomly-generated example
final Collection collection = skript.loadScripts(data);
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);
compileLoadScripts (File)
MethodCompiles and loads all scripts from a source directory. This method may be unavailable in some distributions.
Index | Type | Name |
---|---|---|
1 | File | root |
Collection
public
// Randomly-generated example
final Collection collection = skript.compileLoadScripts(root);
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);
setOutput (PrintStream)
MethodSet the current print stream used by the print
effect.
This can be used to redirect output in a particular state.
Index | Type | Name |
---|---|---|
1 | PrintStream | out |
void
public
allocateProcess (OperationController, Runnable, boolean)
MethodGenerates a script thread from the given process.
Index | Type | Name |
---|---|---|
1 | OperationController | controller |
2 | Runnable | runnable |
3 | boolean | inheritLocals |
Thread
public
// Randomly-generated example
final Thread thread = skript.allocateProcess(controller, runnable, inheritLocals);
thread.getName();
assert thread.run() == null;
thread.toString();
getMainThread ()
MethodThe 'main' thread this runtime was given. This is used mostly for locking.
Thread
public
getScheduler ()
MethodThe scheduler service this runtime uses.
ScheduledExecutorService
public
// Randomly-generated example
final ScheduledExecutorService service = skript.getScheduler();
service.scheduleWithFixedDelay(runnable, j, j, unit);
service.schedule(runnable, j, unit);
service.schedule(callable, j, unit);