Class EntityCommon
java.lang.Object
net.pottercraft.ollivanders2.common.EntityCommon
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
FieldsModifier and TypeFieldDescriptionstatic 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic intdistanceToSurface(org.bukkit.entity.Entity entity) Get the distance to the water surface if an entity is underwater.@Nullable org.bukkit.entity.EntityTypeentityTypeFromString(@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 locationstatic @Nullable org.bukkit.entity.ItemgetItemAtLocation(@NotNull org.bukkit.Location location) Get the item entity at a specific locationstatic @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 locationstatic @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 locationstatic @Nullable org.bukkit.entity.ItemgetNearbyItemByMaterial(@NotNull org.bukkit.Location location, @NotNull org.bukkit.Material material, double radius) Get an item by materialstatic @Nullable org.bukkit.entity.ItemgetNearbyItemByMaterialList(@NotNull org.bukkit.Location location, @NotNull ArrayList<org.bukkit.Material> materials, double radius) Get an item by materialstatic @Nullable org.bukkit.entity.ItemgetNearbyO2ItemByType(@NotNull org.bukkit.Location location, @NotNull O2ItemType itemType, double radius) Get nearby items by O2ItemTypestatic org.bukkit.entity.Cat.TypeGenerate a random Cat type.static org.bukkit.entity.Cat.TypegetRandomCatType(int seed) Generate a random Cat type.static org.bukkit.entity.Horse.ColorGenerate a random horse color.static org.bukkit.entity.Horse.ColorgetRandomHorseColor(int seed) Generate a random horse color.static org.bukkit.entity.Horse.StyleGenerate a random horse style.static org.bukkit.entity.Horse.StylegetRandomHorseStyle(int seed) Generate a random horse style.static org.bukkit.entity.Llama.ColorGenerate random llama color.static org.bukkit.entity.Llama.ColorgetRandomLlamaColor(int seed) Generate random llama color.static @NotNull org.bukkit.DyeColorGenerate a random natural sheep colorstatic @NotNull org.bukkit.DyeColorgetRandomNaturalSheepColor(int seed) Generate a random natural sheep colorstatic org.bukkit.entity.Parrot.VariantGenerates a random parrot variant using the default world time as seed.static org.bukkit.entity.Parrot.VariantgetRandomParrotVariant(int seed) Generates a random parrot variant.static org.bukkit.entity.Rabbit.TypeGet a random rabbit type.static org.bukkit.entity.Rabbit.TypegetRandomRabbitType(int seed) Get a random rabbit type.static booleanisHostile(@NotNull org.bukkit.entity.LivingEntity livingEntity) Is this living entity a hostile? This assumes Player entities are not hostile.
-
Field Details
-
undeadEntities
Undead entities (for use with magic that targets undead) -
attackDamageCauses
Reasons an entity may get damaged which are caused by an attack (rather than falling, etc.) -
minecarts
All minecart entity types. -
boats
All boat entity types.
-
-
Constructor Details
-
EntityCommon
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 fromx- the distance +/- on the x-planey- the distance +/- on the y-planez- 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 fromradius- 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 fromradius- 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 fromradius- radius within which to get entitiesentityType- 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 boxx- the distance +/- on the x-planey- the distance +/- on the y-planez- 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 locationradius- 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 checkmaterial- the material to look forradius- 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 checkmaterials- the list of materials to look forradius- 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 checkitemType- the item type to getradius- 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:
-