Class SimpleEntityData
- All Implemented Interfaces:
SyntaxElement, YggdrasilSerializable, YggdrasilSerializable.YggdrasilExtendedSerializable, EntityItemTypeComparable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final recordNested classes/interfaces inherited from class EntityData
EntityData.EntityDataPatterns<Data>, EntityData.PatternGroup<Data>Nested classes/interfaces inherited from interface YggdrasilSerializable
YggdrasilSerializable.YggdrasilExtendedSerializable, YggdrasilSerializable.YggdrasilRobustEnum, YggdrasilSerializable.YggdrasilRobustSerializable -
Field Summary
Fields inherited from class EntityData
AGE_ADULT, AGE_BABY, AGE_PATTERN, groupIndexFields inherited from class EntityData
LANGUAGE_NODE, serializer -
Constructor Summary
ConstructorsConstructorDescriptionSimpleEntityData(Class<? extends org.bukkit.entity.Entity> entityClass) Constructs a newSimpleEntityDatausingentityClassto find the closestSimpleEntityData.SimpleEntityDataInfothat best represents it.SimpleEntityData(org.bukkit.entity.Entity entity) Constructs a newSimpleEntityDatausingentityto find the closestSimpleEntityData.SimpleEntityDataInfothat best represents it. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanSpawn(@Nullable org.bukkit.World world) Checks whether this entity type is allowed to spawn in the givenWorld.voiddeserialize(Fields fields) Deserializes this object.protected booleanequals_i(EntityData<?> entityData) Internal helper forEntityData.equals(Object)to compare the specific data of thisEntityDatawith another.@NotNull EntityData<?> Returns a more general version of thisEntityDatawith specific data removed.Class<? extends org.bukkit.entity.Entity> getType()protected intInternal method used byEntityData.hashCode()to include subclass-specific fields in the hash calculation for thisEntityData.protected booleaninit(Literal<?>[] exprs, int matchedGroup, int matchedPattern, SkriptParser.ParseResult parseResult) Initializes thisEntityData.protected booleaninit(@Nullable Class<? extends org.bukkit.entity.Entity> entityClass, @Nullable org.bukkit.entity.Entity entity) Initializes thisEntityDatafrom either an entity class or a specificEntity.booleanisOfItemType(ItemType itemType) Whether thisEntityDatatyped-class is ofitemType.booleanisSupertypeOf(EntityData<?> entityData) Determines whether thisEntityDatais a supertype of the givenentityData.booleanmatch(org.bukkit.entity.Entity entity) Determines whether the givenEntitymatches thisEntityDatadata.static voidregister()Serialises this object.voidset(org.bukkit.entity.Entity entity) Applies thisEntityDatato a newly spawnedEntity.Methods inherited from class EntityData
create, create, create, dataMatch, equals, fromClass, fromEntity, getAgeNoun, getAll, getAll, getAll, getInfo, getInfo, getName, getSyntaxTypeName, hashCode, infoBuilder, init, isBaby, isInstance, isPlural, isRegistered, isSupertypeOf, kleeneanMatch, kleeneanMatch, onRegistrationStop, parse, parseWithoutIndefiniteArticle, registerInfo, spawn, spawn, spawn, toString, toString, toString, toString, toString, toStringMethods inherited from class EntityData
getAll, getAllMethods inherited from interface SyntaxElement
getParser, preInit
-
Constructor Details
-
SimpleEntityData
public SimpleEntityData() -
SimpleEntityData
-
SimpleEntityData
Constructs a newSimpleEntityDatausingentityClassto find the closestSimpleEntityData.SimpleEntityDataInfothat best represents it.- Parameters:
entityClass- The class of the desiredEntity.- Throws:
IllegalStateException- If theentityClassis not covered bySimpleEntityData.
-
SimpleEntityData
@Internal public SimpleEntityData(org.bukkit.entity.Entity entity) Constructs a newSimpleEntityDatausingentityto find the closestSimpleEntityData.SimpleEntityDataInfothat best represents it.- Parameters:
entity- The desiredEntity.- Throws:
IllegalStateException- If theentityis not covered bySimpleEntityData.
-
-
Method Details
-
register
@Internal public static void register() -
init
protected boolean init(Literal<?>[] exprs, int matchedGroup, int matchedPattern, SkriptParser.ParseResult parseResult) Description copied from class:EntityDataInitializes thisEntityData.As of Skript 2.13, code names can have multiple patterns.
matchedGroupwill be the index of the code name the matched pattern is linked to. (e.g.PigData"unsaddled pig" = 0, "pig" = 1, "saddled pig" = 2)matchedPatternwill be the index of the pattern used from the patterns of the group.- Specified by:
initin classEntityData<org.bukkit.entity.Entity>- Parameters:
exprs- An array ofLiteralexpressions 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.matchedGroup- The index of the group which matched.matchedPattern- The index of the pattern of the group which matched.parseResult- Additional information from the parser.- Returns:
trueif 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:EntityDataInitializes thisEntityDatafrom 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:
initin 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:
trueif initialization was successful, otherwisefalse.
-
set
public void set(org.bukkit.entity.Entity entity) Description copied from class:EntityDataApplies thisEntityDatato a newly spawnedEntity.This is used during entity spawning to set additional data, such as a saddled pig.
- Specified by:
setin classEntityData<org.bukkit.entity.Entity>- Parameters:
entity- The spawned entity.
-
match
public boolean match(org.bukkit.entity.Entity entity) Description copied from class:EntityDataDetermines whether the givenEntitymatches thisEntityDatadata.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:
matchin classEntityData<org.bukkit.entity.Entity>- Parameters:
entity- TheEntityto match.- Returns:
trueif the entity matches, otherwisefalse.
-
getType
Description copied from class:EntityData- Specified by:
getTypein classEntityData<org.bukkit.entity.Entity>- Returns:
- The entity's
Class, such asPig.class.
-
getSuperType
Description copied from class:EntityDataReturns a more general version of thisEntityDatawith specific data removed.For example, calling this on
"a saddled pig"should return"a pig". This is typically used to obtain the base entity type without any modifiers or traits.- Specified by:
getSuperTypein classEntityData<org.bukkit.entity.Entity>- Returns:
- A generalized
EntityDatarepresenting the base entity type.
-
hashCode_i
protected int hashCode_i()Description copied from class:EntityDataInternal method used byEntityData.hashCode()to include subclass-specific fields in the hash calculation for thisEntityData.- Specified by:
hashCode_iin classEntityData<org.bukkit.entity.Entity>- Returns:
- A hash code representing subclass-specific data.
-
equals_i
Description copied from class:EntityDataInternal helper forEntityData.equals(Object)to compare the specific data of thisEntityDatawith another.- Specified by:
equals_iin classEntityData<org.bukkit.entity.Entity>- Parameters:
entityData- TheEntityDatato compare with.- Returns:
trueif the data is considered equal, otherwisefalse.
-
isSupertypeOf
Description copied from class:EntityDataDetermines whether thisEntityDatais 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:
isSupertypeOfin classEntityData<org.bukkit.entity.Entity>- Parameters:
entityData- TheEntityDatato compare against.- Returns:
trueif this is a supertype of the given entity data, otherwisefalse.
-
canSpawn
public boolean canSpawn(@Nullable @Nullable org.bukkit.World world) Description copied from class:EntityDataChecks whether this entity type is allowed to spawn in the givenWorld.Some entity types may be restricted from spawning due to experimental datapacks.
- Overrides:
canSpawnin classEntityData<org.bukkit.entity.Entity>- Parameters:
world- The world to check spawning permissions in.- Returns:
trueif the entity can be spawned in the given world, or in general if world isnull; otherwisefalse.
-
serialize
Description copied from interface:YggdrasilSerializable.YggdrasilExtendedSerializableSerialises 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:
serializein interfaceYggdrasilSerializable.YggdrasilExtendedSerializable- Overrides:
serializein 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.YggdrasilExtendedSerializableDeserializes 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:
deserializein interfaceYggdrasilSerializable.YggdrasilExtendedSerializable- Overrides:
deserializein 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
-
isOfItemType
Description copied from interface:EntityItemTypeComparableWhether thisEntityDatatyped-class is ofitemType. Each implementation varies on what is considered to pass.- Specified by:
isOfItemTypein interfaceEntityItemTypeComparable- Parameters:
itemType- TheItemTypeto check against.- Returns:
trueif theitemTypepasses, otherwisefalse.
-