Class SimpleEntityData

java.lang.Object
ch.njol.skript.entity.EntityData<org.bukkit.entity.Entity>
ch.njol.skript.entity.SimpleEntityData
All Implemented Interfaces:
SyntaxElement, YggdrasilSerializable, YggdrasilSerializable.YggdrasilExtendedSerializable

public class SimpleEntityData extends EntityData<org.bukkit.entity.Entity>
  • Constructor Details

    • SimpleEntityData

      public SimpleEntityData()
    • SimpleEntityData

      public SimpleEntityData(Class<? extends org.bukkit.entity.Entity> entityClass)
    • SimpleEntityData

      public SimpleEntityData(org.bukkit.entity.Entity entity)
  • Method Details

    • init

      protected boolean init(Literal<?>[] exprs, int matchedPattern, SkriptParser.ParseResult parseResult)
      Description copied from class: EntityData
      Initializes this EntityData from the matched pattern and its associated literals.

      This is used when parsing entity data from user-written patterns such as "a saddled pig".

      Specified by:
      init in class EntityData<org.bukkit.entity.Entity>
      Parameters:
      exprs - An array of Literal expressions from the matched pattern, in the order they appear. If an optional value was omitted by the user, it will still be present in the array with a value of null.
      matchedPattern - The index of the pattern which matched.
      parseResult - Additional information from the parser.
      Returns:
      true if initialization was successful, otherwise false.
    • init

      protected boolean init(@Nullable @Nullable Class<? extends org.bukkit.entity.Entity> entityClass, @Nullable @Nullable org.bukkit.entity.Entity entity)
      Description copied from class: EntityData
      Initializes this EntityData from either an entity class or a specific Entity.

      Example usage:

                  
                      spawn a pig at location(0, 0, 0):
                              set {_entity} to event-entity
                      spawn {_entity} at location(0, 0, 0)
                  
              

      Specified by:
      init in class EntityData<org.bukkit.entity.Entity>
      Parameters:
      entityClass - An entity's class, e.g. Player
      entity - An actual entity, or null to get an entity data for an entity class
      Returns:
      true if initialization was successful, otherwise false.
    • set

      public void set(org.bukkit.entity.Entity entity)
      Description copied from class: EntityData
      Applies this EntityData to a newly spawned Entity.

      This is used during entity spawning to set additional data, such as a saddled pig.

      Specified by:
      set in class EntityData<org.bukkit.entity.Entity>
      Parameters:
      entity - The spawned entity.
    • match

      public boolean match(org.bukkit.entity.Entity entity)
      Description copied from class: EntityData
      Determines whether the given Entity matches this EntityData data.

      For example:

               
                   spawn a pig at location(0, 0, 0):
                              set {_entity} to event-entity
                      if {_entity} is a pig:          # will pass
                      if {_entity} is a saddled pig:  # will not pass
               
           

      Specified by:
      match in class EntityData<org.bukkit.entity.Entity>
      Parameters:
      entity - The Entity to match.
      Returns:
      true if the entity matches, otherwise false.
    • getType

      public Class<? extends org.bukkit.entity.Entity> getType()
      Description copied from class: EntityData
      Returns the Class of the Entity that this EntityData represents or handles.
      Specified by:
      getType in class EntityData<org.bukkit.entity.Entity>
      Returns:
      The entity's Class, such as Pig.class.
    • hashCode_i

      protected int hashCode_i()
      Description copied from class: EntityData
      Internal method used by EntityData.hashCode() to include subclass-specific fields in the hash calculation for this EntityData.
      Specified by:
      hashCode_i in class EntityData<org.bukkit.entity.Entity>
      Returns:
      A hash code representing subclass-specific data.
    • equals_i

      protected boolean equals_i(EntityData<?> obj)
      Description copied from class: EntityData
      Internal helper for EntityData.equals(Object) to compare the specific data of this EntityData with another.
      Specified by:
      equals_i in class EntityData<org.bukkit.entity.Entity>
      Parameters:
      obj - The EntityData to compare with.
      Returns:
      true if the data is considered equal, otherwise false.
    • canSpawn

      public boolean canSpawn(@Nullable @Nullable org.bukkit.World world)
      Description copied from class: EntityData
      Checks whether this entity type is allowed to spawn in the given World.

      Some entity types may be restricted from spawning due to experimental datapacks.

      Overrides:
      canSpawn in class EntityData<org.bukkit.entity.Entity>
      Parameters:
      world - The world to check spawning permissions in.
      Returns:
      true if the entity can be spawned in the given world, or in general if world is null; otherwise false.
    • serialize

      public Fields serialize() throws NotSerializableException
      Description copied from interface: YggdrasilSerializable.YggdrasilExtendedSerializable
      Serialises this object. Only fields contained in the returned Fields object will be written to stream.

      You can use return new Fields(this); to emulate the default behaviour.

      Specified by:
      serialize in interface YggdrasilSerializable.YggdrasilExtendedSerializable
      Overrides:
      serialize in class EntityData<org.bukkit.entity.Entity>
      Returns:
      A Fields object containing all fields that should be written to stream
      Throws:
      NotSerializableException - If this object or one of its fields is not serializable
    • deserialize

      public void deserialize(Fields fields) throws StreamCorruptedException, NotSerializableException
      Description copied from interface: YggdrasilSerializable.YggdrasilExtendedSerializable
      Deserializes this object. No fields have been set when this method is called, use fields.setFields(this, yggdrasil) to set all compatible non-transient and non-static fields (and call incompatible/missing field handlers if applicable – this implies that errors will be thrown if the fields object is invalid).

      You can use fields.setFields(this); to emulate the default behaviour.

      Specified by:
      deserialize in interface YggdrasilSerializable.YggdrasilExtendedSerializable
      Overrides:
      deserialize in class EntityData<org.bukkit.entity.Entity>
      Parameters:
      fields - A Fields object containing all fields read from stream
      Throws:
      StreamCorruptedException - If the Fields object is invalid, i.e. was not written by YggdrasilSerializable.YggdrasilExtendedSerializable.serialize() or Yggdrasil's default serialisation.
      NotSerializableException
    • deserialize

      @Deprecated(since="2.3.0", forRemoval=true) protected boolean deserialize(String string)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Overrides:
      deserialize in class EntityData<org.bukkit.entity.Entity>
    • isSupertypeOf

      public boolean isSupertypeOf(EntityData<?> entityData)
      Description copied from class: EntityData
      Determines whether this EntityData is a supertype of the given entityData.

      This is used to check whether the current entity data represents a broader category than another. For example:

               
                   if a zombie is a monster:    # passes: "monster" is a supertype of "zombie"
                   if a monster is a zombie:    # fails: "zombie" is not a supertype of "monster"
               
           

      Specified by:
      isSupertypeOf in class EntityData<org.bukkit.entity.Entity>
      Parameters:
      entityData - The EntityData to compare against.
      Returns:
      true if this is a supertype of the given entity data, otherwise false.
    • getSuperType

      @NotNull public @NotNull EntityData getSuperType()
      Description copied from class: EntityData
      Returns a more general version of this EntityData with specific data removed.

      For example, calling this on "a saddled pig" would return "a pig". This is typically used to obtain the base entity type without any modifiers or traits.

      Specified by:
      getSuperType in class EntityData<org.bukkit.entity.Entity>
      Returns:
      A generalized EntityData representing the base entity type.