Class Advancement
- Direct Known Subclasses:
BaseAdvancement
,RootAdvancement
Advancement
class is the parent class of every advancement.
It provides the basic methods and fields to work with advancements.
It is extended only by RootAdvancement and BaseAdvancement. It cannot be extended by any other class, which should extends
-
Field Summary
Modifier and TypeFieldDescriptionprotected final @NotNull AdvancementTab
The advancement tab of the advancement.protected final @NotNull AdvancementDisplay
The advancement display of the advancement.protected final @NotNull AdvancementKey
The namespaced key of the advancement, which identifies it univocally.The maximum progression of the advancement. -
Method Summary
Modifier and TypeMethodDescriptionvoid
displayToastToPlayer
(@NotNull Player player) Display the toast of this advancement to a player.boolean
final @NotNull AdvancementTab
Gets the advancement tab of the advancement.getAnnounceMessage
(@NotNull Player player) Gets the chat message to be sent when an advancement is completed.Gets theAdvancementDisplay
of this advancement.final @NotNull AdvancementKey
getKey()
Gets the advancement namespaced key.Gets the maximum progression of the advancement.abstract @NotNull AdvancementWrapper
Returns the NMS wrapper of this advancement.getProgression
(@NotNull TeamProgression progression) Gets the current progression of the provided team.getProgression
(@NotNull UUID uuid) Gets the current progression of the provided player's team.getProgression
(@NotNull Player player) Gets the current progression of the provided player's team.void
giveReward
(@NotNull Player player) Gives the rewards to the provided player when the advancement is completed.void
Grants the advancement to the player's team giving rewards.void
Grant the advancement to the player's team.protected void
handlePlayer
(@NotNull TeamProgression pro, @Nullable Player player, int newProgression, int oldProgression, boolean giveRewards, @Nullable AfterHandle afterHandle) Handles the reward process of the advancement.int
hashCode()
incrementProgression
(@NotNull TeamProgression pro, @Nullable Player player, @Range(from=1, to=Integer.MAX_VALUE) int increment, boolean giveRewards) Increases the progression of the provided team.incrementProgression
(@NotNull UUID uuid) Increases the progression of the provided player's team by one.Increases the progression of the provided player's team.incrementProgression
(@NotNull UUID uuid, @Range(from=1, to=Integer.MAX_VALUE) int increment, boolean giveReward) Increases the progression of the provided player's team.incrementProgression
(@NotNull UUID uuid, boolean giveReward) Increases the progression of the provided player's team by one.incrementProgression
(@NotNull Player player) Increases the progression of the provided player's team by one.Increases the progression of the provided player's team.incrementProgression
(@NotNull Player player, @Range(from=1, to=Integer.MAX_VALUE) int increment, boolean giveReward) Increases the progression of the provided player's team.incrementProgression
(@NotNull Player player, boolean giveReward) Increases the progression of the provided player's team by one.boolean
isGranted
(@NotNull TeamProgression progression) Returns whether the advancement has been completed by the provided team.boolean
Returns whether the advancement has been completed by the provided player's team.boolean
Returns whether the advancement has been completed by the provided player's team.boolean
isValid()
Returns whether the advancement is valid.boolean
isVisible
(@NotNull TeamProgression progression) Returns whether the advancement is visible to the provided team.boolean
Returns whether the advancement is visible to the provided player.boolean
Returns whether the advancement is visible to the provided player.void
Called when the advancement is disposed.void
Called when the advancement is completed by a player.void
Called when the advancement is registered by itsAdvancementTab
throughAdvancementTab.registerAdvancements(RootAdvancement, Set)
.void
onUpdate
(@NotNull TeamProgression teamProgression, @NotNull Map<AdvancementWrapper, Integer> addedAdvancements) Handles the serialisation of the advancement into the update packet.protected final <E extends Event>
voidregisterEvent
(@NotNull Class<E> eventClass, @NotNull Consumer<E> consumer) Registers the provided event into the tabEventManager
.protected final <E extends Event>
voidregisterEvent
(@NotNull Class<E> eventClass, @NotNull EventPriority priority, @NotNull Consumer<E> consumer) Registers the provided event into the tabEventManager
.void
Revoke the advancement to the player's team.protected void
setProgression
(@NotNull TeamProgression pro, @Nullable Player player, @Range(from=0, to=Integer.MAX_VALUE) int progression, boolean giveRewards) Sets a new progression for the provided team.void
Sets a progression for the provided player's team.void
setProgression
(@NotNull UUID uuid, @Range(from=0, to=Integer.MAX_VALUE) int progression, boolean giveReward) Sets a progression for the provided player's team.void
Sets a progression for the provided player's team.void
setProgression
(@NotNull Player player, @Range(from=0, to=Integer.MAX_VALUE) int progression, boolean giveReward) Sets a progression for the provided player's team.toString()
Returns the advancement namespaced key asString
.void
Validate the advancement after it has been registered by the advancement tab.
-
Field Details
-
key
The namespaced key of the advancement, which identifies it univocally.Note that the namespace of the key is the tab's one.
-
advancementTab
The advancement tab of the advancement. -
display
The advancement display of the advancement. -
maxProgression
The maximum progression of the advancement.
-
-
Method Details
-
getKey
Gets the advancement namespaced key.- Returns:
- The advancement namespaced key.
-
getAdvancementTab
Gets the advancement tab of the advancement.- Returns:
- The advancement tab of the advancement.
-
getMaxProgression
Gets the maximum progression of the advancement.- Returns:
- The maximum progression of the advancement.
-
getProgression
Gets the current progression of the provided player's team.- Parameters:
player
- The player.- Returns:
- The current progression of the provided player's team.
-
getProgression
Gets the current progression of the provided player's team.- Parameters:
uuid
- TheUUID
of the player.- Returns:
- The current progression of the provided player's team.
-
getProgression
public @Range(from=0, to=Integer.MAX_VALUE) int getProgression(@NotNull @NotNull TeamProgression progression) Gets the current progression of the provided team.- Parameters:
progression
- TheTeamProgression
of the team.- Returns:
- The current progression of the team.
-
isGranted
Returns whether the advancement has been completed by the provided player's team.- Parameters:
player
- The player.- Returns:
- Whether the advancement has been completed by the provided player's team.
-
isGranted
Returns whether the advancement has been completed by the provided player's team.- Parameters:
uuid
- TheUUID
of the player.- Returns:
- Whether the advancement has been completed by the provided player's team.
-
isGranted
Returns whether the advancement has been completed by the provided team.- Parameters:
progression
- TheTeamProgression
of the team.- Returns:
- Whether the advancement has been completed by the provided team.
-
getAnnounceMessage
Gets the chat message to be sent when an advancement is completed.The message is sent to everybody online on the server.
- Parameters:
player
- The player who has completed the advancement.- Returns:
- The message to be displayed, or
null
if no message should be displayed.
-
incrementProgression
public @Range(from=0, to=Integer.MAX_VALUE) int incrementProgression(@NotNull @NotNull Player player) Increases the progression of the provided player's team by one.If the advancement gets completed, advancement rewards will be given.
- Parameters:
player
- The player who is responsible for the increment.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
incrementProgression
public @Range(from=0, to=Integer.MAX_VALUE) int incrementProgression(@NotNull @NotNull Player player, boolean giveReward) Increases the progression of the provided player's team by one.- Parameters:
player
- The player who is responsible for the increment.giveReward
- Whether to give rewards if the advancement gets completed.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
incrementProgression
public @Range(from=0, to=Integer.MAX_VALUE) int incrementProgression(@NotNull @NotNull Player player, @Range(from=1, to=Integer.MAX_VALUE) int increment) Increases the progression of the provided player's team.If the advancement gets completed, advancement rewards will be given.
- Parameters:
player
- The player who is responsible for the increment.increment
- The progression increment. Must be greater than0
.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
incrementProgression
public @Range(from=0, to=Integer.MAX_VALUE) int incrementProgression(@NotNull @NotNull Player player, @Range(from=1, to=Integer.MAX_VALUE) int increment, boolean giveReward) Increases the progression of the provided player's team.- Parameters:
player
- The player who is responsible for the increment.increment
- The progression increment. Must be greater than0
.giveReward
- Whether to give rewards if the advancement gets completed.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
incrementProgression
Increases the progression of the provided player's team by one.If the advancement gets completed, advancement rewards will be given.
- Parameters:
uuid
- TheUUID
of the player responsible for the increment. If the player is not online, rewards will be given to a pseudorandom online member of the same team if there are any, or it will be set unredeemed.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
incrementProgression
public @Range(from=0, to=Integer.MAX_VALUE) int incrementProgression(@NotNull @NotNull UUID uuid, boolean giveReward) Increases the progression of the provided player's team by one.- Parameters:
uuid
- TheUUID
of the player responsible for the increment. If the player is not online, rewards will be given to a pseudorandom online member of the same team if there are any, or it will be set unredeemed.giveReward
- Whether to give rewards if the advancement gets completed.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
incrementProgression
public @Range(from=0, to=Integer.MAX_VALUE) int incrementProgression(@NotNull @NotNull UUID uuid, @Range(from=1, to=Integer.MAX_VALUE) int increment) Increases the progression of the provided player's team.If the advancement gets completed, advancement rewards will be given.
- Parameters:
uuid
- TheUUID
of the player responsible for the increment. If the player is not online, rewards will be given to a pseudorandom online member of the same team if there are any, or it will be set unredeemed.increment
- The progression increment. Must be greater than0
.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
incrementProgression
public @Range(from=0, to=Integer.MAX_VALUE) int incrementProgression(@NotNull @NotNull UUID uuid, @Range(from=1, to=Integer.MAX_VALUE) int increment, boolean giveReward) Increases the progression of the provided player's team.- Parameters:
uuid
- TheUUID
of the player responsible for the increment. If the player is not online, rewards will be given to a pseudorandom online member of the same team if there are any, or it will be set unredeemed.increment
- The progression increment. Must be greater than0
.giveReward
- Whether to give rewards if the advancement gets completed.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
incrementProgression
protected @Range(from=0, to=Integer.MAX_VALUE) int incrementProgression(@NotNull @NotNull TeamProgression pro, @Nullable @Nullable Player player, @Range(from=1, to=Integer.MAX_VALUE) int increment, boolean giveRewards) Increases the progression of the provided team.The provided player must be an online member of the team. If no members are online or no particular player is to be preferred, it can be put to
null
. In this case, rewards will be given to a pseudorandom online member if there are any or the advancement will be set unredeemed.- Parameters:
pro
- TheTeamProgression
of the team.player
- The team member responsible for the increment. May benull
.increment
- The progression increment. Must be greater than0
.giveRewards
- Whether to give rewards if the advancement gets completed.- Returns:
- The new progression. It is always less or equal to
maxProgression
.
-
setProgression
public void setProgression(@NotNull @NotNull Player player, @Range(from=0, to=Integer.MAX_VALUE) int progression) Sets a progression for the provided player's team.If the advancement gets completed, advancement rewards will be given.
- Parameters:
player
- The player who is responsible for the update.progression
- The new non-negative progression to set.
-
setProgression
public void setProgression(@NotNull @NotNull Player player, @Range(from=0, to=Integer.MAX_VALUE) int progression, boolean giveReward) Sets a progression for the provided player's team.- Parameters:
player
- The player who is responsible for the update.progression
- The new non-negative progression to set.giveReward
- Whether to give rewards if the advancement gets completed.
-
setProgression
public void setProgression(@NotNull @NotNull UUID uuid, @Range(from=0, to=Integer.MAX_VALUE) int progression) Sets a progression for the provided player's team.If the advancement gets completed, advancement rewards will be given.
- Parameters:
uuid
- TheUUID
of the player responsible for the update. If the player is not online, rewards will be given to a pseudorandom online member of the same team if there are any, or it will be set unredeemed.progression
- The new non-negative progression to set.
-
setProgression
public void setProgression(@NotNull @NotNull UUID uuid, @Range(from=0, to=Integer.MAX_VALUE) int progression, boolean giveReward) Sets a progression for the provided player's team.- Parameters:
uuid
- TheUUID
of the player responsible for the update. If the player is not online, rewards will be given to a pseudorandom online member of the same team if there are any, or it will be set unredeemed.progression
- The new non-negative progression to set.giveReward
- Whether to give rewards if the advancement gets completed.
-
setProgression
protected void setProgression(@NotNull @NotNull TeamProgression pro, @Nullable @Nullable Player player, @Range(from=0, to=Integer.MAX_VALUE) int progression, boolean giveRewards) Sets a new progression for the provided team.The provided player must be an online member of the team. If no members are online or no particular player is to be preferred, it can be put to
null
. In this case, rewards will be given to a pseudorandom online member if there are any or the advancement will be set unredeemed.- Parameters:
pro
- TheTeamProgression
that belongs to the team.player
- The team member responsible for the update. May benull
.progression
- The new non-negative progression to set.giveRewards
- Whether to give rewards if the advancement gets completed.
-
handlePlayer
protected void handlePlayer(@NotNull @NotNull TeamProgression pro, @Nullable @Nullable Player player, int newProgression, int oldProgression, boolean giveRewards, @Nullable @Nullable AfterHandle afterHandle) Handles the reward process of the advancement.When the new progression is greater or equal than
maxProgression
and the old progression is less thanmaxProgression
then the advancement is being completed by the provided player. If the provided player is non-null, they will receive the rewards. Otherwise, if there are online members in the team one of them will receive the advancement rewards. If no member of the team are online, the advancement will be set unredeemed for that team.- Parameters:
pro
- TheTeamProgression
of the team.player
- The team member responsible for the update. May benull
.newProgression
- The new non-negative progression that has been set.oldProgression
- The previous progression of the team.giveRewards
- Whether to give rewards if the advancement gets completed.afterHandle
- The action to perform after the reward process, ornull
to don't do any action. The default action updates the tab's advancement to the team (seeAfterHandle.UPDATE_ADVANCEMENTS_TO_TEAM
).
-
displayToastToPlayer
Display the toast of this advancement to a player.- Parameters:
player
- The player the toast will be shown to.
-
isVisible
Returns whether the advancement is visible to the provided player.An advancement is visible to a player if and only if it is visible to all the players in the player's team. By default, every advancement is visible to every player, but this behavior can be changed overriding
isVisible(TeamProgression)
or implementing a suitable interface for the Advancement Visibility System (seeIVisibility
for more information).- Parameters:
player
- The player.- Returns:
- Whether the advancement is visible to the player.
-
isVisible
Returns whether the advancement is visible to the provided player.An advancement is visible to a player if and only if it is visible to all the players in the player's team. By default, every advancement is visible to every player, but this behavior can be changed overriding
isVisible(TeamProgression)
or implementing a suitable interface for the Advancement Visibility System (seeIVisibility
for more information).- Parameters:
uuid
- TheUUID
of the player.- Returns:
- Whether the advancement is visible to the player.
-
isVisible
Returns whether the advancement is visible to the provided team.An advancement is visible to a team if and only if it is visible to all the players in the team. By default, every advancement is visible to every player, but this behavior can be changed overriding this method or implementing a suitable interface for the Advancement Visibility System.
- Implementation Requirements:
- This method is the core method of the Advancement Visibility System (AVS).
The return value is
true
if no suitable interfaces for the AVS are implemented, or the result ofIVisibility.isVisible(Advancement, TeamProgression)
otherwise. When overridden, this method (called viasuper
) enables the AVS features for that method. - Parameters:
progression
- TheTeamProgression
of the team.- Returns:
- Whether the advancement is visible to the provided team.
-
onGrant
Called when the advancement is completed by a player. It handles the chat message, the toast notification, and the advancement rewards (seegiveReward(Player)
for more information).- Parameters:
player
- The player who completed the advancement.giveRewards
- Whether to give rewards.
-
grant
Grants the advancement to the player's team giving rewards.- Parameters:
player
- The player.
-
grant
Grant the advancement to the player's team.- Parameters:
player
- The playergiveRewards
- Whether to give rewards.
-
revoke
Revoke the advancement to the player's team.- Parameters:
player
- The player.
-
onUpdate
public void onUpdate(@NotNull @NotNull TeamProgression teamProgression, @NotNull @NotNull Map<AdvancementWrapper, Integer> addedAdvancements) Handles the serialisation of the advancement into the update packet.Advancement(s) to be sent have to be added to the provided
Map
, which contains theAdvancementWrapper
s paired with the progression of the provided team.- Parameters:
teamProgression
- TheTeamProgression
of the team of the player(s).addedAdvancements
- TheMap
in which the advancements to be sent are added as keys. The values are the current progressions of the team.
-
giveReward
Gives the rewards to the provided player when the advancement is completed.- Implementation Requirements:
- This method does not do anything by default. Override it to change its behavior.
- Parameters:
player
- The player who has completed the advancement.
-
onRegister
public void onRegister()Called when the advancement is registered by itsAdvancementTab
throughAdvancementTab.registerAdvancements(RootAdvancement, Set)
.No exception should be thrown, to validate the advancement registration see
validateRegister()
.Note that not every method of
AdvancementTab
is available, since this method is called before the tab is set initialised.- Implementation Requirements:
- This method does not do anything by default. Override it to change its behavior.
-
validateRegister
Validate the advancement after it has been registered by the advancement tab. If the validation fails, aInvalidAdvancementException
should be thrown.For example,
BaseAdvancement
overrides this method to make sure it and its parent belongs to the same tab.Note that every method of
AdvancementTab
is available, since this method is called after every advancement has been registered and the tab has already been initialised.- Implementation Requirements:
- This method does not do anything by default. Override it to change its behavior.
- Throws:
InvalidAdvancementException
- If the validation fails.
-
onDispose
public void onDispose()Called when the advancement is disposed.- Implementation Requirements:
- This method does not do anything by default. Override it to change its behavior.
-
isValid
public boolean isValid()Returns whether the advancement is valid.An advancement is valid if and only if it belongs to its advancement tab and that tab is active.
- Returns:
- Whether the advancement is valid.
-
getNMSWrapper
Returns the NMS wrapper of this advancement. Should craft the NMS wrapper once and returns it henceforth.- Returns:
- The NMS wrapper of this advancement.
-
registerEvent
protected final <E extends Event> void registerEvent(@NotNull @NotNull Class<E> eventClass, @NotNull @NotNull Consumer<E> consumer) Registers the provided event into the tabEventManager
.- Type Parameters:
E
- The class of the event to register.- Parameters:
eventClass
- The class of the event to register.consumer
- The code to run when the event occurs.- Throws:
DisposedException
- If theAdvancementTab
of this advancement is disposed.IllegalArgumentException
- If any argument is null.
-
registerEvent
protected final <E extends Event> void registerEvent(@NotNull @NotNull Class<E> eventClass, @NotNull @NotNull EventPriority priority, @NotNull @NotNull Consumer<E> consumer) Registers the provided event into the tabEventManager
.- Type Parameters:
E
- The class of the event to register.- Parameters:
eventClass
- The class of the event to register.priority
- The priority of the event. SeeEventPriority
.consumer
- The code to run when the event occurs.- Throws:
DisposedException
- If theAdvancementTab
of this advancement is disposed.IllegalArgumentException
- If any argument is null.
-
toString
Returns the advancement namespaced key asString
.Calling this method is equivalent to call
getKey().toString()
. -
equals
-
hashCode
public int hashCode() -
getDisplay
Gets theAdvancementDisplay
of this advancement.- Returns:
- The
AdvancementDisplay
of this advancement.
-