Class PetType

java.lang.Object
de.Keyle.MyPet.api.entity.PetType

public final class PetType extends Object
Registry of all available pet types. Built-in types are populated by MyPetPlugin.onLoad via BuiltInPetTypes.register() (plugin module); third-party plugins register custom types via register(String, Class).

Each impl class carries its own @ShopInfo / @DefaultInfo annotations and implements the relevant marker interfaces (PetBaby, PetFlyingEntity, etc.) directly.

The registry is thread-safe. Registration and removal are serialised and can happen at any time (addons, /mypet reload) while region threads look types up on every spawn and tick. Lookups are lock-free, and all() and values() return a snapshot in registration order, so iterating while a type is registered or removed never throws a ConcurrentModificationException.

  • Method Details

    • getBukkitEntityClass

      public Class<? extends Mob> getBukkitEntityClass()
      Returns the Bukkit entity class used to spawn this pet's host mob.
      Returns:
      the Bukkit class this pet's host mob is spawned as
    • getHostOverride

      public Class<? extends Mob> getHostOverride()
      The explicit Host class this type was registered with, or null when it spawns the entity its own name maps to. Non-null only for custom (data-driven) types.
      Returns:
      the explicit host class, or null when the name maps to it
    • getHostType

      public PetType getHostType()
      The registered type that spawns this type's Host mob, or null when this type has no explicit Host (or the Host resolves to this type itself). A custom type hosted on EnderDragon returns the built-in EnderDragon type, whose per-type behaviours, lifecycle hooks and goal retentions the host mob needs regardless of the custom type's name.
      Returns:
      the host's registered type, or null
    • actsAs

      public boolean actsAs(String typeName)
      Whether per-type logic registered under typeName applies to this type: its own name, or the name of its host type.
      Parameters:
      typeName - the pet type name a behaviour or hook was registered under
      Returns:
      true if that registration covers this type
    • register

      public static PetType register(String name, Class<? extends Pet> petClass)
      Registers a custom pet type. Use this for third-party or ModelEngine-backed entities.
      Parameters:
      name - CamelCase name (e.g. "MyCustomMob")
      petClass - interface extending Pet
      Returns:
      the registered PetType
      Throws:
      IllegalArgumentException - if a type with this name is already registered
    • register

      public static PetType register(String name, Class<? extends Pet> petClass, Class<? extends Mob> hostClass)
      Registers a custom pet type with an explicit host mob class. Use this for data-driven pet types whose name does not match a vanilla Bukkit EntityType, so getBukkitEntityClass() can return a spawnable class instead of null.
      Parameters:
      name - CamelCase name (e.g. "FrostDragon")
      petClass - interface extending Pet
      hostClass - the vanilla Mob subclass to spawn as the host entity
      Returns:
      the registered PetType
      Throws:
      IllegalArgumentException - if a type with this name is already registered
    • unregister

      public static void unregister(String name)
      Removes a previously registered pet type. Third-party plugins should call this from their onDisable to release the Class<? extends Pet> reference and avoid leaking their plugin classloader across reloads. No-op if the name is unknown.
      Parameters:
      name - the CamelCase name of the type to remove
    • all

      public static List<PetType> all()
      Returns a mutable copy of all registered types in insertion order. The copy is a snapshot: later registrations do not appear in it.
      Returns:
      a mutable copy of every registered type, in insertion order
    • values

      public static Collection<PetType> values()
      Returns an unmodifiable snapshot of all registered types in registration order. Types registered or removed after the call are not reflected, and iterating the result is safe while other threads register or unregister types.
      Returns:
      an unmodifiable snapshot of every registered type, in registration order
    • valueOf

      public static PetType valueOf(String name)
      Looks up a type by its CamelCase name (case-insensitive).
      Parameters:
      name - the name to look up
      Returns:
      the matching type
      Throws:
      PetTypeNotFoundException - if no type is registered
    • byEntityTypeName

      public static PetType byEntityTypeName(String name)
      Looks up a type by its Bukkit EntityType enum name (UPPER_SNAKE_CASE, case-insensitive).
      Parameters:
      name - the name to look up
      Returns:
      the matching type
      Throws:
      PetTypeNotFoundException - if no type is registered
    • byEntityTypeNameOrNull

      public static PetType byEntityTypeNameOrNull(String name)
      Looks up a type by its Bukkit entity name, returning null instead of throwing if the type is not registered.
      Parameters:
      name - the name to look up
      Returns:
      the matching type, or null if none is registered
    • byName

      public static PetType byName(String name)
      Looks up a type by its CamelCase name (case-insensitive).
      Parameters:
      name - the name to look up
      Returns:
      the matching type
      Throws:
      PetTypeNotFoundException - if no type is registered
    • byNameOrNull

      public static PetType byNameOrNull(String name)
      Looks up a type by name, returning null instead of throwing if the type is not registered.
      Parameters:
      name - the name to look up
      Returns:
      the matching type, or null if none is registered
    • getDefault

      public static PetType getDefault()
      Returns the first registered pet type in insertion order — used as a deterministic fallback when callers need a non-null default and have no better choice (e.g. PersistedPet builder initial state, ShopPet field default). Whatever pet ends up first in registration order serves as the default; no specific species is privileged.
      Returns:
      the first registered type
      Throws:
      PetTypeNotFoundException - if no pet types are registered
    • name

      public String name()
      CamelCase display name (e.g. "ZombieVillager").
      Returns:
      the CamelCase display name
    • getTypeID

      public String getTypeID()
      Lowercase type ID used for persistence keys (e.g. "zombie_villager").
      Returns:
      the lower-case id used in persistence keys
    • getPetClass

      public Class<? extends Pet> getPetClass()
      Returns the pet implementation class for this type.
      Returns:
      the pet implementation class for this type
    • isFlyingPet

      public boolean isFlyingPet()
      Type-level capability check: does this pet type's interface declare PetFlyingEntity? The per-pet CanFly preference is checked separately at the pet *instance* level (see PetFlyingEntity.canFly()) — callers that need the combined capability and preference answer should use the instance check directly.
      Returns:
      true if this type's pet class declares PetFlyingEntity
    • isSwimmingPet

      public boolean isSwimmingPet()
      Type-level check: does this type implement PetSwimmingEntity?
      Returns:
      true if this type's pet class declares PetSwimmingEntity
    • floatsInLava

      public boolean floatsInLava()
      Whether this pet type should float on lava (Strider).
      Returns:
      true if this type floats on lava
    • specialFloat

      public boolean specialFloat()
      Whether this type needs custom float logic beyond standard swim.
      Returns:
      true if this type needs float handling beyond ordinary swimming
    • checkMinecraftVersion

      public boolean checkMinecraftVersion()
      Returns true if the current Minecraft version supports this pet type. Overridden for types added in later MC versions.
      Returns:
      true if the running Minecraft version supports this type
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getBukkitName

      public String getBukkitName()
      The Bukkit EntityType name this pet type maps to.
      Returns:
      the UPPER_SNAKE_CASE entity type name