Package de.Keyle.MyPet.api.entity
Class PetType
java.lang.Object
de.Keyle.MyPet.api.entity.PetType
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 Summary
Modifier and TypeMethodDescriptionbooleanWhether per-type logic registered undertypeNameapplies to this type: its own name, or the name of itshost type.all()Returns a mutable copy of all registered types in insertion order.static PetTypebyEntityTypeName(String name) Looks up a type by its BukkitEntityTypeenum name (UPPER_SNAKE_CASE, case-insensitive).static PetTypebyEntityTypeNameOrNull(String name) Looks up a type by its Bukkit entity name, returningnullinstead of throwing if the type is not registered.static PetTypeLooks up a type by its CamelCase name (case-insensitive).static PetTypebyNameOrNull(String name) Looks up a type by name, returningnullinstead of throwing if the type is not registered.booleanReturnstrueif the current Minecraft version supports this pet type.booleanbooleanWhether this pet type should float on lava (Strider).Returns the Bukkit entity class used to spawn this pet's host mob.The BukkitEntityTypename this pet type maps to.static PetTypeReturns 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.The explicit Host class this type was registered with, ornullwhen it spawns the entity its own name maps to.The registered type that spawns this type's Host mob, ornullwhen this type has no explicit Host (or the Host resolves to this type itself).Returns the pet implementation class for this type.Lowercase type ID used for persistence keys (e.g.inthashCode()booleanType-level capability check: does this pet type's interface declarePetFlyingEntity? The per-petCanFlypreference is checked separately at the pet *instance* level (seePetFlyingEntity.canFly()) — callers that need the combined capability and preference answer should use the instance check directly.booleanType-level check: does this type implementPetSwimmingEntity?name()CamelCase display name (e.g.static PetTypeRegisters a custom pet type.static PetTypeRegisters a custom pet type with an explicit host mob class.booleanWhether this type needs custom float logic beyond standard swim.static voidunregister(String name) Removes a previously registered pet type.static PetTypeLooks up a type by its CamelCase name (case-insensitive).static Collection<PetType> values()Returns an unmodifiable snapshot of all registered types in registration order.
-
Method Details
-
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
The explicit Host class this type was registered with, ornullwhen it spawns the entity its own name maps to. Non-null only for custom (data-driven) types.- Returns:
- the explicit host class, or
nullwhen the name maps to it
-
getHostType
The registered type that spawns this type's Host mob, ornullwhen this type has no explicit Host (or the Host resolves to this type itself). A custom type hosted onEnderDragonreturns the built-inEnderDragontype, 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
Whether per-type logic registered undertypeNameapplies to this type: its own name, or the name of itshost type.- Parameters:
typeName- the pet type name a behaviour or hook was registered under- Returns:
trueif that registration covers this type
-
register
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 BukkitEntityType, sogetBukkitEntityClass()can return a spawnable class instead ofnull.- Parameters:
name- CamelCase name (e.g. "FrostDragon")petClass- interface extending PethostClass- the vanillaMobsubclass to spawn as the host entity- Returns:
- the registered PetType
- Throws:
IllegalArgumentException- if a type with this name is already registered
-
unregister
Removes a previously registered pet type. Third-party plugins should call this from theironDisableto release theClass<? 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
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
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
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
Looks up a type by its BukkitEntityTypeenum 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
Looks up a type by its Bukkit entity name, returningnullinstead of throwing if the type is not registered.- Parameters:
name- the name to look up- Returns:
- the matching type, or
nullif none is registered
-
byName
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
Looks up a type by name, returningnullinstead of throwing if the type is not registered.- Parameters:
name- the name to look up- Returns:
- the matching type, or
nullif none is registered
-
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.PersistedPetbuilder initial state,ShopPetfield 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
CamelCase display name (e.g."ZombieVillager").- Returns:
- the CamelCase display name
-
getTypeID
Lowercase type ID used for persistence keys (e.g."zombie_villager").- Returns:
- the lower-case id used in persistence keys
-
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 declarePetFlyingEntity? The per-petCanFlypreference is checked separately at the pet *instance* level (seePetFlyingEntity.canFly()) — callers that need the combined capability and preference answer should use the instance check directly.- Returns:
trueif this type's pet class declaresPetFlyingEntity
-
isSwimmingPet
public boolean isSwimmingPet()Type-level check: does this type implementPetSwimmingEntity?- Returns:
trueif this type's pet class declaresPetSwimmingEntity
-
floatsInLava
public boolean floatsInLava()Whether this pet type should float on lava (Strider).- Returns:
trueif this type floats on lava
-
specialFloat
public boolean specialFloat()Whether this type needs custom float logic beyond standard swim.- Returns:
trueif this type needs float handling beyond ordinary swimming
-
checkMinecraftVersion
public boolean checkMinecraftVersion()Returnstrueif the current Minecraft version supports this pet type. Overridden for types added in later MC versions.- Returns:
trueif the running Minecraft version supports this type
-
equals
-
hashCode
public int hashCode() -
getBukkitName
The BukkitEntityTypename this pet type maps to.- Returns:
- the UPPER_SNAKE_CASE entity type name
-