> For the complete documentation index, see [llms.txt](https://quantioms.gitbook.io/advancedvanish/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantioms.gitbook.io/advancedvanish/api.md).

# API

Before utilizing the API, make sure that the `AdvancedVanish` plugin is enabled by adding`depend: [AdvancedVanish]` or `softdepend: [AdvancedVanish]` to your plugin's `plugin.yml`.

Even though AdvancedVanish was made in Kotlin, the API can still be accessed from Java.

### Adding the Dependency

{% tabs %}
{% tab title="Maven" %}
Add this repository to your `pom.xml`:

```xml
<repository>
  <id>repsy</id>
  <name>quantiom</name>
  <url>https://repo.repsy.io/mvn/quantiom/minecraft</url>
</repository>
```

Add the dependency and replace `<version>...</version>` with the current version:

```xml
<dependency>
  <groupId>me.quantiom</groupId>
  <artifactId>advancedvanish</artifactId>
  <version>1.2.2</version>
</dependency>
```

{% endtab %}

{% tab title="Gradle" %}
Add this repository to your `build.gradle`:

```groovy
allprojects {
	repositories {
		...
		maven { url 'https://repo.repsy.io/mvn/quantiom/minecraft' }
	}
}
```

Add the dependency and replace the version with the current version:

```groovy
dependencies {
    implementation 'me.quantiom:advancedvanish:1.2.2'
}
```

{% endtab %}
{% endtabs %}

### Methods

```kotlin
AdvancedVanishAPI.vanishPlayer(player: Player): Unit
AdvancedVanishAPI.unVanishPlayer(player: Player): Unit
AdvancedVanishAPI.isPlayerVanished(player: Player): Boolean
AdvancedVanishAPI.canSee(player: Player, target: Player): Boolean
```

### Extensions (Kotlin Only)

```kotlin
Player.isVanished(): Boolean
```

### Events

* `PrePlayerVanishEvent` - Gets called before vanishing a player, implements `Cancellable`
* `PlayerVanishEvent` - Gets called after a player vanishes.
* `PrePlayerUnVanishEvent` - Gets called before a player unvanishes, implements `Cancellable`.
* `PlayerUnVanishEvent` - Gets called after a player unvanishes.

### Example Usage

```kotlin
class ExamplePlugin : JavaPlugin(), Listener {
    override fun onEnable() {
        this.server.pluginManager.registerEvents(this, this)
    }

    @EventHandler
    private fun onVanish(event: PlayerVanishEvent) {
        val vanishedPlayers = AdvancedVanishAPI.vanishedPlayers
            .map(Bukkit::getPlayer)
            .joinToString(", ", transform = Player::getName)

        this.logger.log(Level.INFO, "${event.player.name} has entered vanish.")
        this.logger.log(Level.INFO, "Current vanished players: ${vanishedPlayers}.")
    }

    @EventHandler
    private fun onUnVanish(event: PrePlayerUnVanishEvent) {
        event.isCancelled = true // Don't let players unvanish
    }
}
```
