Importing Java Packages into Scripts

The //!import directive allows you to import Java classes and packages directly into your JavaScript script. This gives your scripts full access to the Java APIs of Bukkit, Spigot, Paper, or any other plugin you're working with.

Importing will not function if disabled in the configuration: UseCustomInterpreter

Syntax

//!import full.qualified.ClassName

You can import as many classes as you need at the top of your script:

//!import org.bukkit.Bukkit
//!import org.bukkit.event.player.PlayerJoinEvent
//!import java.util.logging.Logger

Accessing Imported Classes

Once imported, you can access the class via its full Java path, like:

Bukkit = org.bukkit.Bukkit;
var Logger = java.util.logging.Logger;

You can then use these classes just like you would in Java, but with JavaScript syntax:

var logger = Logger.getLogger("OpenJSPluginLogger");
logger.info("This is a log message.");

Last updated