Class AdvancementRegisterBuilder<E extends org.bukkit.event.Event>

java.lang.Object
io.github.lambdaphoenix.advancementLib.AdvancementRegisterBuilder<E>
Type Parameters:
E - the event type

public class AdvancementRegisterBuilder<E extends org.bukkit.event.Event> extends Object
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)
These must be set before calling build().

Optional parameters:

  • condition - predicate for event acceptance (defaults to always true)
  • playerExtractor - function to extract the player from the event (defaults to PlayerExtractor.getDefaultPlayerExtractor(Class, Logger) if available)
  • increment - function to determine progress increment (if null, 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 Details

    • AdvancementRegisterBuilder

      public AdvancementRegisterBuilder(AdvancementAPI api)
      Start building a new advancement.
      Parameters:
      api - the AdvancementAPI instance; must not be null
      Throws:
      NullPointerException - if api is null
      Since:
      0.2.0
      See Also:
    • AdvancementRegisterBuilder

      public AdvancementRegisterBuilder(AdvancementAPI api, String advancementKey)
      Start building a new advancement with a specific key.
      Parameters:
      api - the AdvancementAPI instance; must not be null
      advancementKey - the unique name for this advancement; must not be null
      Since:
      0.2.0
      See Also:
    • AdvancementRegisterBuilder

      public AdvancementRegisterBuilder(AdvancementAPI api, String advancementKey, Class<E> eventType)
      Start building a new advancement with a specific key and event type.
      Parameters:
      api - the AdvancementAPI instance; must not be null
      advancementKey - the unique name for this advancement; must not be null
      eventType - the event type that triggers this advancement; must not be null
      Since:
      0.2.0
      See Also:
  • Method Details

    • advancementKey

      public AdvancementRegisterBuilder<E> advancementKey(String advancementKey)
      Sets the unique identifier for this advancement.
      Parameters:
      advancementKey - the advancement name; must not be null
      Returns:
      this builder
      Throws:
      NullPointerException - if advancementKey is null
      Since:
      0.2.0
    • eventType

      public AdvancementRegisterBuilder<E> eventType(Class<E> eventType)
      Sets the event type that triggers this advancement.
      Parameters:
      eventType - the event class; must not be null
      Returns:
      this builder
      Throws:
      NullPointerException - if eventType is null
      Since:
      0.2.0
      See Also:
      • Event
    • condition

      public AdvancementRegisterBuilder<E> condition(BiPredicate<org.bukkit.entity.Player,E> 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

      public AdvancementRegisterBuilder<E> targetValue(int 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

      public AdvancementRegisterBuilder<E> grantMode(GrantMode grantMode)
      Sets how criteria are granted to the player

      Defaults to GrantMode.ALL_AT_ONCE.

      Parameters:
      grantMode - the grant mode; must not be null
      Returns:
      this builder
      Throws:
      NullPointerException - if grantMode is null
      Since:
      0.2.0
      See Also:
    • increment

      public AdvancementRegisterBuilder<E> increment(ToIntFunction<E> 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

      public AdvancementRegisterBuilder<E> requireParent(boolean 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 and eventType before calling this.

      Throws:
      IllegalArgumentException - if required fields are missing or invalid
      Since:
      0.2.0
      See Also:
      • AdvancementAPI.registerAdvancement(String, Class, BiPredicate, int, Function, GrantMode, ToIntFunction, boolean)