Class TaskAdvancement
TaskAdvancement
class represents a task. It can be used by any AbstractMultiTasksAdvancement
subclass
to separate an advancement progression into different progression (one per task).
For example, the advancement "mine 5 blocks of every plank" can be made using a TaskAdvancement
for every plank (with a progression of 5) and registering them into an AbstractMultiTasksAdvancement
.
TaskAdvancement
s are saved into the database, but they are never sent to players.
For this reason they cannot be registered in tabs either.
-
Field Summary
Fields inherited from class com.fren_gor.ultimateAdvancementAPI.advancement.BaseAdvancement
parent
Fields inherited from class com.fren_gor.ultimateAdvancementAPI.advancement.Advancement
advancementTab, display, key, maxProgression
-
Constructor Summary
ConstructorDescriptionTaskAdvancement
(@NotNull String key, @NotNull AdvancementDisplay display, @NotNull AbstractMultiTasksAdvancement multitask) Creates a newTaskAdvancement
with a maximum progression of1
.TaskAdvancement
(@NotNull String key, @NotNull AdvancementDisplay display, @NotNull AbstractMultiTasksAdvancement multitask, @Range(from=1, to=Integer.MAX_VALUE) int maxProgression) Creates a newTaskAdvancement
.TaskAdvancement
(@NotNull String key, @NotNull AbstractMultiTasksAdvancement multitask) Creates a newTaskAdvancement
with a maximum progression of1
.TaskAdvancement
(@NotNull String key, @NotNull AbstractMultiTasksAdvancement multitask, @Range(from=1, to=Integer.MAX_VALUE) int maxProgression) Creates a newTaskAdvancement
. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
displayToastToPlayer
(@NotNull Player player) Display the toast of this advancement to a player.final @Nullable BaseComponent[]
getAnnounceMessage
(@NotNull Player player) Gets the chat message to be sent when an advancement is completed.Gets the task'sAbstractMultiTasksAdvancement
.final @NotNull AdvancementWrapper
Returns the NMS wrapper of this advancement.boolean
isValid()
Returns whether the advancement is valid.final boolean
isVisible
(@NotNull TeamProgression progression) Returns whether the advancement is visible to the provided team.final boolean
Returns whether the advancement is visible to the provided player.final boolean
Returns whether the advancement is visible to the provided player.void
Called when the advancement is completed by a player.void
onUpdate
(@NotNull TeamProgression teamProgression, @NotNull Map<AdvancementWrapper, Integer> addedAdvancements) Handles the serialisation of the advancement into the update packet.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
Validate the advancement after it has been registered by the advancement tab.Methods inherited from class com.fren_gor.ultimateAdvancementAPI.advancement.BaseAdvancement
getParent
Methods inherited from class com.fren_gor.ultimateAdvancementAPI.advancement.Advancement
equals, getAdvancementTab, getDisplay, getKey, getMaxProgression, getProgression, getProgression, getProgression, giveReward, grant, grant, handlePlayer, hashCode, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, isGranted, isGranted, isGranted, onDispose, onRegister, registerEvent, registerEvent, revoke, setProgression, setProgression, setProgression, setProgression, toString
-
Constructor Details
-
TaskAdvancement
public TaskAdvancement(@NotNull @NotNull String key, @NotNull @NotNull AbstractMultiTasksAdvancement multitask) Creates a newTaskAdvancement
with a maximum progression of1
.- Parameters:
key
- The unique key of the task. It must be unique among the other advancements of the tab.multitask
- TheAbstractMultiTasksAdvancement
that owns this task.
-
TaskAdvancement
public TaskAdvancement(@NotNull @NotNull String key, @NotNull @NotNull AbstractMultiTasksAdvancement multitask, @Range(from=1, to=Integer.MAX_VALUE) int maxProgression) Creates a newTaskAdvancement
.- Parameters:
key
- The unique key of the task. It must be unique among the other advancements of the tab.multitask
- TheAbstractMultiTasksAdvancement
that owns this task.maxProgression
- The maximum progression of the task.
-
TaskAdvancement
public TaskAdvancement(@NotNull @NotNull String key, @NotNull @NotNull AdvancementDisplay display, @NotNull @NotNull AbstractMultiTasksAdvancement multitask) Creates a newTaskAdvancement
with a maximum progression of1
.- Parameters:
key
- The unique key of the task. It must be unique among the other advancements of the tab.display
- The display information of this task.multitask
- TheAbstractMultiTasksAdvancement
that owns this task.
-
TaskAdvancement
public TaskAdvancement(@NotNull @NotNull String key, @NotNull @NotNull AdvancementDisplay display, @NotNull @NotNull AbstractMultiTasksAdvancement multitask, @Range(from=1, to=Integer.MAX_VALUE) int maxProgression) Creates a newTaskAdvancement
.- Parameters:
key
- The unique key of the task. It must be unique among the other advancements of the tab.display
- The display information of this task.multitask
- TheAbstractMultiTasksAdvancement
that owns this task.maxProgression
- The maximum progression of the task.
-
-
Method Details
-
getAnnounceMessage
@Nullable @Contract(pure=true, value="_ -> null") public final @Nullable BaseComponent[] getAnnounceMessage(@NotNull @NotNull Player player) Gets the chat message to be sent when an advancement is completed.The message is sent to everybody online on the server. This method returns
null
by default.- Overrides:
getAnnounceMessage
in classAdvancement
- Parameters:
player
- The player who has completed the advancement.- Returns:
- Always
null
.
-
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.- Overrides:
setProgression
in classAdvancement
- 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.
-
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
Advancement.isVisible(TeamProgression)
or implementing a suitable interface for the Advancement Visibility System (seeIVisibility
for more information). SinceTaskAdvancement
s are not sent to players, this method always returnsfalse
.- Overrides:
isVisible
in classAdvancement
- Parameters:
player
- The player.- Returns:
- Always
false
.
-
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
Advancement.isVisible(TeamProgression)
or implementing a suitable interface for the Advancement Visibility System (seeIVisibility
for more information). SinceTaskAdvancement
s are not sent to players, this method always returnsfalse
.- Overrides:
isVisible
in classAdvancement
- Parameters:
uuid
- TheUUID
of the player.- Returns:
- Always
false
.
-
isVisible
@Contract("_ -> false") public final boolean isVisible(@NotNull @NotNull TeamProgression progression) 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. Since
TaskAdvancement
s are not sent to players, this method always returnsfalse
.- Overrides:
isVisible
in classAdvancement
- Parameters:
progression
- TheTeamProgression
of the team.- Returns:
- Always
false
.
-
onGrant
Called when the advancement is completed by a player. It handles the chat message, the toast notification, and the advancement rewards (seeAdvancement.giveReward(Player)
for more information).Since
TaskAdvancement
s are not sent to players, this method doesn't send toast notifications and chat messages.- Overrides:
onGrant
in classAdvancement
- Parameters:
player
- The player who completed the advancement.giveRewards
- Whether to give rewards.
-
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.
- Overrides:
isValid
in classAdvancement
- Returns:
- Whether the advancement is valid.
-
getMultiTasksAdvancement
Gets the task'sAbstractMultiTasksAdvancement
.- Returns:
- The task's
AbstractMultiTasksAdvancement
.
-
validateRegister
Validate the advancement after it has been registered by the advancement tab.Since
TaskAdvancement
s cannot be registered in tabs, this method always fails.- Overrides:
validateRegister
in classBaseAdvancement
- Throws:
InvalidAdvancementException
- Every time this method is called.
-
getNMSWrapper
Returns the NMS wrapper of this advancement. Should craft the NMS wrapper once and returns it henceforth.Since
TaskAdvancement
s cannot be registered in tabs, this method always throwsUnsupportedOperationException
.- Overrides:
getNMSWrapper
in classBaseAdvancement
- Returns:
- The NMS wrapper of this advancement.
- Throws:
UnsupportedOperationException
- Every time this method is called.
-
displayToastToPlayer
Display the toast of this advancement to a player.Since
TaskAdvancement
s cannot be registered in tabs, this method always throwsUnsupportedOperationException
.- Overrides:
displayToastToPlayer
in classAdvancement
- Parameters:
player
- The player the toast will be shown to.- Throws:
UnsupportedOperationException
- Every time this method is called.
-
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.Since
TaskAdvancement
s cannot be registered in tabs, this method always throwsUnsupportedOperationException
.- Overrides:
onUpdate
in classAdvancement
- 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.- Throws:
UnsupportedOperationException
- Every time this method is called.
-