Embedding Java code in Skript with skript-mirror

Although Skript and its addons wrap many of the essential utilities from Java and Bukkit, some projects have special requirements that utilize features not yet been implemented by addons. One of the features of skript-mirror is the ability to call arbitrary Java methods and fields, effectively allowing scripters to embed Java code into their scripts and access newer or more obscure parts of Java and Bukkit.

This is not a Java tutorial! In order for this tutorial to make sense, you should understand the basics of methods and fields.

Calling instance methods
%object%.<method descriptor>([%objects%])

A <method descriptor> is the name of the method. The descriptor may also be prefixed with the name of the class in brackets. A class prefix is recommended (and, in certain cases, is required) if the method is private. If you include a class prefix, Skript will error at parse-time if the method does not exist.

set {_test} to "test".toUpperCase()
set {_test} to "test".[java.lang.String]toUpperCase()


Arguments may be passed within the brackets.

set {_test} to "test".charAt(1)


If you want to execute a method without using as an expression (you're calling the method as an effect), you must end the line with a semicolon.

player.setDisplayName("Notch");


Calling instance fields
%object%.<field descriptor>!

A <field descriptor> is the name of the field. The descriptor may also be prefixed with the name of the class in brackets. A class prefix is recommended (and, in certain cases, is required) if the field is private. If you include a class prefix, Skript will error at parse-time if the field does not exist.

set {_test} to player.health!
set {_test} to player.[org.bukkit.craftbukkit.entity.CraftPlayer]health!


Fields may be set or deleted.

set player.health! to 0
delete player.conversationTracker!


Import syntax
import %string% [as %variable%]

The below samples require a reference to a Java type, which can be obtained using the Java type expression [the] ([java] class|java[ ]type) %string%. For convenience, skript-mirror provides import syntax to save a Java type to a variable.

# set {String} to the java class "java.lang.String"
import "java.lang.String"

# set {MyStringType} to the java class "java.lang.String"
import "java.lang.String" as {MyStringType}


Calling static methods
Calling static methods is the same as calling instance methods, but using a Java type as the target object.

{System}.exit(0);


Calling static fields
Calling static fields is the same as calling instance fields, but using a Java type as the target object.

{System}.out!.println();


Calling constructors
new %javatype%([%objects%])

set {_test} to new {String}("copy of another string")