Class AdvancementRegisterBuilder<E extends org.bukkit.event.Event>
java.lang.Object
io.github.lambdaphoenix.advancementLib.AdvancementRegisterBuilder<E>
- Type Parameters:
E
- the event type
Fluent Builder for registering custom advancements in your plugin.
Allows you to specify all the details for your advancement, including the event, conditions, progress targets, and how criteria are granted.
Required parameters:
advancementKey
(unique string identifier)eventType
(class of the Bukkit event)
build()
.
Optional parameters:
condition
- predicate for event acceptance (defaults to always true)playerExtractor
- function to extract the player from the event (defaults toPlayerExtractor.getDefaultPlayerExtractor(Class, Logger)
if available)increment
- function to determine progress increment (ifnull
, defaults to 1 per event; otherwise, uses the provided function)targetValue
- required progress to complete (default: 1, must be at least 1)grantMode
- how the advancement is granted (default:GrantMode.ALL_AT_ONCE
)
Note: The PlayerExtractor
utility provides default extractors for common Bukkit
events. For custom events, you may supply your own extractor.
- Since:
- 0.2.0
- Version:
- 0.3.2
- Author:
- lambdaphoenix
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionStart building a new advancement.AdvancementRegisterBuilder
(AdvancementAPI api, String advancementKey) Start building a new advancement with a specific key.AdvancementRegisterBuilder
(AdvancementAPI api, String advancementKey, Class<E> eventType) Start building a new advancement with a specific key and event type. -
Method Summary
Modifier and TypeMethodDescriptionadvancementKey
(String advancementKey) Sets the unique identifier for this advancement.void
build()
Registers the advancement with the specified configuration.condition
(BiPredicate<org.bukkit.entity.Player, E> condition) Sets the condition that must be true for the advancement to progress.Sets the event type that triggers this advancement.Sets how criteria are granted to the playerincrement
(ToIntFunction<E> increment) Sets how much progress each event should add.playerExtractor
(Function<E, org.bukkit.entity.Player> playerExtractor) Sets a custom function to extract the player from the event.requireParent
(boolean requireParent) Sets if the parent advancement needs to be completed.targetValue
(int targetValue) Sets how many times the event must occur before the advancement is granted.
-
Constructor Details
-
AdvancementRegisterBuilder
Start building a new advancement.- Parameters:
api
- the AdvancementAPI instance; must not benull
- Throws:
NullPointerException
- ifapi
isnull
- Since:
- 0.2.0
- See Also:
-
AdvancementRegisterBuilder
Start building a new advancement with a specific key.- Parameters:
api
- the AdvancementAPI instance; must not benull
advancementKey
- the unique name for this advancement; must not benull
- Since:
- 0.2.0
- See Also:
-
AdvancementRegisterBuilder
Start building a new advancement with a specific key and event type.- Parameters:
api
- the AdvancementAPI instance; must not benull
advancementKey
- the unique name for this advancement; must not benull
eventType
- the event type that triggers this advancement; must not benull
- Since:
- 0.2.0
- See Also:
-
-
Method Details
-
advancementKey
Sets the unique identifier for this advancement.- Parameters:
advancementKey
- the advancement name; must not benull
- Returns:
- this builder
- Throws:
NullPointerException
- ifadvancementKey
isnull
- Since:
- 0.2.0
-
eventType
Sets the event type that triggers this advancement.- Parameters:
eventType
- the event class; must not benull
- Returns:
- this builder
- Throws:
NullPointerException
- ifeventType
isnull
- Since:
- 0.2.0
- See Also:
-
condition
Sets the condition that must be true for the advancement to progress.If not set, defaults to always
true
.- Parameters:
condition
- a predicate(player, event) -> true
if this event should count- Returns:
- this builder
- Since:
- 0.2.0
- See Also:
-
targetValue
Sets how many times the event must occur before the advancement is granted.Must be at least 1. Default is 1.
- Parameters:
targetValue
- the number of times the event must occur- Returns:
- this builder
- Since:
- 0.2.0
-
playerExtractor
public AdvancementRegisterBuilder<E> playerExtractor(Function<E, org.bukkit.entity.Player> playerExtractor) Sets a custom function to extract the player from the event.If not set, a default extractor will be used if available for the event type (see
PlayerExtractor.getDefaultPlayerExtractor(Class, Logger)
).- Parameters:
playerExtractor
- function to extract the player from the event- Returns:
- this builder
- Since:
- 0.2.0
- See Also:
-
grantMode
Sets how criteria are granted to the playerDefaults to
GrantMode.ALL_AT_ONCE
.- Parameters:
grantMode
- the grant mode; must not benull
- Returns:
- this builder
- Throws:
NullPointerException
- ifgrantMode
isnull
- Since:
- 0.2.0
- See Also:
-
increment
Sets how much progress each event should add.If not set, each event increases progress by 1.
- Parameters:
increment
- function to determine progress increment- Returns:
- this builder
- Since:
- 0.2.0
- See Also:
-
requireParent
Sets if the parent advancement needs to be completed.If not set, parent advancement is not needed.
- Parameters:
requireParent
- boolean- Returns:
- this builder
- Since:
- 0.3.2
-
build
public void build()Registers the advancement with the specified configuration.You must set both
advancementKey
andeventType
before calling this.- Throws:
IllegalArgumentException
- if required fields are missing or invalid- Since:
- 0.2.0
- See Also:
-