Class SimpleEntityData
- All Implemented Interfaces:
SyntaxElement
,YggdrasilSerializable
,YggdrasilSerializable.YggdrasilExtendedSerializable
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface ch.njol.yggdrasil.YggdrasilSerializable
YggdrasilSerializable.YggdrasilExtendedSerializable, YggdrasilSerializable.YggdrasilRobustEnum, YggdrasilSerializable.YggdrasilRobustSerializable
-
Field Summary
Fields inherited from class ch.njol.skript.entity.EntityData
LANGUAGE_NODE, m_adult, m_age_pattern, m_baby, matchedPattern, serializer, WORLD_1_17_CONSUMER, WORLD_1_17_CONSUMER_METHOD
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleEntityData
(Class<? extends org.bukkit.entity.Entity> entityClass) SimpleEntityData
(org.bukkit.entity.Entity entity) -
Method Summary
Modifier and TypeMethodDescriptionboolean
canSpawn
(@Nullable org.bukkit.World world) Checks whether this entity type is allowed to spawn in the givenWorld
.void
deserialize
(Fields fields) Deserializes this object.protected boolean
deserialize
(String string) Deprecated, for removal: This API element is subject to removal in a future version.protected boolean
equals_i
(EntityData<?> obj) Internal helper forEntityData.equals(Object)
to compare the specific data of thisEntityData
with another.@NotNull EntityData
Returns a more general version of thisEntityData
with specific data removed.Class
<? extends org.bukkit.entity.Entity> getType()
protected int
Internal method used byEntityData.hashCode()
to include subclass-specific fields in the hash calculation for thisEntityData
.protected boolean
init
(Literal<?>[] exprs, int matchedPattern, SkriptParser.ParseResult parseResult) Initializes thisEntityData
from the matched pattern and its associated literals.protected boolean
init
(@Nullable Class<? extends org.bukkit.entity.Entity> entityClass, @Nullable org.bukkit.entity.Entity entity) Initializes thisEntityData
from either an entity class or a specificEntity
.boolean
isSupertypeOf
(EntityData<?> entityData) Determines whether thisEntityData
is a supertype of the givenentityData
.boolean
match
(org.bukkit.entity.Entity entity) Determines whether the givenEntity
matches thisEntityData
data.Serialises this object.void
set
(org.bukkit.entity.Entity entity) Applies thisEntityData
to a newly spawnedEntity
.Methods inherited from class ch.njol.skript.entity.EntityData
create, create, create, equals, fromClass, fromEntity, getAgeAdjective, getAll, getAll, getAll, getInfo, getInfo, getName, getSyntaxTypeName, hashCode, init, isBaby, isInstance, isPlural, onRegistrationStop, parse, parseWithoutIndefiniteArticle, register, register, spawn, spawn, spawn, spawn, toString, toString, toString, toString, toString, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.njol.skript.lang.SyntaxElement
getParser, preInit
-
Constructor Details
-
SimpleEntityData
public SimpleEntityData() -
SimpleEntityData
-
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 thisEntityData
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 classEntityData<org.bukkit.entity.Entity>
- Parameters:
exprs
- An array ofLiteral
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 ofnull
.matchedPattern
- The index of the pattern which matched.parseResult
- Additional information from the parser.- Returns:
true
if initialization was successful, otherwisefalse
.
-
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 thisEntityData
from either an entity class or a specificEntity
.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 classEntityData<org.bukkit.entity.Entity>
- Parameters:
entityClass
- An entity's class, e.g. Playerentity
- An actual entity, or null to get an entity data for an entity class- Returns:
true
if initialization was successful, otherwisefalse
.
-
set
public void set(org.bukkit.entity.Entity entity) Description copied from class:EntityData
Applies thisEntityData
to a newly spawnedEntity
.This is used during entity spawning to set additional data, such as a saddled pig.
- Specified by:
set
in classEntityData<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 givenEntity
matches thisEntityData
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 classEntityData<org.bukkit.entity.Entity>
- Parameters:
entity
- TheEntity
to match.- Returns:
true
if the entity matches, otherwisefalse
.
-
getType
Description copied from class:EntityData
- Specified by:
getType
in classEntityData<org.bukkit.entity.Entity>
- Returns:
- The entity's
Class
, such asPig.class
.
-
hashCode_i
protected int hashCode_i()Description copied from class:EntityData
Internal method used byEntityData.hashCode()
to include subclass-specific fields in the hash calculation for thisEntityData
.- Specified by:
hashCode_i
in classEntityData<org.bukkit.entity.Entity>
- Returns:
- A hash code representing subclass-specific data.
-
equals_i
Description copied from class:EntityData
Internal helper forEntityData.equals(Object)
to compare the specific data of thisEntityData
with another.- Specified by:
equals_i
in classEntityData<org.bukkit.entity.Entity>
- Parameters:
obj
- TheEntityData
to compare with.- Returns:
true
if the data is considered equal, otherwisefalse
.
-
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 givenWorld
.Some entity types may be restricted from spawning due to experimental datapacks.
- Overrides:
canSpawn
in classEntityData<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 isnull
; otherwisefalse
.
-
serialize
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 interfaceYggdrasilSerializable.YggdrasilExtendedSerializable
- Overrides:
serialize
in classEntityData<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
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 interfaceYggdrasilSerializable.YggdrasilExtendedSerializable
- Overrides:
deserialize
in classEntityData<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 byYggdrasilSerializable.YggdrasilExtendedSerializable.serialize()
or Yggdrasil's default serialisation.NotSerializableException
-
deserialize
Deprecated, for removal: This API element is subject to removal in a future version.- Overrides:
deserialize
in classEntityData<org.bukkit.entity.Entity>
-
isSupertypeOf
Description copied from class:EntityData
Determines whether thisEntityData
is a supertype of the givenentityData
.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 classEntityData<org.bukkit.entity.Entity>
- Parameters:
entityData
- TheEntityData
to compare against.- Returns:
true
if this is a supertype of the given entity data, otherwisefalse
.
-
getSuperType
Description copied from class:EntityData
Returns a more general version of thisEntityData
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 classEntityData<org.bukkit.entity.Entity>
- Returns:
- A generalized
EntityData
representing the base entity type.
-