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.

Extends

Object

Modifiers

public final

Constructors


new Skript (ModifiableCompiler)

Constructor

Create 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.

IndexTypeName
1ModifiableCompilercompiler
Return Type

Skript

Modifiers

public

// Randomly-generated example
final Skript skript = new Skript(compiler);
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);

new Skript ()

Constructor

Create a default Skript runtime with all basic features present. The thread this is created from is treated as the 'main' thread.

Return Type

Skript

Modifiers

public

// Randomly-generated example
final Skript skript = new Skript();
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);

new Skript (SkriptThreadProvider, ModifiableCompiler, Thread)

Constructor

Create a custom Skript runtime with altered providers. The thread provider needs to provide ScriptThread for most features to work.

IndexTypeName
1SkriptThreadProviderprovider
2ModifiableCompilercompiler
3Threadthread
Return Type

Skript

Modifiers

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

Constant

The 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.

Type

ThreadGroup

Modifiers

public static final

// Randomly-generated example
final ThreadGroup group = Skript.THREAD_GROUP;
group.getName();
group.toString();
assert group.list() == null;

VARIABLES

Constant

The global variable map. This is obtainable through the getter method.

Type

GlobalVariableMap

Modifiers

static final

// Randomly-generated example
final GlobalVariableMap map = Skript.VARIABLES;


Methods


getCompiler ()

Method

Returns the provided script compiler.

Return Type

ModifiableCompiler

Modifiers

public

// Randomly-generated example
final ModifiableCompiler compiler = skript.getCompiler();
compiler.clone();
compiler.load(b, string);
compiler.compile(stream, string);

println (Object)

Method
No description is available for this element.
IndexTypeName
1Objectobject
Return Type

void

Modifiers

public

getClass (String)

Method

This searches the app class loader and all library class loaders for the given class. This does not search script class loaders.

IndexTypeName
1Stringname
Return Type

Class

Modifiers

public

// Randomly-generated example
final Class clazz = skript.getClass(name);
clazz.getName();
clazz.forName(name, initialize, loader);
clazz.forName(className);

convert (Object, Class, boolean)

Method
No description is available for this element.
IndexTypeName
1Objectfrom
2Classto
3booleanfail
Return Type

Object

Modifiers

public static

convert (Object, Class)

Method
No description is available for this element.
IndexTypeName
1Objectfrom
2Classto
Return Type

Object

Modifiers

public static

print (Object)

Method
No description is available for this element.
IndexTypeName
1Objectobject
Return Type

void

Modifiers

public

getLoader ()

Method

Gets the parent class-loader attached to this Skript runtime. This is used to search available libraries and scripts for classes.

Return Type

RuntimeClassLoader

Modifiers

public

// Randomly-generated example
final RuntimeClassLoader loader = skript.getLoader();
loader.loadClass(name, bytecode);
loader.loadClass(aClass, name, bytecode);
loader.loadClass(name);

findLoader ()

Method

Attempts 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.

Return Type

RuntimeClassLoader

Modifiers

public static

// Randomly-generated example
final RuntimeClassLoader loader = Skript.findLoader();
loader.loadClass(name, bytecode);
loader.loadClass(aClass, name, bytecode);
loader.loadClass(name);

getScript (Class)

Method
No description is available for this element.
IndexTypeName
1Classpart
Return Type

Script

Modifiers

public

currentLoader ()

Method

Finds 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.

Return Type

RuntimeClassLoader

Modifiers

public static

// Randomly-generated example
final RuntimeClassLoader loader = Skript.currentLoader();
loader.loadClass(name, bytecode);
loader.loadClass(aClass, name, bytecode);
loader.loadClass(name);

getExecutor ()

Method

The executor service this runtime uses. This is separate from the scheduler so that threads can be re-used more efficiently.

Return Type

ExecutorService

Modifiers

public

// Randomly-generated example
final ExecutorService service = skript.getExecutor();
assert service.shutdown() == null;
assert service.isShutdown();
service.submit(runnable);

registerConverter (Class, Class, Converter)

Method
No description is available for this element.
IndexTypeName
1Classfrom
2Classto
3Converterconverter
Return Type

void

Modifiers

public

runEvent (Event, Script)

Method

Trigger all event handlers that can deal with this event. Each handler will spawn its own process. This will trigger only the given script.

IndexTypeName
1Eventevent
2Scriptscript
Return Type

boolean

Modifiers

public

// Randomly-generated example
assert skript.runEvent(event, script);

