Class Skilltree

java.lang.Object
de.Keyle.MyPet.api.skill.skilltree.Skilltree

public class Skilltree extends Object
Represents a named skilltree that defines how a pet's skills progress as it levels up.

A skilltree contains a set of Upgrade entries gated by LevelRules. When a pet reaches a new level, each rule is checked and the matching upgrades are applied to the pet's skills. Skilltrees may also inherit from another skilltree so that common progressions can be shared without duplication.

Additional metadata includes:

  • Display name / description -- shown to the player in the skilltree selection GUI
  • Icon -- the SkilltreeIcon rendered in inventory menus
  • Mob types -- which pet types can use this skilltree
  • Weight -- relative probability when randomly assigning a skilltree
  • Order -- display ordering in lists and menus
  • Requirements -- conditions (permissions, economy, etc.) the pet must satisfy
  • Max level / required level -- bounds on when this tree is available and active

Skilltrees are loaded from .st.json files by the plugin's loader and registered with the SkilltreeManager.

  • Field Details

    • skilltreeName

      protected final String skilltreeName
      This skilltree's unique name, as the file that defines it is called.
    • inheritedSkilltreeName

      protected String inheritedSkilltreeName
      Name of the skilltree this one inherits upgrades from, or null when it stands alone.
    • description

      protected final List<String> description
      Lore lines shown in the selection menu.
    • icon

      protected SkilltreeIcon icon
      Icon shown in the selection menu, or null for the default.
    • displayName

      protected String displayName
      Name shown to players, or null to use getName().
    • maxLevel

      protected int maxLevel
      Highest level this skilltree grants upgrades for; 0 means unbounded.
    • requiredLevel

      protected int requiredLevel
      Level a pet must reach before it may select this skilltree.
    • order

      protected int order
      Sort position in the selection menu; lower comes first.
    • weight

      protected double weight
      Relative chance of being picked when skilltrees are assigned at random.
    • weightOverrides

      protected final Map<PetType,Double> weightOverrides
      Per-pet-type overrides of weight.
    • mobTypes

      protected final Set<PetType> mobTypes
      Pet types allowed to use this skilltree; empty means all of them.
    • upgrades

      protected final List<Skilltree.UpgradeEntry> upgrades
      Level-gated upgrades, ordered by rule priority.
    • notifications

      protected final List<Skilltree.NotificationEntry> notifications
      Level-gated messages shown to the owner.
    • requirementSettings

      protected List<Settings> requirementSettings
      Requirement blocks gating who may select this skilltree.
  • Constructor Details

    • Skilltree

      public Skilltree(String name)
      Creates a new skilltree with the given internal name.
      Parameters:
      name - the unique identifier for this skilltree
  • Method Details

    • setWeight

      public void setWeight(double weight)
      Default weight used by random assignment when no per-type override exists.
      Parameters:
      weight - the relative chance of being picked at random
    • setWeightOverride

      public void setWeightOverride(PetType type, double weight)
      Per-type override for random-assignment weighting.
      Parameters:
      type - the pet type to override for
      weight - the relative chance for that type
    • getWeight

      public double getWeight(PetType type)
      Random-assignment weight for the given pet type.
      Parameters:
      type - the pet type to read
      Returns:
      the override for that type, or the shared weight when none is set
    • getName

      public String getName()
      Returns the unique internal name of this skilltree.
      Returns:
      this skilltree's unique name
    • getDescription

      public List<String> getDescription()
      Returns an unmodifiable view of this skilltree's description lines.
      Returns:
      the lore lines shown in the selection menu
    • addDescriptionLine

      public void addDescriptionLine(String line)
      Appends a single line to the description.
      Parameters:
      line - the lore line to append
    • addDescription

      public void addDescription(String[] lines)
      Appends multiple lines to the description.
      Parameters:
      lines - the lore lines to append
    • removeDescriptionLine

      public void removeDescriptionLine(int index)
      Removes the description line at the specified index.
      Parameters:
      index - position of the line to remove
    • clearDescription

      public void clearDescription()
      Removes all description lines.
    • getIcon

      public SkilltreeIcon getIcon()
      Returns the icon for this skilltree, creating a default one if not yet set.
      Returns:
      the menu icon, or null for the default
    • getMaxLevel

      public int getMaxLevel()
      Returns the maximum level for this skilltree.

      If not explicitly set (or set to 0), falls back to the global level cap from configuration.

      Returns:
      the highest level this skilltree grants upgrades for
    • setMaxLevel

      public void setMaxLevel(int maxLevel)
      Sets the maximum level for this skilltree, clamped to the global level cap. A value of 0 or below means "use the global cap".
      Parameters:
      maxLevel - highest level to grant upgrades for; 0 for unbounded
    • setRequiredLevel

      public void setRequiredLevel(int requiredLevel)
      Sets the minimum pet level required before this skilltree becomes available. Clamped to a minimum of 1.
      Parameters:
      requiredLevel - level a pet must reach to select this skilltree
    • getDisplayName

      public String getDisplayName()
      Returns the display name shown to players, falling back to the internal name if unset.
      Returns:
      the name shown to players
    • hasDisplayName

      public boolean hasDisplayName()
      Returns true if a custom display name has been explicitly set.
      Returns:
      true if an explicit display name is set
    • hasInheritance

      public boolean hasInheritance()
      Returns true if this skilltree inherits from another registered skilltree.
      Returns:
      true if this skilltree inherits from another
    • getUpgrades

      public List<Upgrade<?>> getUpgrades(int level)
      Collects all upgrades that should be applied at the given level, including inherited ones.

      Inherited skilltree upgrades are resolved first (depth-first), then this tree's own upgrades are appended. Circular inheritance is detected and prevented.

      Parameters:
      level - the pet's current level
      Returns:
      an ordered list of upgrades to apply
    • getUpgrades

      protected List<Upgrade<?>> getUpgrades(int level, Set<String> computedSkilltrees)
      Internal recursive method that collects upgrades while tracking already-visited trees to avoid circular inheritance loops.
      Parameters:
      level - the pet level to collect upgrades for
      computedSkilltrees - names already visited, guarding against an inheritance cycle
      Returns:
      every upgrade active at that level, inherited ones included
    • addUpgrade

      public void addUpgrade(LevelRule levelRule, Upgrade<?> upgrade)
      Registers an upgrade to be applied whenever the given level rule matches. The backing list is kept sorted by rule priority (stable) so the getters can iterate it directly.
      Parameters:
      levelRule - the rule determining at which levels this upgrade activates
      upgrade - the upgrade to apply
    • getNotifications

      public List<String> getNotifications(int level)
      Collects all notification messages that should be displayed at the given level.
      Parameters:
      level - the pet's current level
      Returns:
      the list of notification strings whose rules match this level
    • addNotification

      public void addNotification(LevelRule levelRule, String notification)
      Registers a notification message to be displayed when the given level rule matches. The backing list is kept sorted by rule priority (stable), like addUpgrade(de.Keyle.MyPet.api.skill.skilltree.levelrule.LevelRule, de.Keyle.MyPet.api.skill.Upgrade<?>).
      Parameters:
      levelRule - the rule determining at which levels the notification fires
      notification - the message to display to the pet owner
    • setMobTypes

      public void setMobTypes(Collection<PetType> mobTypes)
      Replaces the set of pet types that are allowed to use this skilltree.
      Parameters:
      mobTypes - the collection of allowed pet types
    • addRequirementSettings

      public void addRequirementSettings(Settings settings)
      Adds a requirement configuration block that will be evaluated by the named Requirement.
      Parameters:
      settings - the requirement name and its parameters
    • checkRequirements

      public boolean checkRequirements(Pet pet)
      Evaluates all configured requirements against the given pet.

      Returns true only if every requirement passes. Short-circuits on the first failure.

      Parameters:
      pet - the pet to check requirements against
      Returns:
      true if the pet satisfies all requirements for this skilltree
    • getFailedRequirements

      public List<String> getFailedRequirements(Pet pet)
      Names of the requirements the pet currently fails, in evaluation order.
      Parameters:
      pet - the pet to test
      Returns:
      names of the requirements that pet does not meet; empty when it may select this skilltree
    • isAscensionFor

      public boolean isAscensionFor(Pet pet)
      True if this tree's Skilltree requirement names the pet's current tree — i.e. selecting it is an ascension.
      Parameters:
      pet - the pet to test
      Returns:
      true if this skilltree is an ascension from the pet's current one
    • getInheritedSkilltreeName

      public String getInheritedSkilltreeName()
      Name of the skilltree this one inherits upgrades from, or null when it stands alone.
      Returns:
      the inherited skilltree's name, or null when it stands alone
    • setInheritedSkilltreeName

      public void setInheritedSkilltreeName(String inheritedSkilltreeName)
      Name of the skilltree this one inherits upgrades from, or null when it stands alone.
      Parameters:
      inheritedSkilltreeName - the inherited skilltree's name, or null
    • setIcon

      public void setIcon(SkilltreeIcon icon)
      Icon shown in the selection menu, or null for the default.
      Parameters:
      icon - the menu icon
    • setDisplayName

      public void setDisplayName(String displayName)
      Name shown to players, or null to use getName().
      Parameters:
      displayName - the name to show players
    • getRequiredLevel

      public int getRequiredLevel()
      Level a pet must reach before it may select this skilltree.
      Returns:
      the level a pet must reach before selecting this skilltree
    • setOrder

      public void setOrder(int order)
      Sort position in the selection menu; lower comes first.
      Parameters:
      order - the sort position; lower comes first
    • getOrder

      public int getOrder()
      Sort position in the selection menu; lower comes first.
      Returns:
      the sort position in the selection menu
    • getMobTypes

      public Set<PetType> getMobTypes()
      Pet types allowed to use this skilltree; empty means all of them.
      Returns:
      the pet types allowed to use this skilltree; empty means all of them
    • getRequirementSettings

      public List<Settings> getRequirementSettings()
      Requirement blocks gating who may select this skilltree.
      Returns:
      the requirement blocks gating selection