Class EntityBuilder

java.lang.Object
de.eldoria.eldoutilities.entities.EntityBuilder

public final class EntityBuilder extends Object
A class to build entities with a builder pattern.
Since:
1.1.0
  • Method Details

    • of

      public static EntityBuilder of(LivingEntity entity)
      Returns a new EntityBuilder with an entity at the requested position.
      Parameters:
      entity - entity to wrap
      Returns:
      new EntityBuilder instance with entity
    • of

      public static EntityBuilder of(EntityType entity, Location location)
      Returns a new EntityBuilder with an entity at the requested position.
      Parameters:
      entity - entity type to spawn
      location - location to spawn
      Returns:
      new EntityBuilder instance with spawned entity
    • withPassenger

      public EntityBuilder withPassenger(@NotNull @NotNull Entity... passengers)
      Add a passenger to the vehicle.
      Parameters:
      passengers - One or more passengers to add
      Returns:
      builder instance
      Since:
      1.1.0
    • withScoreboardTag

      public EntityBuilder withScoreboardTag(@NotNull @NotNull String tag)
      Add a tag to this entity.
      Entities can have no more than 1024 tags.
      Parameters:
      tag - the tag to add
      Returns:
      builder instance
      Since:
      1.1.0
    • withVelocity

      public EntityBuilder withVelocity(@NotNull @NotNull Vector velocity)
      Sets this entity's velocity
      Parameters:
      velocity - New velocity to travel with
      Returns:
      builder instance
      Since:
      1.1.0
    • withRotation

      public EntityBuilder withRotation(float yaw, float pitch)
      Sets the entity's rotation.

      Note that if the entity is affected by AI, it may override this rotation.

      Parameters:
      yaw - the yaw
      pitch - the pitch
      Returns:
      builder instance
      Throws:
      UnsupportedOperationException - if used for players
      Since:
      1.1.0
    • withFireTicks

      public EntityBuilder withFireTicks(int ticks)
      Sets the entity's current fire ticks (ticks before the entity stops being on fire).
      Parameters:
      ticks - Current ticks remaining
      Returns:
      builder instance
    • asPersistent

      public EntityBuilder asPersistent(boolean persistent)
      Sets whether or not the entity gets persisted.
      Parameters:
      persistent - the persistence status
      Returns:
      builder instance
      See Also:
    • withFallDistance

      public EntityBuilder withFallDistance(float distance)
      Sets the fall distance for this entity
      Parameters:
      distance - The new distance.
      Returns:
      builder instance
    • withTicksLived

      public EntityBuilder withTicksLived(int value)
      Sets the amount of ticks this entity has lived for.

      This is the equivalent to "age" in entities. May not be less than one tick.

      Parameters:
      value - Age of entity
      Returns:
      builder instance
    • withVisibleCustomName

      public EntityBuilder withVisibleCustomName(boolean flag)
      Sets whether or not to display the mob's custom name client side. The name will be displayed above the mob similarly to a player.

      This value has no effect on players, they will always display their name.

      Parameters:
      flag - custom name or not
      Returns:
      builder instance
    • withGlowing

      public EntityBuilder withGlowing(boolean flag)
      Sets whether the entity has a team colored (default: white) glow. nb: this refers to the 'Glowing' entity property, not whether a glowing potion effect is applied
      Parameters:
      flag - if the entity is glowing
      Returns:
      builder instance
    • asInvulnerable

      public EntityBuilder asInvulnerable(boolean flag)
      Sets whether the entity is invulnerable or not.

      When an entity is invulnerable it can only be damaged by players in creative mode.

      Parameters:
      flag - if the entity is invulnerable
      Returns:
      builder instance
    • asSilent

      public EntityBuilder asSilent(boolean flag)
      Sets whether the entity is silent or not.

      When an entity is silent it will not produce any sound.

      Parameters:
      flag - if the entity is silent
      Returns:
      builder instance
    • withGravity

      public EntityBuilder withGravity(boolean gravity)
      Sets whether gravity applies to this entity.
      Parameters:
      gravity - whether gravity should apply
      Returns:
      builder instance
    • withMetadata

      public EntityBuilder withMetadata(@NotNull @NotNull String metadataKey, @NotNull @NotNull MetadataValue newMetadataValue)
      Sets a metadata value in the implementing object's metadata store.
      Parameters:
      metadataKey - A unique key to identify this metadata.
      newMetadataValue - The metadata value to apply.
      Returns:
      builder instance
      Throws:
      IllegalArgumentException - If value is null, or the owning plugin is null
    • withCustomName

      public EntityBuilder withCustomName(@Nullable @Nullable String name)
      Sets a custom name on a mob or block. This name will be used in death messages and can be sent to the client as a nameplate over the mob.

      Setting the name to null or an empty string will clear it.

      This value has no effect on players, they will always use their real name.

      Parameters:
      name - the name to set
      Returns:
      builder instance
    • withNBT

      Applies changes to the persistent data container of the entity
      Parameters:
      change - conumer for data container
      Returns:
      builder instance
    • withAttribute

      public EntityBuilder withAttribute(Attribute attribute, double value)
      Sets the AttributeInstance.getBaseValue() to the value which is required to get the target value on AttributeInstance.getValue() for the requested Attribute
      Parameters:
      attribute - attribute type to set if present
      value - target value which should be retrieved via AttributeInstance.getValue()
      Returns:
      builder instance
    • withPotionEffect

      public EntityBuilder withPotionEffect(@NotNull @NotNull PotionEffect effect)
      Adds the given PotionEffect to the living entity.
      Parameters:
      effect - PotionEffect to be added
      Returns:
      builder instance
    • withAI

      public EntityBuilder withAI(boolean ai)
      Sets whether an entity will have AI.

      The entity will be completely unable to move if it has no AI.

      Parameters:
      ai - whether the mob will have AI or not.
      Returns:
      builder instance
    • with

      public EntityBuilder with(Consumer<LivingEntity> entityConsumer)
      Applies a consumer on this entity
      Parameters:
      entityConsumer - consumer
      Returns:
      builder instance
    • with

      public <T extends LivingEntity> EntityBuilder with(Class<T> clazz, Consumer<T> entityConsumer)
      Applies a consumer on this entity after casting it to the requested type.
      Type Parameters:
      T - type of entity
      Parameters:
      clazz - class of entity
      entityConsumer - consumer
      Returns:
      builder instance
    • setCollidable

      public EntityBuilder setCollidable(boolean collidable)
      Set if this entity will be subject to collisions with other entities.

      Exemptions to this rule can be managed with LivingEntity.getCollidableExemptions()

      Parameters:
      collidable - collision status
      Returns:
      builder instance
    • setInvisible

      public EntityBuilder setInvisible(boolean invisible)
      Sets whether the entity is invisible or not.
      Parameters:
      invisible - If the entity is invisible
      Returns:
      builder instance
    • withHealth

      public EntityBuilder withHealth(double health)
      Sets the entity's health from 0 to Damageable.getMaxHealth(), where 0 is dead.
      Parameters:
      health - New health represented from 0 to max
      Returns:
      builder instance
    • withAbsorptionAmount

      public EntityBuilder withAbsorptionAmount(double amount)
      Sets the entity's absorption amount.
      Parameters:
      amount - new absorption amount from 0
      Returns:
      builder instance
      Throws:
      IllegalArgumentException - thrown if health is < 0 or non-finite.
    • build

      public <T extends LivingEntity> T build()
      Returns the builded entity and casts it to the requested type.
      Type Parameters:
      T - type of entity
      Returns:
      entity instance