Class SelectedPetResolver

java.lang.Object
de.Keyle.MyPet.api.util.SelectedPetResolver

public final class SelectedPetResolver extends Object
Decides which of a player's active pets a command with no pet named acts on.

The player's explicit choice wins while that pet is still out. Otherwise the pet brought out most recently -- the newest lastUsed -- stands in, with a tie going to the later activation. Pure so :plugin:test can pin the rules without a server.

  • Method Details

    • resolve

      public static <T> T resolve(List<T> active, Function<T,UUID> uuid, ToLongFunction<T> lastUsed, UUID selected)
      Picks the pet to act on: the selected one while it is out, else the most recently brought out, with ties going to the later activation.
      Type Parameters:
      T - the pet representation, so tests need no live pets
      Parameters:
      active - the owner's active pets, in activation order
      uuid - how to read a pet's UUID
      lastUsed - how to read when a pet was last brought out
      selected - the UUID the owner selected, or null for none
      Returns:
      the pet to act on, or null when nothing is out