Interface PerkService
perks.yml: named tiers tied to permissions, and temporary
boosts given to single players.
A player holds every enabled tier whose permission they have, and is shown as belonging to
the highest-priority one. The resolution mode decides where
each perk comes from: that tier, or the best value among all the tiers they hold. A tier's value
comes from the tier itself, then up its parent chain. Every perk no tier gives, and every perk of
a player without a tier, follows the server-wide default: settings.yml for host limits,
party size and scenario settings, the defaults of perks.yml for the rest, and an
addon's own default for its perks. Active personal and server-wide boosts apply on top.
Addons can register perks of their own, which resolve exactly as
the built-in ones do. A number value of PerkDefinition.UNLIMITED in perks.yml
means unlimited for perks that support it; getNumber(org.bukkit.entity.Player, dev.itsharshxd.zentrix.api.perk.Perk) answers Integer.MAX_VALUE
for it, so limits compare as usual.
Zentrix asks for a perk when the player acts - creating a game, inviting someone - so a rank
that expires takes nothing away the player already has. When a perk stops a player,
PerkLimitReachedEvent fires.
Reads answer at once, on the main thread, from what Zentrix holds for online players. Boost changes are stored with the player's data, work for offline players and complete on the main thread; they complete exceptionally while storage is unavailable.
PerkService perks = ZentrixAPI.get().getPerkService();
int slots = perks.getNumber(player, Perk.CUSTOM_GAMES_MAX_HOSTED);
perks.grantBoost(player.getUniqueId(), Perk.CUSTOM_GAMES_MAX_HOSTED, 1, Duration.ofHours(24), "shop");
- Since:
- 1.9.0
-
Method Summary
Modifier and TypeMethodDescription@NotNull CompletableFuture<Integer> clearBoosts(@NotNull UUID playerId, @Nullable Perk perk) Ends a player's boosts early: every boost, or every boost of one perk.@NotNull CompletableFuture<Boolean> endServerBoost(@NotNull String boostId) Ends one server-wide boost early.getAllBoosts(@NotNull UUID playerId) A player's active boosts of every perk, addon perks included, as last read.A player's active boosts, as last read.intgetDefaultNumber(@NotNull Perk perk) The server-wide default of aPerk.Type.NUMBERperk, for players without a tier.getNextTier(@NotNull org.bukkit.entity.Player player, @NotNull Perk perk) The tier a player would have to reach for more of a perk: the lowest-priority enabled tier above their own whose value is higher, or that allows a toggle they are refused.getNextTier(@NotNull org.bukkit.entity.Player player, @NotNull String perkKey) The tier a player would have to reach for more of a perk, built-in or addon, asgetNextTier(Player, Perk)answers it.intAPerk.Type.NUMBERperk as it applies to a player now: their tier's value or the server-wide default, plus their active boosts.intA number perk, built-in or addon, as it applies to a player now.@NotNull Optional<PerkDefinition> A built-in or registered addon perk by its exact key.@NotNull List<PerkDefinition> getPerks()Every perk, built-in perks first in their order, then registered addon perks.@NotNull PerkResolutionModeHow a player holding several tiers gets each perk, fromperks.yml.@NotNull List<ServerBoost> The server-wide boosts in force, as last read.An enabled tier by itsperks.ymlkey, ignoring case.getTier(@NotNull org.bukkit.entity.Player player) The tier a player belongs to now, or empty when they hold no tier's permission.getTiers()The enabled tiers, highest priority first.@NotNull CompletableFuture<PerkBoost> grantBoost(@NotNull UUID playerId, @NotNull Perk perk, int amount, @NotNull Duration duration, @NotNull String source) Gives a player a temporary boost, online or offline.@NotNull CompletableFuture<PerkBoost> grantBoost(@NotNull UUID playerId, @NotNull String perkKey, int amount, @NotNull Duration duration, @NotNull String source) Gives a player a temporary boost of any perk, built-in or addon, by its key.booleanWhether aPerk.Type.TOGGLEperk is allowed for a player now: by their tier, the server-wide default, or an active boost.booleanWhether a toggle perk, built-in or addon, is allowed for a player now.booleanisAllowedByDefault(@NotNull Perk perk) The server-wide default of aPerk.Type.TOGGLEperk, for players without a tier.@NotNull CompletableFuture<List<PerkBoost>> refreshBoosts(@NotNull UUID playerId) Reads a player's boosts as stored now, online or offline, which another server may have changed.voidregisterPerk(org.bukkit.plugin.Plugin owner, @NotNull PerkDefinition definition) Registers an addon perk.@NotNull CompletableFuture<Boolean> removeBoost(@NotNull UUID playerId, @NotNull String boostId) Ends one of a player's boosts early.@NotNull CompletableFuture<ServerBoost> startServerBoost(@NotNull String perkKey, int amount, @NotNull Duration duration, @NotNull String source) Starts a server-wide boost, announced to players and ending on its own afterduration.booleanunregisterPerk(@NotNull String key) Unregisters an addon perk.
-
Method Details
-
getTiers
The enabled tiers, highest priority first. Empty whenperks.ymlenables none. -
getTier
An enabled tier by itsperks.ymlkey, ignoring case. -
getTier
The tier a player belongs to now, or empty when they hold no tier's permission. -
getNumber
APerk.Type.NUMBERperk as it applies to a player now: their tier's value or the server-wide default, plus their active boosts.- Throws:
IllegalArgumentException- for a toggle perk
-
isAllowed
Whether aPerk.Type.TOGGLEperk is allowed for a player now: by their tier, the server-wide default, or an active boost.- Throws:
IllegalArgumentException- for a number perk
-
getDefaultNumber
The server-wide default of aPerk.Type.NUMBERperk, for players without a tier. -
isAllowedByDefault
The server-wide default of aPerk.Type.TOGGLEperk, for players without a tier. -
getNextTier
@NotNull @NotNull Optional<PerkTier> getNextTier(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull Perk perk) The tier a player would have to reach for more of a perk: the lowest-priority enabled tier above their own whose value is higher, or that allows a toggle they are refused. UnderPerkResolutionMode.BEST_VALUE, the lowest-priority enabled tier they do not hold that would beat what they get now. What the limit message names, so a shop can offer it.- Returns:
- empty when no tier above theirs would give them more
-
getBoosts
A player's active boosts, as last read. Empty for offline players; seerefreshBoosts(java.util.UUID). -
refreshBoosts
Reads a player's boosts as stored now, online or offline, which another server may have changed. -
grantBoost
@NotNull @NotNull CompletableFuture<PerkBoost> grantBoost(@NotNull @NotNull UUID playerId, @NotNull @NotNull Perk perk, int amount, @NotNull @NotNull Duration duration, @NotNull @NotNull String source) Gives a player a temporary boost, online or offline. It ends on its own afterduration.- Parameters:
amount- added to a number perk; must be positive. Ignored by a toggle perk, which the boost allowsduration- how long it lasts; must be positivesource- who or what gave it, kept with the boost- Returns:
- completes on the main thread with the boost as stored
- Throws:
IllegalArgumentException- when the amount or duration is not positive
-
removeBoost
@NotNull @NotNull CompletableFuture<Boolean> removeBoost(@NotNull @NotNull UUID playerId, @NotNull @NotNull String boostId) Ends one of a player's boosts early.- Returns:
- completes with whether the boost existed
-
clearBoosts
@NotNull @NotNull CompletableFuture<Integer> clearBoosts(@NotNull @NotNull UUID playerId, @Nullable @Nullable Perk perk) Ends a player's boosts early: every boost, or every boost of one perk.- Parameters:
perk- the perk whose boosts end, or null for all of them- Returns:
- completes with how many boosts ended
-
registerPerk
void registerPerk(@NotNull org.bukkit.plugin.Plugin owner, @NotNull @NotNull PerkDefinition definition) Registers an addon perk. From then on tiers inperks.ymlcan set it under its key, boosts can raise it, and/perks, the tier editor and placeholders (%zentrix_perk_<key>%, dots and dashes as underscores) show it, exactly as they do built-in perks.Values and boosts of a perk that is not registered are kept as they are, so an addon that loads late, or is removed for a while, finds them again. The perk is unregistered when its owner disables. Main thread, such as from the addon's
onEnable.- Parameters:
owner- the addon registering itdefinition- the perk; build one withPerkDefinition.number(java.lang.String)orPerkDefinition.toggle(java.lang.String)- Throws:
IllegalArgumentException- when the key is a built-in perk's, or another addon'sIllegalStateException- off the main thread- Since:
- 1.16.0
-
unregisterPerk
Unregisters an addon perk. Its values inperks.ymland its stored boosts are kept.- Returns:
- whether it was registered
- Since:
- 1.16.0
-
getPerks
Every perk, built-in perks first in their order, then registered addon perks.- Since:
- 1.16.0
-
getPerk
A built-in or registered addon perk by its exact key.- Since:
- 1.16.0
-
getNumber
A number perk, built-in or addon, as it applies to a player now.Integer.MAX_VALUEwhen unlimited.- Throws:
IllegalArgumentException- for a toggle perk or a key nothing registered- Since:
- 1.16.0
-
isAllowed
boolean isAllowed(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String perkKey) Whether a toggle perk, built-in or addon, is allowed for a player now.- Throws:
IllegalArgumentException- for a number perk or a key nothing registered- Since:
- 1.16.0
-
getNextTier
@NotNull @NotNull Optional<PerkTier> getNextTier(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String perkKey) The tier a player would have to reach for more of a perk, built-in or addon, asgetNextTier(Player, Perk)answers it.- Since:
- 1.16.0
-
getResolutionMode
How a player holding several tiers gets each perk, fromperks.yml.- Since:
- 1.16.0
-
getAllBoosts
A player's active boosts of every perk, addon perks included, as last read. Boosts of addon perks have a nullPerkBoost.perk();getBoosts(java.util.UUID)leaves them out.- Since:
- 1.16.0
-
grantBoost
@NotNull @NotNull CompletableFuture<PerkBoost> grantBoost(@NotNull @NotNull UUID playerId, @NotNull @NotNull String perkKey, int amount, @NotNull @NotNull Duration duration, @NotNull @NotNull String source) Gives a player a temporary boost of any perk, built-in or addon, by its key.- Throws:
IllegalArgumentException- when the amount or duration is not positive, or the key names no perk- Since:
- 1.16.0
-
getServerBoosts
The server-wide boosts in force, as last read. They apply to every player, on top of their own boosts, and are shared by every server on the same database.- Since:
- 1.16.0
-
startServerBoost
@NotNull @NotNull CompletableFuture<ServerBoost> startServerBoost(@NotNull @NotNull String perkKey, int amount, @NotNull @NotNull Duration duration, @NotNull @NotNull String source) Starts a server-wide boost, announced to players and ending on its own afterduration.- Parameters:
amount- added to a number perk; must be positive. Ignored by a toggle perk- Returns:
- completes on the main thread with the boost as stored
- Throws:
IllegalArgumentException- when the amount or duration is not positive, or the key names no perk- Since:
- 1.16.0
-
endServerBoost
Ends one server-wide boost early.- Returns:
- completes with whether it existed
- Since:
- 1.16.0
-