Interface CosmeticHandler
CosmeticsService.registerType(org.bukkit.plugin.Plugin, dev.itsharshxd.zentrix.api.cosmetics.CosmeticTypeDefinition, dev.itsharshxd.zentrix.api.cosmetics.CosmeticHandler): the cosmetics there are, and what they do.
Zentrix does the rest as it does for its own categories: it stores who owns and chose what,
lists the type in /cosmetics, checks permissions, sells cosmetics that have a price, and
calls this handler when one of them should show.
Every method is called on the main thread. One that throws is logged and skipped, so a failing handler cannot break a match or a menu.
public final class HatHandler implements CosmeticHandler {
public List<CosmeticDefinition> getCosmetics() {
return hats.values().stream().map(Hat::definition).toList();
}
public void onTrigger(CosmeticTrigger trigger) {
switch (trigger.moment()) {
case GAME_START -> wear(trigger.player(), trigger.cosmetic().getId());
case GAME_LEAVE -> takeOff(trigger.player());
default -> { }
}
}
public boolean startPreview(Player player, CosmeticDefinition cosmetic, Runnable onFinish) {
wear(player, cosmetic.getId());
Bukkit.getScheduler().runTaskLater(plugin, () -> {
takeOff(player);
onFinish.run();
}, 100L);
return true;
}
}
- Since:
- 1.11.0
-
Method Summary
Modifier and TypeMethodDescription@NotNull List<CosmeticDefinition> Every cosmetic of the type, in the order menus list them.default voidonEquippedChange(@NotNull org.bukkit.entity.Player player, @Nullable CosmeticDefinition equipped) What an online player has equipped of this type changed: they chose another, it was taken away or expired, or their cosmetics were read as they joined.default voidonTrigger(@NotNull CosmeticTrigger trigger) A player's equipped cosmetic of this type, triggered at one of the moments the type's definition lists.default voidThe type was unregistered, by its owner or because the owning plugin is disabling.default booleanstartPreview(@NotNull org.bukkit.entity.Player player, @NotNull CosmeticDefinition cosmetic, @NotNull CosmeticPreview preview, @NotNull Runnable onFinish) Shows a cosmetic to a player for a while, as the cosmetics menu's right-click does, where and how the server chose.default booleanstartPreview(@NotNull org.bukkit.entity.Player player, @NotNull CosmeticDefinition cosmetic, @NotNull Runnable onFinish) Shows a cosmetic to a player for a while, on the player, as the cosmetics menu's right-click does in place.default voidstopPreview(@NotNull org.bukkit.entity.Player player) Ends a player's preview early: they started another, left, or an addon asked.
-
Method Details
-
getCosmetics
Every cosmetic of the type, in the order menus list them. Asked whenever Zentrix needs them, so a reload of the addon's own configuration shows at once; keep it quick.A cosmetic removed from the list stays owned by those who own it, and counts again once it is listed again. IDs must be unique; a repeated one is ignored.
-
onTrigger
A player's equipped cosmetic of this type, triggered at one of the moments the type's definition lists. ACosmeticTriggerEventlistener may have skipped it. -
onEquippedChange
default void onEquippedChange(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable CosmeticDefinition equipped) What an online player has equipped of this type changed: they chose another, it was taken away or expired, or their cosmetics were read as they joined. For a cosmetic that shows outside matches, such as in the lobby. Not called as players leave the server.- Parameters:
equipped- the cosmetic now in effect, or null when there is none
-
startPreview
default boolean startPreview(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull CosmeticDefinition cosmetic, @NotNull @NotNull CosmeticPreview preview, @NotNull @NotNull Runnable onFinish) Shows a cosmetic to a player for a while, as the cosmetics menu's right-click does, where and how the server chose.In the showcase, the player is taken to a viewing spot and watches a still model of themselves: show the cosmetic at
CosmeticPreview.location(), not on the player. This default callsstartPreview(Player, CosmeticDefinition, Runnable), which shows on the player, so a handler that can only do that still works there.Zentrix closes the menu first and opens it again once
onFinishruns.- Parameters:
preview- where the preview shows, and whether it is in the showcaseonFinish- to run once the preview has finished on its own; not afterstopPreview(org.bukkit.entity.Player)- Returns:
- whether it shows; false, the default, when this type has no previews
- Since:
- 1.13.0
-
startPreview
default boolean startPreview(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull CosmeticDefinition cosmetic, @NotNull @NotNull Runnable onFinish) Shows a cosmetic to a player for a while, on the player, as the cosmetics menu's right-click does in place.Called by the default
startPreview(Player, CosmeticDefinition, CosmeticPreview, Runnable)for a handler that does not override the location-aware form. Zentrix closes the menu first and opens it again onceonFinishruns.- Parameters:
onFinish- to run once the preview has finished on its own; not afterstopPreview(org.bukkit.entity.Player)- Returns:
- whether it shows; false, the default, when this type has no previews
-
stopPreview
default void stopPreview(@NotNull @NotNull org.bukkit.entity.Player player) Ends a player's preview early: they started another, left, or an addon asked. Called only while a preview this handler started has not finished. -
onUnregister
default void onUnregister()The type was unregistered, by its owner or because the owning plugin is disabling. Previews still showing have been stopped; anything else the type keeps up, such as worn items, should be undone here.
-