Class AdvancementAPI

java.lang.Object
io.github.lambdaphoenix.advancementLib.AdvancementAPI

public final class AdvancementAPI extends Object
API for registering and tracking custom or vanilla advancements in your plugin.

Use this API to define custom triggers and conditions for granting advancements to players. All registration must go through the builder pattern.

Example usage:


 AdvancementAPI api = new AdvancementAPI(plugin);
 api.register(PlayerInteractEvent.class)
  .advancementKey("minecraft:adventure/trade")
  .condition((player, event) -> event.getAction() == Action.RIGHT_CLICK_BLOCK)
  .targetValue(5)
  .playerExtractor(event -> event.getPlayer())
  .build();
 
Since:
0.1.0
Version:
0.3.2
Author:
lambdaphoenix
See Also:
  • Constructor Details

    • AdvancementAPI

      public AdvancementAPI(org.bukkit.plugin.Plugin plugin)
      Creates a new AdvancementAPI instance for your plugin.
      Parameters:
      plugin - your plugin instance (not null)
      Throws:
      NullPointerException - if plugin is null
      Since:
      0.1.0
      See Also:
      • Plugin
  • Method Details

    • register

      public <E extends org.bukkit.event.Event> AdvancementRegisterBuilder<E> register(Class<E> eventType)
      Starts a new AdvancementRegisterBuilder for the given event type.

      This is the only supported way to register advancements.

      Type Parameters:
      E - the event type
      Parameters:
      eventType - the Bukkit event class to listen for
      Returns:
      a new builder instance
      Since:
      0.2.0
      See Also:
    • getProgress

      public int getProgress(String advancementKey, org.bukkit.entity.Player player)
      Gets the current progress towards an advancement for a specific player.
      Parameters:
      advancementKey - the namespaced key of the advancement
      player - the player to check progress for
      Returns:
      the number of times the condition has been met
      Since:
      0.1.0
    • resetProgress

      public void resetProgress(String advancementKey, org.bukkit.entity.Player player)
      Resets the current progress for the specified advancement to the player.
      Parameters:
      advancementKey - the namespaced key of the advancement
      player - the player who should have their progress reset
      Since:
      0.3.1
      See Also:
      • Advancement
      • AdvancementProgress
    • resetAdvancement

      public void resetAdvancement(String advancementKey, org.bukkit.entity.Player player)
      Resets the player's advancement including all criteria.
      Parameters:
      advancementKey - the namespaced key of the advancement
      player - the player who should have their advancement reset
      Since:
      0.3.1
      See Also:
      • Advancement
      • AdvancementProgress