runEvent (Event)

Method

Trigger all event handlers that can deal with this event. Each handler will spawn its own process.

IndexTypeName
1Eventevent
Return Type

boolean

Modifiers

public

// Randomly-generated example
assert skript.runEvent(event);

currentInstance ()

Method

This 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.

Return Type

Skript

Modifiers

public static

// Randomly-generated example
final Skript skript = Skript.currentInstance();
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);

getConverter (Class, Class)

Method
No description is available for this element.
IndexTypeName
1Classfrom
2Classto
Return Type

Converter

Modifiers

public

runScript (ScriptRunner, Event)

Method

Runs 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!

IndexTypeName
1ScriptRunnerrunner
2Eventevent
Return Type

Future

Modifiers

public

// Randomly-generated example
final Future future = skript.runScript(runner, event);
future.get(j, unit);
future.get();
assert future.cancel(z);

runScript (ScriptRunner)

Method

Runs 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!

IndexTypeName
1ScriptRunnerrunner
Return Type

Future

Modifiers

public

// Randomly-generated example
final Future future = skript.runScript(runner);
future.get(j, unit);
future.get();
assert future.cancel(z);

runScript (Runnable)

Method

Runs 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.

IndexTypeName
1Runnableexecutable
Return Type

Future

Modifiers

public

// Randomly-generated example
final Future future = skript.runScript(executable);
future.get(j, unit);
future.get();
assert future.cancel(z);

unregisterConverter (Class, Class)

Method
No description is available for this element.
IndexTypeName
1Classfrom
2Classto
Return Type

void

Modifiers

public

hasCompiler ()

Method

Whether this Skript runtime has a compiler.

Return Type

boolean

Modifiers

public

// Randomly-generated example
assert skript.hasCompiler();

compileComplexScript (InputStream, String, File)

Method

Compiles a complex script to multiple class files in the output directory.

IndexTypeName
1InputStreaminput
2Stringname
3FileoutputDirectory
Return Type

Collection

Modifiers

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)

Method

Compiles a single script to its class files. This method may be unavailable in some distributions.

IndexTypeName
1InputStreamstream
2Stringname
Return Type

PostCompileClass[]

Modifiers

public

// Randomly-generated example
final PostCompileClass[] class = skript.compileComplexScript(stream, name);

compileScript (String, String)

Method

Compiles a simple script from its string source to a memory class. This method may be unavailable in some distributions.

IndexTypeName
1Stringcode
2Stringname
Return Type

PostCompileClass

Modifiers

public

// Randomly-generated example
final PostCompileClass class = skript.compileScript(code, name);
class.name();
assert class.equals(o);
class.toString();

compileScript (InputStream, String, OutputStream)

Method

Compiles a source input stream and writes it to a target output stream. This can compile only simple scripts (which create a single class file.)

IndexTypeName
1InputStreaminput
2Stringname
3OutputStreamtarget
Return Type

void

Modifiers

public

// Randomly-generated example
skript.compileScript(input, name, target);

compileScript (InputStream, String)

Method

Compiles a simple script from its source to a memory class. This method may be unavailable in some distributions.

IndexTypeName
1InputStreamstream
2Stringname
Return Type

PostCompileClass

Modifiers

public

// Randomly-generated example
final PostCompileClass class = skript.compileScript(stream, name);
class.name();
assert class.equals(o);
class.toString();

compileComplexScriptAsync (InputStream, String)

Method

Compiles 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.

IndexTypeName
1InputStreamstream
2Stringname
Return Type

Promise

Modifiers

public

// Randomly-generated example
final Promise promise = skript.compileComplexScriptAsync(stream, name);
promise.get();
promise.get(timeout, unit);
assert promise.cancel(mayInterruptIfRunning);

unloadScript (Class)

Method

Unloads a script by its main class. This is a destructive operation.

IndexTypeName
1Classmain
Return Type

void

Modifiers

public

// Randomly-generated example
skript.unloadScript(main);

unloadScript (Script)

Method

Unloads 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.

IndexTypeName
1Scriptscript
Return Type

void

Modifiers

public

// Randomly-generated example
skript.unloadScript(script);

compileLoad (File, String)

Method

This is designed for internal use.

IndexTypeName
1Filefile
2Stringname
Return Type

Script

Modifiers

public

compileLoad (InputStream, String)

Method

This is designed for internal use.

IndexTypeName
1InputStreamstream
2Stringname
Return Type

Script

