Class EntityCommon

java.lang.Object
net.pottercraft.ollivanders2.common.EntityCommon

public class EntityCommon extends Object
Utility class providing static lists and methods for working with Minecraft entities.

Provides:

  • Pre-defined entity type lists (undead, minecarts, boats)
  • Methods to find entities by type, material, or location
  • Random entity attribute generators (colors, styles, types)
  • Entity classification methods (hostile detection)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final List<org.bukkit.event.entity.EntityDamageEvent.DamageCause>
    Reasons an entity may get damaged which are caused by an attack (rather than falling, etc.)
    static final List<org.bukkit.entity.EntityType>
    All boat entity types.
    static final List<org.bukkit.entity.EntityType>
    All minecart entity types.
    static final List<org.bukkit.entity.EntityType>
    Undead entities (for use with magic that targets undead)
  • Constructor Summary

    Constructors
    Constructor
    Description
    EntityCommon(@NotNull Ollivanders2 plugin)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    distanceToSurface(org.bukkit.entity.Entity entity)
    Get the distance to the water surface if an entity is underwater.
    @Nullable org.bukkit.entity.EntityType
    entityTypeFromString(@NotNull String entityTypeString)
    Get an EntityType enum from a string.
    static @NotNull Collection<org.bukkit.entity.Entity>
    getEntitiesInBounds(@NotNull org.bukkit.Location location, double x, double y, double z)
    Get all the entities with a bounding box of a specific location.
    static @NotNull Collection<org.bukkit.entity.Entity>
    getEntitiesInRadius(@NotNull org.bukkit.Location location, double radius)
    Gets all entities within a radius of a specific location
    static @Nullable org.bukkit.entity.Item
    getItemAtLocation(@NotNull org.bukkit.Location location)
    Get the item entity at a specific location
    static @NotNull List<org.bukkit.entity.Item>
    getItemsInBounds(@NotNull org.bukkit.Location location, double x, double y, double z)
    Gets item entities within a bounding box around a location.
    static @NotNull List<org.bukkit.entity.Item>
    getItemsInRadius(@NotNull org.bukkit.Location location, double radius)
    Gets item entities within a radius of a location.
    static @NotNull List<org.bukkit.entity.LivingEntity>
    getLivingEntitiesInRadius(@NotNull org.bukkit.Location location, double radius)
    Gets all living entities within a radius of a specific location
    static @NotNull List<org.bukkit.entity.Entity>
    getNearbyEntitiesByType(@NotNull org.bukkit.Location location, double radius, @NotNull org.bukkit.entity.EntityType entityType)
    Gets all of a specific entity type within a radius of a specific location
    static @Nullable org.bukkit.entity.Item
    getNearbyItemByMaterial(@NotNull org.bukkit.Location location, @NotNull org.bukkit.Material material, double radius)
    Get an item by material
    static @Nullable org.bukkit.entity.Item
    getNearbyItemByMaterialList(@NotNull org.bukkit.Location location, @NotNull ArrayList<org.bukkit.Material> materials, double radius)
    Get an item by material
    static @Nullable org.bukkit.entity.Item
    getNearbyO2ItemByType(@NotNull org.bukkit.Location location, @NotNull O2ItemType itemType, double radius)
    Get nearby items by O2ItemType
    static org.bukkit.entity.Cat.Type
    Generate a random Cat type.
    static org.bukkit.entity.Cat.Type
    getRandomCatType(int seed)
    Generate a random Cat type.
    static org.bukkit.entity.Horse.Color
    Generate a random horse color.
    static org.bukkit.entity.Horse.Color
    Generate a random horse color.
    static org.bukkit.entity.Horse.Style
    Generate a random horse style.
    static org.bukkit.entity.Horse.Style
    Generate a random horse style.
    static org.bukkit.entity.Llama.Color
    Generate random llama color.
    static org.bukkit.entity.Llama.Color
    Generate random llama color.
    static @NotNull org.bukkit.DyeColor
    Generate a random natural sheep color
    static @NotNull org.bukkit.DyeColor
    Generate a random natural sheep color
    static org.bukkit.entity.Parrot.Variant
    Generates a random parrot variant using the default world time as seed.
    static org.bukkit.entity.Parrot.Variant
    Generates a random parrot variant.
    static org.bukkit.entity.Rabbit.Type
    Get a random rabbit type.
    static org.bukkit.entity.Rabbit.Type
    Get a random rabbit type.
    static boolean
    isHostile(@NotNull org.bukkit.entity.LivingEntity livingEntity)
    Is this living entity a hostile? This assumes Player entities are not hostile.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • undeadEntities

      public static final List<org.bukkit.entity.EntityType> undeadEntities
      Undead entities (for use with magic that targets undead)
    • attackDamageCauses

      public static final List<org.bukkit.event.entity.EntityDamageEvent.DamageCause> attackDamageCauses
      Reasons an entity may get damaged which are caused by an attack (rather than falling, etc.)
    • minecarts

      public static final List<org.bukkit.entity.EntityType> minecarts
      All minecart entity types.
    • boats

      public static final List<org.bukkit.entity.EntityType> boats
      All boat entity types.
  • Constructor Details

    • EntityCommon

      public EntityCommon(@NotNull @NotNull Ollivanders2 plugin)
      Constructor
      Parameters:
      plugin - a reference to the plugin using this common
  • Method Details

    • entityTypeFromString

      @Nullable public @Nullable org.bukkit.entity.EntityType entityTypeFromString(@NotNull @NotNull String entityTypeString)
      Get an EntityType enum from a string.
      Parameters:
      entityTypeString - the entity type as a string
      Returns:
      the EntityType or null if an exception occurred
    • getEntitiesInBounds

      @NotNull public static @NotNull Collection<org.bukkit.entity.Entity> getEntitiesInBounds(@NotNull @NotNull org.bukkit.Location location, double x, double y, double z)
      Get all the entities with a bounding box of a specific location.
      Parameters:
      location - the location to check from
      x - the distance +/- on the x-plane
      y - the distance +/- on the y-plane
      z - the distance +/- on the z-plane
      Returns:
      a Collection of all entities within the bounding box.
    • getEntitiesInRadius

      @NotNull public static @NotNull Collection<org.bukkit.entity.Entity> getEntitiesInRadius(@NotNull @NotNull org.bukkit.Location location, double radius)
      Gets all entities within a radius of a specific location
      Parameters:
      location - the location to search for entities from
      radius - radius within which to get entities
      Returns:
      List of entities within the radius
    • getLivingEntitiesInRadius

      @NotNull public static @NotNull List<org.bukkit.entity.LivingEntity> getLivingEntitiesInRadius(@NotNull @NotNull org.bukkit.Location location, double radius)
      Gets all living entities within a radius of a specific location
      Parameters:
      location - the location to search for entities from
      radius - radius within which to get entities
      Returns:
      List of living entities within the radius
    • getNearbyEntitiesByType

      @NotNull public static @NotNull List<org.bukkit.entity.Entity> getNearbyEntitiesByType(@NotNull @NotNull org.bukkit.Location location, double radius, @NotNull @NotNull org.bukkit.entity.EntityType entityType)
      Gets all of a specific entity type within a radius of a specific location
      Parameters:
      location - the location to search for entities from
      radius - radius within which to get entities
      entityType - the type of entity to look for
      Returns:
      List of entities of the specified type within the radius
    • getItemAtLocation

      @Nullable public static @Nullable org.bukkit.entity.Item getItemAtLocation(@NotNull @NotNull org.bukkit.Location location)
      Get the item entity at a specific location
      Parameters:
      location - the location to get the item from
      Returns:
      the Item entity or null if none present at the location
    • getItemsInBounds

      @NotNull public static @NotNull List<org.bukkit.entity.Item> getItemsInBounds(@NotNull @NotNull org.bukkit.Location location, double x, double y, double z)
      Gets item entities within a bounding box around a location.
      Parameters:
      location - the center location for the bounding box
      x - the distance +/- on the x-plane
      y - the distance +/- on the y-plane
      z - the distance +/- on the z-plane
      Returns:
      list of item entities within the bounding box
    • getItemsInRadius

      @NotNull public static @NotNull List<org.bukkit.entity.Item> getItemsInRadius(@NotNull @NotNull org.bukkit.Location location, double radius)
      Gets item entities within a radius of a location.
      Parameters:
      location - the center location
      radius - the radius to search within
      Returns:
      list of item entities within the radius
    • getNearbyItemByMaterial

      @Nullable public static @Nullable org.bukkit.entity.Item getNearbyItemByMaterial(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull org.bukkit.Material material, double radius)
      Get an item by material
      Parameters:
      location - the location to check
      material - the material to look for
      radius - the radius to look in
      Returns:
      an item if found, null otherwise
    • getNearbyItemByMaterialList

      @Nullable public static @Nullable org.bukkit.entity.Item getNearbyItemByMaterialList(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull ArrayList<org.bukkit.Material> materials, double radius)
      Get an item by material
      Parameters:
      location - the location to check
      materials - the list of materials to look for
      radius - the radius to look in
      Returns:
      an item if found, null otherwise
    • getNearbyO2ItemByType

      @Nullable public static @Nullable org.bukkit.entity.Item getNearbyO2ItemByType(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull O2ItemType itemType, double radius)
      Get nearby items by O2ItemType
      Parameters:
      location - the location to check
      itemType - the item type to get
      radius - the radius to look in
      Returns:
      the item if found, null otherwise
    • getRandomCatType

      @NotNull public static org.bukkit.entity.Cat.Type getRandomCatType(int seed)
      Generate a random Cat type.
      Parameters:
      seed - the base value that the percentile check will use
      Returns:
      the Cat type
    • getRandomCatType

      @NotNull public static org.bukkit.entity.Cat.Type getRandomCatType()
      Generate a random Cat type.
      Returns:
      the Cat type
    • getRandomRabbitType

      @NotNull public static org.bukkit.entity.Rabbit.Type getRandomRabbitType(int seed)
      Get a random rabbit type. Odds are 1/60 to get a Killer Bunny.
      Parameters:
      seed - the base value that the percentile check will use
      Returns:
      the type color for the rabbit
    • getRandomRabbitType

      @NotNull public static org.bukkit.entity.Rabbit.Type getRandomRabbitType()
      Get a random rabbit type. Odds are 1/60 to get a Killer Bunny.
      Returns:
      the type color for the rabbit
    • getRandomHorseStyle

      @NotNull public static org.bukkit.entity.Horse.Style getRandomHorseStyle(int seed)
      Generate a random horse style.
      Parameters:
      seed - the base value that the percentile check will use
      Returns:
      the horse style
    • getRandomHorseStyle

      @NotNull public static org.bukkit.entity.Horse.Style getRandomHorseStyle()
      Generate a random horse style.
      Returns:
      the horse style
    • getRandomHorseColor

      @NotNull public static org.bukkit.entity.Horse.Color getRandomHorseColor(int seed)
      Generate a random horse color.
      Parameters:
      seed - the base value that the percentile check will use
      Returns:
      the color
    • getRandomHorseColor

      @NotNull public static org.bukkit.entity.Horse.Color getRandomHorseColor()
      Generate a random horse color.
      Returns:
      the color
    • getRandomLlamaColor

      @NotNull public static org.bukkit.entity.Llama.Color getRandomLlamaColor(int seed)
      Generate random llama color.
      Parameters:
      seed - the base value that the percentile check will use
      Returns:
      the color
    • getRandomLlamaColor

      @NotNull public static org.bukkit.entity.Llama.Color getRandomLlamaColor()
      Generate random llama color.
      Returns:
      the color
    • getRandomParrotVariant

      @NotNull public static org.bukkit.entity.Parrot.Variant getRandomParrotVariant(int seed)
      Generates a random parrot variant.
      Parameters:
      seed - the base value used with random number generation for variant selection
      Returns:
      a random parrot variant
    • getRandomParrotVariant

      @NotNull public static org.bukkit.entity.Parrot.Variant getRandomParrotVariant()
      Generates a random parrot variant using the default world time as seed.
      Returns:
      a random parrot variant
    • getRandomNaturalSheepColor

      @NotNull public static @NotNull org.bukkit.DyeColor getRandomNaturalSheepColor(int seed)
      Generate a random natural sheep color
      Parameters:
      seed - the base value that the percentile check will use
      Returns:
      the color
    • getRandomNaturalSheepColor

      @NotNull public static @NotNull org.bukkit.DyeColor getRandomNaturalSheepColor()
      Generate a random natural sheep color
      Returns:
      the color
    • isHostile

      public static boolean isHostile(@NotNull @NotNull org.bukkit.entity.LivingEntity livingEntity)
      Is this living entity a hostile? This assumes Player entities are not hostile.
      Parameters:
      livingEntity - the entity to check
      Returns:
      true if it is a hostile or angry mob, false otherwise
      See Also:
    • distanceToSurface

      public static int distanceToSurface(org.bukkit.entity.Entity entity)
      Get the distance to the water surface if an entity is underwater.
      Parameters:
      entity - the player to measure
      Returns:
      the distance from the player to the surface of the water, to a max of 100 blocks
      See Also: