Class MultiTasksAdvancement
java.lang.Object
com.fren_gor.ultimateAdvancementAPI.advancement.Advancement
com.fren_gor.ultimateAdvancementAPI.advancement.BaseAdvancement
com.fren_gor.ultimateAdvancementAPI.advancement.tasks.AbstractMultiTasksAdvancement
com.fren_gor.ultimateAdvancementAPI.advancement.tasks.MultiTasksAdvancement
An implementation of
AbstractMultiTasksAdvancement
. TaskAdvancement
s have to be registered
using registerTasks(Set)
in order to initialise an instance of this class.-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected boolean
Whether to enable arbitrary progression updates insetProgression(TeamProgression, Player, int, boolean)
.The cache for the team's progressions (the key is the team unique id).protected final Set
<TaskAdvancement> The tasks of this advancement.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
ConstructorDescriptionMultiTasksAdvancement
(@NotNull String key, @NotNull AdvancementDisplay display, @NotNull Advancement parent, @Range(from=1, to=Integer.MAX_VALUE) int maxProgression) Creates a newMultiTasksAdvancement
. -
Method Summary
Modifier and TypeMethodDescriptiongetProgression
(@NotNull TeamProgression progression) Gets the current progression of the provided team.getTasks()
Gets an unmodifiableSet
of the registered tasks.boolean
Returns whether the advancement has been completed by the provided team.boolean
Returns whether the multi-task advancement is initialised.void
Called when the advancement is disposed.void
registerTasks
(@NotNull TaskAdvancement... tasks) Register the tasks for this multi-task advancement, initializing it.void
registerTasks
(@NotNull Set<TaskAdvancement> tasks) Register the tasks for this multi-task advancement, initializing it.protected void
reloadTasks
(@NotNull TeamProgression progression, @Nullable Player player, boolean giveRewards) Reloads and updates the tasks to the provided team members.void
Resets the progression cache for every team.void
Resets the progression cache for the provided team.protected void
setProgression
(@NotNull TeamProgression progression, @Nullable Player player, @Range(from=0, to=Integer.MAX_VALUE) int newProgression, boolean giveRewards) Sets a progression for the provided player's team.protected void
updateProgressionCache
(@NotNull TeamProgression pro, @Range(from=0, to=Integer.MAX_VALUE) int progression) Updates the progression cache 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.tasks.AbstractMultiTasksAdvancement
reloadTasks, reloadTasks, reloadTasks, reloadTasks
Methods inherited from class com.fren_gor.ultimateAdvancementAPI.advancement.BaseAdvancement
getNMSWrapper, getParent
Methods inherited from class com.fren_gor.ultimateAdvancementAPI.advancement.Advancement
displayToastToPlayer, equals, getAdvancementTab, getAnnounceMessage, getDisplay, getKey, getMaxProgression, getProgression, getProgression, giveReward, grant, grant, handlePlayer, hashCode, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, incrementProgression, isGranted, isGranted, isValid, isVisible, isVisible, isVisible, onGrant, onRegister, onUpdate, registerEvent, registerEvent, revoke, setProgression, setProgression, setProgression, setProgression, toString
-
Field Details
-
ENABLE_ARBITRARY_SET_PROGRESSION
protected boolean ENABLE_ARBITRARY_SET_PROGRESSIONWhether to enable arbitrary progression updates insetProgression(TeamProgression, Player, int, boolean)
.- See Also:
-
DISABLE_EXCEPTION_ON_ARBITRARY_SET_PROGRESSION
protected boolean DISABLE_EXCEPTION_ON_ARBITRARY_SET_PROGRESSIONWhether to disableArbitraryMultiTaskProgressionUpdateException
insetProgression(TeamProgression, Player, int, boolean)
.Ignored when
ENABLE_ARBITRARY_SET_PROGRESSION
is set totrue
.- See Also:
-
tasks
The tasks of this advancement. -
progressionsCache
The cache for the team's progressions (the key is the team unique id).
-
-
Constructor Details
-
MultiTasksAdvancement
public MultiTasksAdvancement(@NotNull @NotNull String key, @NotNull @NotNull AdvancementDisplay display, @NotNull @NotNull Advancement parent, @Range(from=1, to=Integer.MAX_VALUE) int maxProgression) Creates a newMultiTasksAdvancement
.- Parameters:
key
- The unique key of the advancement. It must be unique among the other advancements of the tab.display
- The display information of this advancement.parent
- The parent of this advancement.maxProgression
- The sum of the maximum progressions of all the tasks that will be registered.
-
-
Method Details
-
registerTasks
Register the tasks for this multi-task advancement, initializing it. Thus, it cannot be called twice.- Parameters:
tasks
- The tasks to register. Cannot include anynull
task.
-
registerTasks
Register the tasks for this multi-task advancement, initializing it. Thus, it cannot be called twice.- Parameters:
tasks
- The tasks to register. Cannot include anynull
task.
-
getTasks
Gets an unmodifiableSet
of the registered tasks.- Returns:
- An unmodifiable
Set
of the registered tasks. - Throws:
IllegalStateException
- If the multi-task advancement is not initialised.
-
getProgression
public @Range(from=0, to=Integer.MAX_VALUE) int getProgression(@NotNull @NotNull TeamProgression progression) Gets the current progression of the provided team.- Overrides:
getProgression
in classAdvancement
- Parameters:
progression
- TheTeamProgression
of the team.- Returns:
- The current progression of the team.
- Throws:
IllegalStateException
- If the multi-task advancement is not initialised.
-
isGranted
Returns whether the advancement has been completed by the provided team.- Overrides:
isGranted
in classAdvancement
- Parameters:
pro
- TheTeamProgression
of the team.- Returns:
- Whether the advancement has been completed by the provided team.
- Throws:
IllegalStateException
- If the multi-task advancement is not initialised.
-
setProgression
protected void setProgression(@NotNull @NotNull TeamProgression progression, @Nullable @Nullable Player player, @Range(from=0, to=Integer.MAX_VALUE) int newProgression, boolean giveRewards) throws ArbitraryMultiTaskProgressionUpdateException Sets a progression for the provided player's team. SinceMultiTasksAdvancement
handles a set ofTaskAdvancement
s, it is not possible (by default) to set any progression, but0
orAdvancement.maxProgression
. Setting any progression between those will result in anArbitraryMultiTaskProgressionUpdateException
.To enable arbitrary progression updates, set
ENABLE_ARBITRARY_SET_PROGRESSION
totrue
(false
by default). To prevent the throwing ofArbitraryMultiTaskProgressionUpdateException
s setDISABLE_EXCEPTION_ON_ARBITRARY_SET_PROGRESSION
totrue
.- Overrides:
setProgression
in classAdvancement
- Parameters:
progression
- TheTeamProgression
of the player.player
- The player,null
if it's not online. (Note: it must have been loaded into cache)newProgression
- The new progression to set. Must be between 0 andAdvancement.maxProgression
.giveRewards
- Whether to give rewards to player if the team's progression reachesAdvancement.maxProgression
.- Throws:
ArbitraryMultiTaskProgressionUpdateException
- When the provided new progression is not0
orAdvancement.maxProgression
and eitherENABLE_ARBITRARY_SET_PROGRESSION
orDISABLE_EXCEPTION_ON_ARBITRARY_SET_PROGRESSION
are not set totrue
.IllegalStateException
- If the multi-task advancement is not initialised.
-
reloadTasks
protected void reloadTasks(@NotNull @NotNull TeamProgression progression, @Nullable @Nullable Player player, boolean giveRewards) Reloads and updates the tasks to the provided team members.This method should be invoked when the progression of a task changes.
- Specified by:
reloadTasks
in classAbstractMultiTasksAdvancement
- Parameters:
progression
- TheTeamProgression
of the team.player
- The player responsible for the task's progression update, ornull
if there's not. In this case, the implementation can choose a random online member.- Throws:
IllegalStateException
- If the multi-task advancement is not initialised.
-
resetProgressionCache
public void resetProgressionCache()Resets the progression cache for every team. -
resetProgressionCache
Resets the progression cache for the provided team.- Parameters:
pro
- The team to remove from the cache.
-
updateProgressionCache
protected void updateProgressionCache(@NotNull @NotNull TeamProgression pro, @Range(from=0, to=Integer.MAX_VALUE) int progression) Updates the progression cache for the provided team.- Parameters:
pro
- The team to update.progression
- The new progression to store in cache.
-
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.- Overrides:
validateRegister
in classBaseAdvancement
- Throws:
InvalidAdvancementException
- If the validation fails.
-
onDispose
public void onDispose()Called when the advancement is disposed.- Overrides:
onDispose
in classAdvancement
- Throws:
IllegalStateException
- If the multi-task advancement is not initialised.
-
isInitialised
public boolean isInitialised()Returns whether the multi-task advancement is initialised.- Returns:
- Whether the multi-task advancement is initialised.
-