Class SkilltreeManager

java.lang.Object
de.Keyle.MyPet.api.skill.skilltree.SkilltreeManager
All Implemented Interfaces:
ServiceContainer, Listener

public class SkilltreeManager extends Object implements ServiceContainer
Central service for managing all registered Skilltrees and Requirements.

Skilltrees are loaded from .st.json files during plugin startup and registered here by name. The manager provides lookup, ordering, weighted random selection, and requirement evaluation for the pet skilltree selection UI.

Requirements are registered by their RequirementName annotation and evaluated at runtime to determine if a pet qualifies for a given skilltree.

Loaded during Load.State.OnLoad so that skilltrees are available before pet data is restored from the repository.

  • Constructor Details

    • SkilltreeManager

      public SkilltreeManager()
      Creates an empty manager. MyPet registers one as a service; addons use that instance.
  • Method Details

    • onDisable

      public void onDisable()
      Description copied from interface: ServiceContainer
      Disables the service
      Specified by:
      onDisable in interface ServiceContainer
    • registerSkilltree

      public void registerSkilltree(Skilltree skilltree)
      Registers a skilltree, keyed by its name. Overwrites any existing tree with the same name.
      Parameters:
      skilltree - the skilltree to register
    • getSkilltree

      public Skilltree getSkilltree(String name)
      Returns the skilltree with the given name, or null if none is registered.
      Parameters:
      name - the skilltree's name
      Returns:
      the registered skilltree, or null if none has that name
    • getSkilltreeNames

      public Set<String> getSkilltreeNames()
      Returns the set of all registered skilltree names.
      Returns:
      the names of every registered skilltree
    • getOrderedSkilltreeNames

      public List<String> getOrderedSkilltreeNames()
      Returns skilltree names sorted by their Skilltree.getOrder() value.
      Returns:
      the names, in menu order
    • getSkilltrees

      public Collection<Skilltree> getSkilltrees()
      Returns all registered skilltree instances (unordered).
      Returns:
      every registered skilltree
    • getOrderedSkilltrees

      public List<Skilltree> getOrderedSkilltrees()
      Returns all registered skilltrees sorted by their Skilltree.getOrder() value.
      Returns:
      every registered skilltree, in menu order
    • getRandomSkilltree

      public Skilltree getRandomSkilltree(Pet pet)
      Selects a random skilltree for the given pet using weighted probability.

      Only skilltrees that match the pet's type, pass all requirements, and have a positive weight are candidates. The selection uses a cumulative-weight random algorithm so that trees with higher weights are proportionally more likely.

      Parameters:
      pet - the pet to select a skilltree for
      Returns:
      a randomly selected skilltree, or null if no candidates qualify
    • hasSkilltree

      public boolean hasSkilltree(String name)
      Returns true if a skilltree with the given name is registered.
      Parameters:
      name - the name to look for
      Returns:
      true if a skilltree with that name is registered
    • clearSkilltrees

      public void clearSkilltrees()
      Removes all registered skilltrees. Typically called during reload or shutdown.
    • registerRequirement

      public void registerRequirement(Requirement Requirement)
      Registers a requirement implementation, keyed by the name from its RequirementName annotation (case-insensitive).
      Parameters:
      Requirement - the requirement instance to register
    • getRequirement

      public Requirement getRequirement(String requirementName)
      Looks up a requirement by name (case-insensitive).
      Parameters:
      requirementName - the requirement name to look up
      Returns:
      the requirement instance, or null if not registered
    • getRequirementName

      public String getRequirementName(Class<?> clazz)
      Resolves the requirement name for a class by searching its type hierarchy for a RequirementName annotation.

      Searches the class itself, then its superclass chain, then all implemented interfaces recursively.

      Parameters:
      clazz - the class to inspect
      Returns:
      the annotated requirement name, or null if not found
    • removeRequirement

      public void removeRequirement(String requirementName)
      Unregisters a requirement by name.
      Parameters:
      requirementName - the requirement to unregister
    • removeRequirement

      public void removeRequirement(Requirement requirement)
      Unregisters a requirement by resolving the name from its class annotation.
      Parameters:
      requirement - the requirement to unregister