Package valorless.rarespawns.builders
Class EntityCreator
java.lang.Object
valorless.rarespawns.builders.EntityCreator
EntityCreator is responsible for creating, updating, and managing custom entities in the RareSpawns plugin.
It loads entity configurations, applies custom properties, handles entity updates, boss bars, nameplates,
inventory, attributes, and more. It also provides utility methods for entity selection, spawning, and conversion.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic List<org.bukkit.entity.LivingEntity> List of all living rare entities currently managed by the plugin.static List<RareEntityNameplate> List of all custom nameplates for rare entities.protected static BooleanIndicates whether the entity data has been fully loaded and is ready for use. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddEntity(String id, EntityData entity) Adds a new entity to the collection with the provided ID.static voidcreateNameplate(org.bukkit.entity.LivingEntity entity, EntityData data) Creates a custom nameplate for a rare entity if it doesn't already exist.static List<org.bukkit.inventory.ItemStack> generateDropTable(EntityData data) Builds the drop table for an entity from a list of item strings.static HashMap<String, EntityData> Returns a clone of the entities map containing all custom entity data.static List<EntityData> getEntitiesByGroup(String group) Retrieves all entities that belong to the specified spawn group id.static List<EntityData> getEntitiesByGroup(SpawnGroup group) Retrieves all entities that belong to the specified spawn group.static EntityDataRetrieves entity data by its unique ID.static SpawnGroupgetSpawnGroup(String group) Finds a spawn group by its identifier (case-insensitive).static List<SpawnGroup> Gets all configured spawn groups currently loaded.static org.bukkit.entity.Wolf.VariantgetWolfVariant(String variantName) static booleanisPotentiallyHostile(org.bukkit.entity.LivingEntity mob) Checks if a mob is potentially hostile (used for AI and targeting logic).static BooleanisReady()Returns whether the entity data is fully loaded and ready for use.Retrieves the names of all files (excluding their extensions) in the 'entities' folder of the plugin's data directory.static org.bukkit.inventory.ItemStackparseDropItem(String itemString) Parses a drop-table item definition into anItemStack, applying an optional drop chance.static org.bukkit.inventory.ItemStackParses an item definition string into anItemStackfor equipment or inventories.static StringPicks a random rare entity ID based on weighted probabilities.static StringPicks a random rare entity ID within the specified spawn group using weighted selection.static voidreload()Reloads spawn groups and entity definitions from configuration and disk.static voidsetEntityAsBaby(org.bukkit.entity.Entity entity, Boolean baby) Sets an entity as a baby or adult if supported.static voidsetEntityAttribute(org.bukkit.entity.LivingEntity entity, org.bukkit.attribute.Attribute attribute, double value) Sets an attribute value for a living entity.static voidsetInventory(org.bukkit.entity.LivingEntity entity, InventoryData inv) Sets the inventory for a living entity using InventoryData.static org.bukkit.LocationspawnAboveGround(org.bukkit.entity.LivingEntity entity, EntityData data) Spawns an entity at a safe above-ground location, and teleports passengers if present.static org.bukkit.entity.LivingEntitySpawns a configured rare entity by its unique ID at the given location and initializes it.static voidupdateEntity(org.bukkit.entity.LivingEntity entity, String id, boolean New) Updates a living entity with the properties from its EntityData, by ID.static voidupdateEntity(org.bukkit.entity.LivingEntity entity, EntityData data, boolean New) Updates a living entity with the properties from its EntityData.
-
Field Details
-
ready
Indicates whether the entity data has been fully loaded and is ready for use. Set to true once all entity data is loaded from configuration files. -
allEntities
List of all living rare entities currently managed by the plugin. -
nameplates
List of all custom nameplates for rare entities.
-
-
Constructor Details
-
EntityCreator
public EntityCreator()
-
-
Method Details
-
isReady
Returns whether the entity data is fully loaded and ready for use.- Returns:
- true if entity data is ready; false otherwise
-
getEntities
Returns a clone of the entities map containing all custom entity data.- Returns:
- A cloned HashMap of entity IDs to EntityData.
-
getEntitiesByGroup
Retrieves all entities that belong to the specified spawn group id. Matching is case-insensitive.- Parameters:
group- the spawn group identifier- Returns:
- list of EntityData in the group (empty if none)
-
getEntitiesByGroup
Retrieves all entities that belong to the specified spawn group.- Parameters:
group- the SpawnGroup to match against- Returns:
- list of EntityData in the group (empty if none)
-
getSpawnGroups
Gets all configured spawn groups currently loaded. Returns the live backing list; do not modify.- Returns:
- list of SpawnGroup entries
-
getSpawnGroup
Finds a spawn group by its identifier (case-insensitive).- Parameters:
group- the group identifier- Returns:
- the matching SpawnGroup, or null if not found
-
getEntity
Retrieves entity data by its unique ID.- Parameters:
id- The unique ID of the entity.- Returns:
- The EntityData associated with the ID, or null if not found.
-
addEntity
Adds a new entity to the collection with the provided ID. Validates the ID and entity before adding.- Parameters:
id- The unique ID of the entity to be added.entity- The EntityData that represents the entity.- Returns:
- True if the entity was successfully added; false if the ID already exists or if an error occurs.
- Throws:
Exception- If the ID is null or empty.
-
reload
public static void reload()Reloads spawn groups and entity definitions from configuration and disk.This method:
- Rebuilds the in-memory list of
SpawnGroupentries from the main config (keys:spawn-chanceandspawn-groups), inserting a default group when missing. - Loads all YAML files under the plugin data folder
entities/and creates newEntityDataentries or updates existing ones viaprepareData(Config, String). - Logs errors per invalid entry, as well as total entities processed and elapsed time.
Side effects:
- Mutates static collections:
spawnGroupsandentities. - Emits log messages for progress and issues.
- Rebuilds the in-memory list of
-
updateEntity
Updates a living entity with the properties from its EntityData, by ID.- Parameters:
entity- The entity to update.id- The unique ID of the entity.New- Whether the entity is newly spawned.
-
updateEntity
public static void updateEntity(org.bukkit.entity.LivingEntity entity, EntityData data, boolean New) Updates a living entity with the properties from its EntityData.- Parameters:
entity- The entity to update.data- The EntityData containing all properties.New- Whether the entity is newly spawned.
-
isPotentiallyHostile
public static boolean isPotentiallyHostile(org.bukkit.entity.LivingEntity mob) Checks if a mob is potentially hostile (used for AI and targeting logic).- Parameters:
mob- The living entity to check.- Returns:
- True if the mob is considered hostile, false otherwise.
-
createNameplate
Creates a custom nameplate for a rare entity if it doesn't already exist.- Parameters:
entity- The entity to attach the nameplate to.data- The EntityData for the entity.
-
generateDropTable
Builds the drop table for an entity from a list of item strings. Supports randomization and chance.- Parameters:
items- List of item strings in format "item:amount[:chance]".- Returns:
- List of ItemStack objects representing the drop table.
-
setInventory
Sets the inventory for a living entity using InventoryData.- Parameters:
entity- The entity to set inventory for.inv- The InventoryData object containing item slots.
-
setEntityAttribute
public static void setEntityAttribute(org.bukkit.entity.LivingEntity entity, org.bukkit.attribute.Attribute attribute, double value) Sets an attribute value for a living entity.- Parameters:
entity- The entity to set the attribute for.attribute- The Attribute to set.value- The value to set.
-
pickRandomRareEntity
Picks a random rare entity ID based on weighted probabilities. Only entities with positive weight are considered.- Returns:
- The selected entity ID, or null if none found.
-
pickRandomRareEntityByGroup
Picks a random rare entity ID within the specified spawn group using weighted selection. Only entities with positive weight are considered.- Parameters:
group- the SpawnGroup to filter candidates by- Returns:
- the selected entity ID, or null if none are eligible
-
setEntityAsBaby
Sets an entity as a baby or adult if supported.- Parameters:
entity- The entity to modify.baby- True to set as baby, false for adult.
-
spawnAboveGround
public static org.bukkit.Location spawnAboveGround(org.bukkit.entity.LivingEntity entity, EntityData data) Spawns an entity at a safe above-ground location, and teleports passengers if present.- Parameters:
entity- The entity to spawn.data- The EntityData for the entity.- Returns:
- True if the entity was successfully spawned, false otherwise.
-
getWolfVariant
-
listEntities
Retrieves the names of all files (excluding their extensions) in the 'entities' folder of the plugin's data directory.- Returns:
- A List of file names without extensions.
-
spawnRare
Spawns a configured rare entity by its unique ID at the given location and initializes it.This will:
- Create the entity using its configured
EntityType. - Apply all properties via
updateEntity(LivingEntity, EntityData, boolean)withNew=true. - Cache the spawned entity and fire a
RareSpawnEvent.
- Parameters:
id- the unique rare ID as defined in entities/configslocation- the world location to spawn at- Returns:
- the spawned LivingEntity, or null if the ID is invalid
- Create the entity using its configured
-
parseItem
Parses an item definition string into anItemStackfor equipment or inventories.Format:
id:amountid:min-max— the amount is chosen randomly in the inclusive range
nexo:, the item is built via NexoItems; otherwise it tries BukkitMaterialfirst, then falls back to custom item builders.- Parameters:
itemString- the item descriptor stringrandomize- when true, uses ItemBuilder (randomized) for custom IDs; otherwise uses ItemCreator- Returns:
- the resulting ItemStack;
Material.AIRif parsing fails
-
parseDropItem
Parses a drop-table item definition into anItemStack, applying an optional drop chance.Format:
id:amountid:min-max— amount is randomized in the inclusive rangeid:amount:chance— the item is returned only if the chance check passesid:min-max:chance— the item is returned only if the chance check passes
nullwhen the roll fails.- Parameters:
itemString- the drop-table descriptor string- Returns:
- the built ItemStack to drop, or
nullif the chance roll fails
-