Modifiers

public

loadScript (byte[], String)

Method

Loads a script from its compiled bytecode and class name.

IndexTypeName
1byte[]bytecode
2Stringname
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(bytecode, name);
script.toString();
script.getSimpleName();
script.classes();

loadScript (File)

Method

Loads a script from its compiled class file.

IndexTypeName
1Filesource
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(source);
script.toString();
script.getSimpleName();
script.classes();

loadScript (InputStream, String)

Method

Loads a script from a stream of its compiled bytecode.

IndexTypeName
1InputStreamstream
2Stringname
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(stream, name);
script.toString();
script.getSimpleName();
script.classes();

loadScript (File, String)

Method

Loads a script from its compiled class file.

IndexTypeName
1Filesource
2Stringname
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(source, name);
script.toString();
script.getSimpleName();
script.classes();

loadScript (PostCompileClass[])

Method

Loads a script from compiled source code.

IndexTypeName
1PostCompileClass[]data
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(data);
script.toString();
script.getSimpleName();
script.classes();

loadScript (Class[])

Method

Loads a script from defined classes.

IndexTypeName
1Class[]loaded
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(loaded);
script.toString();
script.getSimpleName();
script.classes();

loadScript (InputStream)

Method

Loads a script from a stream of its compiled bytecode.

IndexTypeName
1InputStreamstream
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(stream);
script.toString();
script.getSimpleName();
script.classes();

loadScript (Class)

Method

Loads a script from a defined class.

IndexTypeName
1Classloaded
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(loaded);
script.toString();
script.getSimpleName();
script.classes();

loadScript (PostCompileClass)

Method

Loads a script from compiled source code.

IndexTypeName
1PostCompileClassdatum
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(datum);
script.toString();
script.getSimpleName();
script.classes();

loadScript (byte[])

Method

Loads a script from its compiled bytecode. The name is determined by reading the class name entry from the code.

IndexTypeName
1byte[]bytecode
Return Type

Script

Modifiers

public

// Randomly-generated example
final Script script = skript.loadScript(bytecode);
script.toString();
script.getSimpleName();
script.classes();

assembleScript (Class...)

Method

Assembles a script from defined classes.

IndexTypeName
1Class[]loaded
Return Type

Script

Modifiers

public varargs

// Randomly-generated example
final Script script = skript.assembleScript(loaded);
script.toString();
script.getSimpleName();
script.classes();

assembleScript (PostCompileClass...)

Method

Assembles 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.

IndexTypeName
1PostCompileClass[]data
Return Type

Script

Modifiers

public varargs

// Randomly-generated example
final Script script = skript.assembleScript(data);
script.toString();
script.getSimpleName();
script.classes();

schedule (Runnable, long)

Method

Schedules a task to be run at some point in the future.

IndexTypeName
1Runnablerunnable
2longmillis
Return Type

Future

Modifiers

public

// Randomly-generated example
final Future future = skript.schedule(runnable, millis);
future.get(j, unit);
future.get();
assert future.cancel(z);

localLoader ()

Method

Gets the parent class-loader local to this thread. This is only usable from a script thread.

Return Type

RuntimeClassLoader

Modifiers

public static

// Randomly-generated example
final RuntimeClassLoader loader = Skript.localLoader();
loader.loadClass(name, bytecode);
loader.loadClass(aClass, name, bytecode);
loader.loadClass(name);

getVariables ()

Method

This 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.

Return Type

GlobalVariableMap

Modifiers

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 ()

Method

This returns the Skript instance that launched the current thread. This is available only to scripts.

Return Type

Skript

Modifiers

public static

// Randomly-generated example
final Skript skript = Skript.localInstance();
skript.getCompiler();
assert skript.println(object) == null;
skript.getClass(name);

findAnyClass (String)

Method
No description is available for this element.
IndexTypeName
1Stringname
Return Type

Class

Modifiers

public static

getOperatorFunction (Type, Class, Class)

Method
No description is available for this element.
IndexTypeName
1Typetype
2Classfirst
3Classsecond
Return Type

OperatorFunction

Modifiers

public

runOnAsyncThread (Runnable)

Method

Submits this instruction to a background thread. Background threads are safe for blocking.

IndexTypeName
1Runnablerunnable
Return Type

void

Modifiers

public

// Randomly-generated example
skript.runOnAsyncThread(runnable);

runOnAsyncThread (Instruction)

Method

Submits this instruction to a background thread. Background threads are safe for blocking.

