-
Notifications
You must be signed in to change notification settings - Fork 2
API
ProCosmetics provides a developer API that allows other plugins to integrate with and extend its features.
The API artefact is published to the FilleDev repository.
Repository
<repositories>
<repository>
<id>filledev-releases</id>
<url>https://repo.filledev.se/releases</url>
</repository>
</repositories>
Dependency
<dependencies>
<dependency>
<groupId>se.filledev</groupId>
<artifactId>procosmetics-api</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Repository
repositories {
maven {
url = uri("https://repo.filledev.se/releases")
}
}
Dependency
dependencies {
compileOnly("se.filledev:procosmetics-api:2.0.0")
}
repositories {
maven {
url 'https://repo.filledev.se/releases'
}
}
Dependency
dependencies {
compileOnly 'se.filledev:procosmetics-api:2.0.0'
}
When the plugin is enabled, an instance of ProCosmetics can be obtained statically from the ProCosmeticsProvider class.
Note: this method will throw an IllegalStateException if the API is accessed before the plugin has been fully enabled.
ProCosmetics api = ProCosmeticsProvider.get();To create a custom cosmetic, start by creating a new class representing your cosmetic and implement the appropriate CosmeticBehavior. For example, if you want to create an arrow effect, implement the ArrowEffectBehavior. After implementing the interface, define your custom behaviour by overriding the available methods. Below is an example of an arrow effect:
public class LoveArrows implements ArrowEffectBehavior {
private static final int HIT_AMOUNT = 4;
private static final double HIT_SPREAD = 0.5d;
@Override
public void onEquip(CosmeticContext<ArrowEffectType> context) {
}
@Override
public void onUpdate(CosmeticContext<ArrowEffectType> context, Location location) {
location.getWorld().spawnParticle(Particle.HEART, location, 1);
}
@Override
public void onArrowHit(CosmeticContext<ArrowEffectType> context, Location location) {
location.getWorld().spawnParticle(Particle.HEART,
location,
HIT_AMOUNT,
HIT_SPREAD,
HIT_SPREAD,
HIT_SPREAD
);
}
@Override
public void onUnequip(CosmeticContext<ArrowEffectType> context) {
}
}Cosmetics are registered through their corresponding CosmeticRegistry based on the CosmeticCategory. First, access the built-in registries:
ProCosmetics api = ProCosmeticsProvider.get();
CosmeticRegistry<ArrowEffectType, ArrowEffectBehavior, ArrowEffectType.Builder> arrowEffectRegistry = api.getCategoryRegistries().arrowEffects().getCosmeticRegistry();Each cosmetic is defined using a builder. You should provide a unique key in lowercase format. If the name contains spaces, replace them with underscores (_).
ArrowEffectType.Builder builder = arrowEffectRegistry.builder("love_arrows");You can define cosmetic data in two ways:
- Open the relevant configuration file for the cosmetic category in
/plugins/ProCosmetics/. - Copy and paste an existing cosmetic entry.
- Rename the key to your new desired cosmetic key (the configuration key must exactly match the builder key (case-sensitive)).
- Use readFromConfig() to automatically load the values.
Alternatively, you can configure all values manually using the builder (e.g. cost, rarity, permissions, etc.).
You must provide a factory before calling build(). In this example, the factory creates a new instance of LoveArrows using LoveArrows::new. After that, you can register it with:
arrowEffectRegistry.register(arrowEffectRegistry.builder("love_arrows").readFromConfig().factory(LoveArrows::new).build());The custom cosmetic should now be registered properly and visible in the ProCosmetics cosmetics menu.
WIP