# API

{% hint style="warning" %}
The API is subject to change in future versions as we improve ServerAssistantAI and may result in breakages. You can join our [discord](https://code-solutions.dev/discord) server to make sure you're notified when a breaking change is done/will be done to ServerAssistantAI, so you can update your addons accordingly.
{% endhint %}

## JavaDoc

[![Javadoc Latest](https://img.shields.io/badge/JavaDoc-Released_API-4ac51c)](https://repo.bluetree242.dev/javadoc/releases/dev/bluetree242/serverassistantai/api/1.4/raw/index.html)

[![Javadoc Dev](https://img.shields.io/badge/JavaDoc-Development_API-FF7F7F)](https://repo.bluetree242.dev/javadoc/snapshots/dev/bluetree242/serverassistantai/api/1.4.1-SNAPSHOT/raw/index.html)

{% hint style="info" %}
Please check the links to ensure you are working with the desired version. The badges below display the latest versions.
{% endhint %}

## API Version

[![Latest Release](https://repo.bluetree242.dev/api/badge/latest/releases/dev/bluetree242/serverassistantai/api?name=Latest%20Release)](https://repo.bluetree242.dev/api/maven/versions/releases/dev/bluetree242/serverassistantai/api)

[![Latest Snapshot](https://repo.bluetree242.dev/api/badge/latest/snapshots/dev/bluetree242/serverassistantai/api?name=Latest%20Snapshot\&color=FF7F7F)](https://repo.bluetree242.dev/api/maven/versions/snapshots/dev/bluetree242/serverassistantai/api)

## Integrating with our API:

To integrate with the ServerAssistantAI API, simply add the necessary repository and dependency to your build configuration. For Maven users, update your `pom.xml` file, and for Gradle users, modify your `build.gradle`/`build.gradle.kts` file.

Replace `VERSION` with the API version you would like. The badges above display the latest versions available.

Additionally, ServerAssistantAI should load before your plugin by specifying this in the `plugin.yml`:\
`softdepend: [ServerAssistantAI]`

{% tabs %}
{% tab title="Maven" %}

```xml
<repository>
    <id>bluetree242-repo</id>
    <url>https://repo.bluetree242.dev/public</url>
</repository>
```

```xml
<dependency>
    <groupId>dev.bluetree242.serverassistantai</groupId>
    <artifactId>api</artifactId>
    <version>VERSION</version>
    <scope>provided</scope>
</dependency>
```

{% endtab %}

{% tab title="Gradle (Groovy DSL)" %}

```groovy
repositories {
    maven { url 'https://repo.bluetree242.dev/public' }
    // Other repositories..
}
```

```groovy
dependencies {
    compileOnly 'dev.bluetree242.serverassistantai:api:VERSION'
    // Other dependencies..
}
```

{% endtab %}

{% tab title="Gradle (Kotlin DSL)" %}

```kotlin
repositories {
    maven("https://repo.bluetree242.dev/public")
    // Other repositories..
}
```

```kotlin
dependencies {
    compileOnly("dev.bluetree242.serverassistantai:api:VERSION")
    // Other dependencies..
}
```

{% endtab %}

{% tab title="Gradle (libs.versions.toml)" %}
{% hint style="info" %}
You must also copy the repository from the repositories section from either of the other gradle sections according to what you use. You must add `libs.serverassistantai` in your dependencies section. (compileOnly)
{% endhint %}

```toml
[versions]
serverassistantai = "VERSION"
# Other versions..

[libraries]
serverassistantai = { group = "dev.bluetree242.serverassistantai", name = "api", version.ref = "serverassistantai" }
# Other dependencies..
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
ServerAssistantAI's API is public and accessible to all developers, even if they haven't purchased the plugin. As long as you obtain the plugin's JAR file legally, such as receiving it from someone for testing purposes, you can receive support for our API. However, using pirated or illegally obtained versions of ServerAssistantAI will not be eligible for support.
{% endhint %}

## Events: <a href="#events" id="events"></a>

ServerAssistantAI API includes four events that can be used to interact with the AI assistant's functionality and customize its behavior.

### MinecraftChatHandleEvent:

The [MinecraftChatHandleEvent](https://repo.bluetree242.dev/javadoc/releases/dev/bluetree242/serverassistantai/api/1.4/raw/dev/bluetree242/serverassistantai/api/events/MinecraftChatHandleEvent.html) is fired right before the plugin starts handling a chat message.

This event allows you to cancel the message handling process and provides access to whether the event was triggered by ServerAssistantAI's built-in listeners or another plugin. You can access the player, message, and receivers set. Note that this event is not fired when a player is in a `/ai chat` session.

### PreDiscordHandleEvent:

The [PreDiscordHandleEvent](https://repo.bluetree242.dev/javadoc/releases/dev/bluetree242/serverassistantai/api/1.4/raw/dev/bluetree242/serverassistantai/api/events/PreDiscordHandleEvent.html) is fired **before** the bot handles a question on Discord.

This allows you to cancel the event, preventing the bot from responding to the message or sending typing indicators. You can also access the user, message, event, and history associated with the question.

### PostDiscordHandleEvent:

The [PostDiscordHandleEvent](https://repo.bluetree242.dev/javadoc/releases/dev/bluetree242/serverassistantai/api/1.4/raw/dev/bluetree242/serverassistantai/api/events/PostDiscordHandleEvent.html) is fired **after** the bot has finished handling a question on Discord.

This event provides access to the user, message, event, history, reply message, response, response text, and information used to generate the response. It allows you to perform custom actions or logging based on the bot's response.

### PreMinecraftHandleEvent:

The [PreMinecraftHandleEvent](https://repo.bluetree242.dev/javadoc/releases/dev/bluetree242/serverassistantai/api/1.4/raw/dev/bluetree242/serverassistantai/api/events/PreMinecraftHandleEvent.html) is fired **before** the bot handles an in-game question, either through chat or the `/serverassistantai ask` command.

This event allows you to cancel the question-handling process, preventing the bot from responding to the player's message. You can access the player, message, and whether the question was forced.

### PostMinecraftHandleEvent:

The [PostMinecraftHandleEvent](https://repo.bluetree242.dev/javadoc/releases/dev/bluetree242/serverassistantai/api/1.4/raw/dev/bluetree242/serverassistantai/api/events/PostMinecraftHandleEvent.html) is fired **after** the bot has finished handling an in-game question.

This event provides access to the player, message, whether the question was forced, response, response text, whether the response was private, and information used to generate the response. It allows you to perform custom actions or logging based on the bot's interaction with the player.
