Getting Started
The following guide will show you how to implement our API in your Velocity plugin.
Our API includes the ControllerApi and the PlayerApi class. The ControllerApi is used to interact with SimpleCloud’s groups, servers, and more, while the PlayerApi is used to interact with players.
Dependencies
First, we need to add the dependencies to your build.gradle or pom.xml:
Gradle (Kotlin)
Gradle (Groovy)
Maven
repositories {
maven("https://repo.simplecloud.app/snapshots")
maven("https://buf.build/gen/maven")
}
dependencies {
compileOnly("app.simplecloud.api.platform:velocity:LATEST")
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
}
repositories {
maven { url 'https://repo.simplecloud.app/snapshots' }
maven { url 'https://buf.build/gen/maven' }
}
dependencies {
compileOnly 'app.simplecloud.api.platform:velocity:LATEST'
compileOnly 'com.velocitypowered:velocity-api:3.4.0-SNAPSHOT'
}
<repositories>
<repository>
<id>simplecloud-snapshots</id>
<url>https://repo.simplecloud.app/snapshots</url>
</repository>
<repository>
<id>buf-maven</id>
<url>https://buf.build/gen/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>app.simplecloud.api.platform</groupId>
<artifactId>velocity</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.4.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Please don’t compile our API into your plugin, just follow the next step, and
depend on the API.
Depend on the API
Velocity plugins can inherit from the SimpleCloud Cloud API plugin. This is useful if you want to use the SimpleCloud API in your plugin.
For this, you need to add a dependency configuration to your velocity-plugin.json file. Here is an example:
{
"id": "simplecloud-example-velocity",
"name": "SimpleCloud Example",
"version": "1.0.0",
"main": "app.simplecloud.examples.plugin.velocity.VelocityExamplePlugin",
"dependencies": [
{
"id": "simplecloud-api",
"optional": false
}
]
}
After that, you can use the SimpleCloud API in your plugin:
import app.simplecloud.controller.api.ControllerApi
import com.google.inject.Inject
import com.velocitypowered.api.event.Subscribe
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent
import com.velocitypowered.api.plugin.Dependency
import com.velocitypowered.api.plugin.Plugin
import com.velocitypowered.api.proxy.ProxyServer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.slf4j.Logger
@Plugin(
id = "simplecloud-example-velocity",
name = "SimpleCloud Example",
version = "1.0.0",
dependencies = [Dependency(id = "simplecloud-api")]
)
class VelocityExamplePlugin @Inject constructor(
private val server: ProxyServer,
private val logger: Logger
) {
private val controllerApi = ControllerApi.createCoroutineApi()
@Subscribe
fun onProxyInitialization(event: ProxyInitializeEvent) {
logger.info("Hello from Velocity!")
CoroutineScope(Dispatchers.IO).launch {
val groups = controllerApi.getGroups().getAllGroups()
logger.info("Groups: $groups")
}
}
}
import app.simplecloud.controller.api.ControllerApi;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.ProxyServer;
import org.slf4j.Logger;
@Plugin(
id = "simplecloud-example-velocity",
name = "SimpleCloud Example",
version = "1.0.0",
dependencies = {@Dependency(id = "simplecloud-api")}
)
public class VelocityExamplePlugin {
private final ProxyServer server;
private final Logger logger;
private final ControllerApi.Future controllerApi = ControllerApi.createFutureApi();
@Inject
public VelocityExamplePlugin(ProxyServer server, Logger logger) {
this.server = server;
this.logger = logger;
}
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
logger.info("Hello from Velocity!");
controllerApi.getGroups().getAllGroups().thenAccept(groups -> {
logger.info("Groups: " + groups);
});
}
}