How to use external plugins in scripts
By default you should see if the plugin you want to use is a Service. If it is not available as a service you will have to manually import with the plugin’s Java API classes and methods within your script.
Example: Integrating CoreProtect
CoreProtect does not have a Service wrapper, but you can still access its API using Java reflection and Bukkit plugin management:
const CoreProtect = importClass("net.coreprotect.CoreProtect")
const CoreProtectAPI = importClass("net.coreprotect.CoreProtectAPI")
var Bukkit = org.bukkit.Bukkit;
var CoreProtectPlugin = Bukkit.getPluginManager().getPlugin("CoreProtect");
var CoreProtectAPI = getMethod(CoreProtect, "getAPI").invoke(CoreProtectPlugin);
CoreProtectAPI.testAPI(); // Example call to CoreProtect APIFor more info on CoreProtect's API, see their official documentation.
Utility Functions for Reflection
To work with Java methods dynamically, OpenJS provides helper functions:
getMethod(Package, MethodName, ExpectedParameters)
getMethod(Package, MethodName, ExpectedParameters)Finds a method by name and parameter types in the specified class.
Package: The Java class object.
MethodName: Name of the method to find.
ExpectedParameters: Array of fully qualified parameter class names (optional).
Returns the first matching method or null if none found.
getMethods(Package)
getMethods(Package)Logs all methods of a class with their parameter types to help find the correct method signatures.
Summary
When integrating unsupported plugins:
Import required Java classes manually using importClass(..).
Use Bukkit’s
getPluginManager().getPlugin()to get the plugin instance.Use
getMethodandgetMethodsto find and invoke plugin API methods.Handle API calls carefully since no built-in wrappers handle lifecycle or errors.
This approach enables powerful flexibility, allowing access to nearly any Java-based plugin API within OpenJS scripts.
Last updated
Was this helpful?