> For the complete documentation index, see [llms.txt](https://openjs.wiki.gd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openjs.wiki.gd/rescources/advanced-guides/how-to-use-external-plugins-in-scripts.md).

# How to use external plugins in scripts

By default you should see if the plugin you want to use is a [Service](/apis-and-tools/services.md). 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](/apis-and-tools/services.md) wrapper, but you can still access its API using Java reflection and Bukkit plugin management:

```js
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 API
```

For more info on CoreProtect's API, see their [official documentation](https://docs.coreprotect.net/api/version/v10/).

***

### 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 [importClass(..)](/apis-and-tools/globals/importclass.md).
* 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://openjs.wiki.gd/rescources/advanced-guides/how-to-use-external-plugins-in-scripts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
