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.
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.");
This example is for demonstration only.
Logging directly with java.util.logging.Logger
will obscure the log source, making debugging and support difficult.
It is recommended to use the embedded logging system instead.
Last updated