To use the CommandBridge API in your plugin, add the commandbridge-api dependency to your build and declare CommandBridge as a plugin dependency so it loads first.
Add the dependency to your build script.
<dependency>
<groupId>dev.objz</groupId>
<artifactId>commandbridge-api</artifactId>
<version>3.3.4</version>
<scope>provided</scope>
</dependency>
compileOnly 'dev.objz:commandbridge-api:3.3.4'
compileOnly("dev.objz:commandbridge-api:3.3.4")
Shading the API into your jar is not supported. CommandBridge bundles the API in its own jar and provides it at runtime, so use provided or compileOnly.
Declare CommandBridge as a required dependency in your plugin descriptor so it loads before your plugin.
@Plugin(
id = "myplugin",
dependencies = { @Dependency(id = "commandbridge") }
)
public class MyPlugin { }
dependencies:
server:
CommandBridge:
load: BEFORE
required: true
join-classpath: true
join-classpath: true is required. Paper uses isolated classloaders, so your plugin can't see CommandBridge's API classes without it.
depend:
- CommandBridge
Call CommandBridgeProvider.get() to get the API instance. Store it as a field and call it from the right lifecycle method.
import dev.objz.commandbridge.api.CommandBridgeAPI;
import dev.objz.commandbridge.api.CommandBridgeProvider;
private CommandBridgeAPI api;
@Subscribe
public void onProxyInitialize(ProxyInitializeEvent event) {
api = CommandBridgeProvider.get();
}
import dev.objz.commandbridge.api.CommandBridgeAPI;
import dev.objz.commandbridge.api.CommandBridgeProvider;
private CommandBridgeAPI api;
@Override
public void onEnable() {
api = CommandBridgeProvider.get();
}
CommandBridgeProvider.get() throws IllegalStateException if CommandBridge is not installed or has not finished enabling.
If you need to cast to a platform-specific subtype, use the typed overload. It throws IllegalStateException if the registered implementation is not an instance of the requested type:
CommandBridgeProvider.get(MyPlatformExtension.class)