Skript callbacks

Expose Skript sections to Java for synchronous invocation.

Register a section

A java callback section registers named code for the current event. Registration does not execute its body.

command /javacallback:
    trigger:
        java callback "notify":
            send "Java returned %{_java_callback_value}%" to player
        execute java:
            consumer("notify").accept("Hello!");

Java interfaces

consumer("notify") returns a Consumer<Object> and temporarily exposes its argument through {_java_callback_value}. The previous value is restored after invocation.

callback("name") exposes a Runnable for invocation without an argument. External APIs must invoke it synchronously while the original event is still valid.

Constraints

  • Register the section before accessing it from Java.
  • Invocation is allowed only on the main server thread.
  • wait and delays inside the section are rejected during parsing.
  • Do not retain callbacks in libraries for delayed execution or pass them to background executors.
  • Unknown names or expired events cause errors; registrations are cleared on reload and shutdown.

This bridges a Skript section; it is not a scheduler. Ordinary Java lambdas can also be passed directly to approved Java APIs without registering a callback section.

Type a query to search the guide.