-
Notifications
You must be signed in to change notification settings - Fork 26
Developer API
This page is for developers who want to integrate with BedWars Cosmetics from another plugin.
The project targets Java 11 or above. Please note, this is due to the requirement of the supported BedWars plugins.
At minimum, your plugin should soft-depend or depend on BedWars Cosmetics. As to avoid issues with race conditions.
Use either one only!
softdepend:
- BedWars-Cosmeticsdepend:
- BedWars-CosmeticsThe BedWars-Cosmetics API is provided via JitPack. You can find the respective configuration for your pick of toolkit at JitPack.
The main API interface is:
xyz.iamthedefender.cosmetics.api.CosmeticsAPIYou can get it from Bukkit services:
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import xyz.iamthedefender.cosmetics.api.CosmeticsAPI;
RegisteredServiceProvider<CosmeticsAPI> rsp =
Bukkit.getServicesManager().getRegistration(CosmeticsAPI.class);
CosmeticsAPI api = rsp != null ? rsp.getProvider() : null;If api is null, the plugin is not loaded or not registered yet.
You should usually do that lookup in onEnable() after dependency checks, and cache the result.
Main things you can do:
- read the selected cosmetic for a player
- set the selected cosmetic for a player
- access category lists
- access the menu data
- access the plugin instance
- access the current handler
- access version support
- access the preview registry
- access the GUI manager
- access the active database implementation
- register new cosmetics
The plugin now supports these backend types:
SQLITEMYSQLMARIADBPOSTGRESQLMONGODB
The active backend can be inspected through:
api.getDatabase().getDatabaseType();
api.getDatabase().getDisplayName();Do not assume the backend is JDBC anymore. Make sure to check type if you are dealing with storage-related addon.
String selected = api.getSelectedCosmetic(player, CosmeticType.SPRAYS);Useful categories are in:
CosmeticTypeExamples:
CosmeticType.SPRAYSCosmeticType.KILL_MESSAGESCosmeticType.FINAL_KILL_EFFECTS
Important note: CosmeticType is no longer an enum class. It is now a normal Java class with static values.
api.setSelectedCosmetic(player, CosmeticType.KILL_MESSAGES, "frostbite");This saves asynchronously through the plugin's player data flow.
Do note, this method does not check if the set cosmetic is valid,
make sure to validate the ID before setting the value for a player.
As this may cause game-breaking issues. You may utilize the CosmeticRegistry#cosmeticExist.
Examples:
api.getSprayList();
api.getDeathCryList();
api.getFinalKillList();
api.getShopKeeperSkinList();These give you the registered cosmetic objects, not just strings.
Most cosmetic category classes expose a getField method.
Example:
Spray spray = api.getSprayList().get(0);
String name = (String) spray.getField(FieldsType.NAME, player);Useful field types:
FieldsType.NAMEFieldsType.LOREFieldsType.PRICEFieldsType.RARITYFieldsType.ITEM_STACKFieldsType.FILEFieldsType.URLFieldsType.ENTITY_TYPEFieldsType.SKIN_VALUEFieldsType.SKIN_SIGNFieldsType.MIRROR
boolean usingMySpray = api.getSelectedCosmetic(player, CosmeticType.SPRAYS).equals("my-logo");
);if (api.getSelectedCosmetic(player, CosmeticType.DEATH_CRIES) == null) {
api.setSelectedCosmetic(player, CosmeticType.DEATH_CRIES, "none");
}Available API events include:
CosmeticPurchaseEventBedBreakEffectExecuteEventFinalKillEffectsExecuteEventVictoryDancesExecuteEvent
@EventHandler
public void onPurchase(CosmeticPurchaseEvent event) {
if (event.getCategory() == CosmeticType.SPRAYS) {
event.getPlayer().sendMessage("You bought a spray.");
}
}@EventHandler
public void onPurchase(CosmeticPurchaseEvent event) {
if (event.getCategory() == CosmeticType.FINAL_KILL_EFFECTS) {
event.setCancelled(true);
}
}The API also exposes a small GUI framework:
SystemGuiSystemGuiManagerClickableItem
You can access the manager through:
SystemGuiManager manager = api.getSystemGuiManager();This is mainly useful if you are building custom UI behavior around the plugin.
Preview handlers are tracked in:
api.getPreviewList()Custom preview handlers extend:
CosmeticPreviewThat is only relevant if you are adding new coded cosmetics and want proper preview behaviour.
Current version-specific abstraction is exposed through:
api.getVersionSupport()Use that when you need skull generation or version aware rendering helpers instead of hardcoding server-specific methods. Need additional version specific methods? You may open a PR or suggest them to me on any platform.
You can access the main menu config manager with:
ConfigManager menuData = api.getMenuData();The API module also exposes ConfigUtils and ConfigType, but if you use them from an external plugin.