Developer API
For plugin developers: react to cosmetics going on and off, and put them on from your own plugin.
Add the API
The API is a small jar of interfaces and events. Compile against it; BoxCosmetics provides it at run time.
Gradle (Kotlin)
repositories {
maven("https://boxpixstudios.com/maven/")
}
dependencies {
compileOnly("com.lunggolfs:boxcosmetics-api:1.0.0")
}
Maven
<repository>
<id>boxpix</id>
<url>https://boxpixstudios.com/maven/</url>
</repository>
<dependency>
<groupId>com.lunggolfs</groupId>
<artifactId>boxcosmetics-api</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
In your plugin.yml, add depend: [BoxCosmetics] (or softdepend).
Events
| Event | When | Cancel |
|---|---|---|
CosmeticEquipEvent |
A cosmetic is about to go on: menu, Collection, command, dispenser, Wear-full swap, dressing room, API | Yes. Not for a piece put back after a swap that could not finish (isPutBack()) |
CosmeticUnequipEvent |
A cosmetic came off | No |
CosmeticColorChangeEvent |
A worn cosmetic is about to be dyed, or get its own colour back | Yes |
Each gives getPlayer(), getSlot(), getCosmetic() (the key, or null for an item that is no cosmetic) and getItem(). A quit, death or world change fires nothing: what is worn stays kept.
@EventHandler
public void onEquip(CosmeticEquipEvent event) {
if ("crown".equals(event.getCosmetic()) && !event.getPlayer().hasPermission("vip")) {
event.setCancelled(true);
event.getPlayer().sendMessage("Only VIPs wear the crown.");
}
}
Events are in com.lunggolfs.boxcosmetics.api.event.
The service
BoxCosmeticsApi api = BoxCosmeticsApi.get();
if (api.owns(player, "crown") && !api.isWearing(player, "crown")) {
EquipResult result = api.equip(player, "crown");
}
api.addToCollection(player, "red-balloon", 1);
| Method | Does |
|---|---|
getCosmeticKeys() |
Every loaded cosmetic's key |
getWornCosmetics(player) |
What the player has on: key, slot, item |
isWearing(player, key) |
Whether a piece of it is on |
owns(player, key) |
Worn, in the Collection, or given by its permission |
getCollectionCount(player, key) |
How many are in the Collection |
equip(player, key) |
Puts one on from the Collection, as /bc collection equip |
unequip(player, key) |
Takes it off into the Collection, as /bc collection unequip |
addToCollection(player, key, amount) |
Adds to the Collection, as /bc collection add; waits for an offline player's join |
Keys are matched without regard to case. Call it from the main thread.