Repository navigation
Developer API
Other plugins can hook into Vanish++ through net.thecommandcraft.vanishpp.api.VanishAPI to check and change vanish state.
Vanish++ is available through Modrinth's Maven repository. Add it as a compile-only dependency so it doesn't get shaded into your plugin (the server provides it).
Gradle
repositories {
exclusiveContent {
forRepository { maven("https://api.modrinth.com/maven") { name = "Modrinth" } }
filter { includeGroup("maven.modrinth") }
}
}
dependencies {
compileOnly("maven.modrinth:vanish-plus-plus:1.2.1")
}Maven
<repository>
<id>modrinth</id>
<url>https://api.modrinth.com/maven</url>
</repository><dependency>
<groupId>maven.modrinth</groupId>
<artifactId>vanish-plus-plus</artifactId>
<version>1.2.1</version>
<scope>provided</scope>
</dependency>Use the Vanish++ version you build against. The version number gives the Paper jar, which contains the API. Each version page on Modrinth also shows an exact coordinate with the version ID (for example maven.modrinth:kbKpK1bc:vR0afCeO for 1.2.0), which works too.
Then add Vanish++ as a soft dependency in your plugin.yml so it loads before your plugin:
softdepend: [Vanishpp]Always check that Vanish++ is enabled before touching the API - VanishAPI.get() throws an IllegalStateException if it isn't loaded.
if (Bukkit.getPluginManager().isPluginEnabled("Vanishpp")) {
VanishAPI api = VanishAPI.get();
if (api.isVanished(player)) {
// player is vanished
}
if (!api.canSee(viewer, target)) {
// viewer can't see target (respects vanish levels / see permissions)
}
}| Method | Returns | Description |
|---|---|---|
isVanished(Player) / isVanished(UUID)
|
boolean |
Whether the player is currently vanished |
canSee(Player observer, Player subject) |
boolean |
Whether the observer can see the subject. true if the subject isn't vanished or the observer has a high enough see level. See Layered Permissions (Vanish Levels)
|
getVanishLevel(UUID) |
int |
The player's stored vanish level, 1 if none is stored |
getVanishReason(UUID) |
String |
Reason for the current vanish session, null if none was given |
getTimedVanishRemaining(UUID) |
long |
Milliseconds left on a timed vanish, -1 if not timed |
getRules(UUID) |
Map<String, Object> |
Snapshot of the player's Personal Rules (VRules) |
getStats(UUID) |
VanishStats |
Total vanish time, vanish count and longest session. Read from storage, so a currently running session may not be included yet |
These must be called on the main thread (on Folia: the player's region thread).
| Method | Description |
|---|---|
vanish(Player) |
Vanishes the player, same as them running /vanish
|
vanish(Player, String reason) |
Vanishes the player with a reason |
unvanish(Player) |
Unvanishes the player |
setVanishReason(UUID, String reason) |
Changes the reason of the current session. Does nothing if the player isn't vanished |
All in net.thecommandcraft.vanishpp.api.events.
| Event | Cancellable | When |
|---|---|---|
VanishEvent |
Yes | Before a player vanishes through a command, the API or another local request. getExecutor() is who triggered it. Cancelling it stops the vanish (since 1.2.0) |
UnvanishEvent |
Yes | Before a player unvanishes, same as above |
VanishStateChangeEvent |
No | After the state changed. isVanished() is the new state |
Restoring a stored state (for example when a vanished player rejoins, or the proxy hands over the state on a server switch) does not fire the cancellable events, only VanishStateChangeEvent.
@EventHandler
public void onVanish(VanishEvent event) {
if (inArena(event.getPlayer())) event.setCancelled(true); // no vanishing inside the arena
}If you only need to know whether someone is vanished, you don't need the API at all. Vanish++ sets the common vanished metadata that most vanish plugins use:
boolean vanished = player.getMetadata("vanished").stream().anyMatch(MetadataValue::asBoolean);This works with other vanish plugins too (SuperVanish, PremiumVanish, ...), so it's the easiest option if your plugin should support more than one.
-
getVanishLevel,getRulesandgetStatsread from the configured Storage. On MySQL/PostgreSQL that's a database query, so don't call them every tick. - For placeholders in other plugins, use PlaceholderAPI instead.
- For proxy plugins (Velocity/BungeeCord), see Proxy Plugin Compatibility.