IndexTypeName
1Instructionrunnable
Return Type

void

Modifiers

public

// Randomly-generated example
skript.runOnAsyncThread(runnable);

getOnAsyncThread (Instruction)

Method

Submits this future to a background thread. Background threads are safe for blocking.

IndexTypeName
1Instructionrunnable
Return Type

Future

Modifiers

public

// Randomly-generated example
final Future future = skript.getOnAsyncThread(runnable);
future.get(j, unit);
future.get();
assert future.cancel(z);

getScripts ()

Method

Gets 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.

Return Type

Script[]

Modifiers

public

// Randomly-generated example
final Script[] script = skript.getScripts();

getProcesses ()

Method

A 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.

Return Type

Collection

Modifiers

public

// Randomly-generated example
final Collection collection = skript.getProcesses();
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);

registerEventHandler (Class, ScriptRunner)

Method

Registers 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.

IndexTypeName
1Classevent
2ScriptRunnerrunner
Return Type

void

Modifiers

public

// Randomly-generated example
skript.registerEventHandler(event, runner);

registerLibraryClass (byte[])

Method

Registers 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.

IndexTypeName
1byte[]bytecode
Return Type

void

Modifiers

public

// Randomly-generated example
skript.registerLibraryClass(bytecode);

registerLibrary (Library)

Method

Registers a library instance to the current compiler.

IndexTypeName
1Librarylibrary
Return Type

boolean

Modifiers

public

// Randomly-generated example
assert skript.registerLibrary(library);

unregisterLibrary (Library)

Method

Removes a library instance from the current compiler.

IndexTypeName
1Librarylibrary
Return Type

boolean

Modifiers

public

// Randomly-generated example
assert skript.unregisterLibrary(library);

getLoadedLibraries ()

Method

Returns an array of all registered libraries.

Return Type

Library[]

Modifiers

public

// Randomly-generated example
final Library[] library = skript.getLoadedLibraries();

compileScripts (File)

Method

Compiles all scripts in the root file to code representations. These representations may be loaded, written to files or otherwise used.

IndexTypeName
1Fileroot
Return Type

PostCompileClass[]

Modifiers

public

// Randomly-generated example
final PostCompileClass[] class = skript.compileScripts(root);

compileScripts (File, File)

Method

Compiles 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.

IndexTypeName
1Fileroot
2FileoutputDirectory
Return Type

Collection

Modifiers

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)

Method

Compiles a simple script from its string source to a memory class. This method may be unavailable in some distributions.

IndexTypeName
1Stringcode
2Stringname
Return Type

Promise

Modifiers

public

// Randomly-generated example
final Promise promise = skript.compileScriptAsync(code, name);
promise.get();
promise.get(timeout, unit);
assert promise.cancel(mayInterruptIfRunning);

loadScripts (File)

Method

Loads 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.

IndexTypeName
1Fileroot
Return Type

Collection

Modifiers

public

// Randomly-generated example
final Collection collection = skript.loadScripts(root);
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);

loadScripts (PostCompileClass[])

Method

Loads scripts from compiled source code.

IndexTypeName
1PostCompileClass[]data
Return Type

Collection

Modifiers

public

// Randomly-generated example
final Collection collection = skript.loadScripts(data);
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);

compileLoadScripts (File)

Method

Compiles and loads all scripts from a source directory. This method may be unavailable in some distributions.

IndexTypeName
1Fileroot
Return Type

Collection

Modifiers

public

// Randomly-generated example
final Collection collection = skript.compileLoadScripts(root);
assert collection.add(object);
assert collection.remove(object);
assert collection.equals(object);

setOutput (PrintStream)

Method

Set the current print stream used by the print effect. This can be used to redirect output in a particular state.

IndexTypeName
1PrintStreamout
Return Type

void

Modifiers

public

allocateProcess (OperationController, Runnable, boolean)

Method

Generates a script thread from the given process.

IndexTypeName
1OperationControllercontroller
2Runnablerunnable
3booleaninheritLocals
Return Type

Thread

Modifiers

public

// Randomly-generated example
final Thread thread = skript.allocateProcess(controller, runnable, inheritLocals);
thread.getName();
assert thread.run() == null;
thread.toString();

getMainThread ()

Method

The 'main' thread this runtime was given. This is used mostly for locking.

Return Type

Thread

Modifiers

public

getScheduler ()

Method

The scheduler service this runtime uses.

Return Type

ScheduledExecutorService

Modifiers

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);