Unsupported plugin integration

OpenJS allows integration with plugins that do not have pre-built API wrappers. This requires manually importing and interacting with the plugin’s Java API classes and methods within your script.

Example: Integrating CoreProtect

CoreProtect does not have a built-in OpenJS API layer, but you can still access its API using Java reflection and Bukkit plugin management:

//!import net.coreprotect.CoreProtect
//!import net.coreprotect.CoreProtectAPI
//!import org.bukkit.Bukkit

var Bukkit = org.bukkit.Bukkit;
var CoreProtectPlugin = Bukkit.getPluginManager().getPlugin("CoreProtect");
var CoreProtectAPI = getMethod(CoreProtect, "getAPI").invoke(CoreProtectPlugin);

CoreProtectAPI.testAPI();  // Example call to CoreProtect API

For 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)

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)

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 //!import.

  • Use Bukkit’s getPluginManager().getPlugin() to get the plugin instance.

  • Use getMethod and getMethods to 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?