Class LeashFlagManager

java.lang.Object
de.Keyle.MyPet.api.entity.leashing.LeashFlagManager
All Implemented Interfaces:
ServiceContainer, Listener

public class LeashFlagManager extends Object implements ServiceContainer
Central registry for LeashFlag implementations. Each flag is stored under the lowercase form of its LeashFlagName annotation value.

Flags are registered at plugin startup (built-in flags) and when third-party hook plugins enable (integration flags like WorldGuard, MythicMobs). The leash-attempt logic in the plugin module queries this manager to resolve flag names from the skilltree config into live LeashFlag instances.

  • Constructor Details

    • LeashFlagManager

      public LeashFlagManager()
      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
    • registerLeashFlag

      public void registerLeashFlag(LeashFlag leashFlag)
      Registers a flag instance. The name is derived from the LeashFlagName annotation on the flag's class hierarchy.
      Parameters:
      leashFlag - the flag to register
    • flagNames

      public Set<String> flagNames()
      Returns the canonical config names of all registered flags (the original LeashFlagName casing, not the lower-cased map keys), sorted alphabetically.
      Returns:
      the registered flag names
    • getLeashFlag

      public LeashFlag getLeashFlag(String flagName)
      Looks up a registered flag by its config name (case-insensitive).
      Parameters:
      flagName - the config-facing name
      Returns:
      the flag instance, or null if no flag with that name is registered
    • getLeashFlagName

      public String getLeashFlagName(Class<?> clazz)
      Walks the class hierarchy (superclasses then interfaces) to find the LeashFlagName annotation. Returns null if no annotation is found before reaching Object.
      Parameters:
      clazz - the class to inspect
      Returns:
      the declared flag name, or null if the class declares none
    • removeFlag

      public void removeFlag(String flagName)
      Removes a flag by its config name (case-sensitive).
      Parameters:
      flagName - the name to remove
    • removeFlag

      public void removeFlag(LeashFlag flag)
      Removes a flag by deriving its name from the class annotation.
      Parameters:
      flag - the flag to remove