> ## Documentation Index
> Fetch the complete documentation index at: https://new-docs.simplecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Start with Velocity

> Implementing the SimpleCloud Controller API in Velocity

## 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](/en/manual/setup/groups), [servers](/en/manual/setup/servers), and more, while the `PlayerApi` is used to interact with [players](/en/manual/droplet/player).

## Dependencies

First, we need to add the dependencies to your `build.gradle` or `pom.xml`:

<Tabs>
  <Tab title="Gradle (Kotlin)">
    ```kotlin theme={null}
    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")
    }
    ```
  </Tab>

  <Tab title="Gradle (Groovy)">
    ```groovy theme={null}
    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'
    }
    ```
  </Tab>

  <Tab title="Maven">
    ```xml theme={null}
    <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>
    ```
  </Tab>
</Tabs>

<Warning>
  Please don't compile our API into your plugin, just follow the next step, and
  depend on the API.
</Warning>

## 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:

```json theme={null}
{
  "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:

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    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")
            }
        }

    }
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    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);
            });
        }

    }
    ```
  </Tab>
</Tabs>
