Skip to main content

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:
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")
}
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")
        }
    }

}