Package com.comphenix.protocol.wrappers
Class WrappedDataWatcher
java.lang.Object
com.comphenix.protocol.wrappers.WrappedDataWatcher
- All Implemented Interfaces:
IDataWatcher,Iterable<WrappedWatchableObject>
Represents a DataWatcher
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a DataWatcherRegistry containing the supportedWrappedDataWatcher.Serializers in 1.9.static classRepresents a DataWatcherSerializer in 1.9.static classRepresents a DataWatcherObject in 1.9. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new DataWatcher using a fake egg entity.WrappedDataWatcher(Object handle) Constructs a new DataWatcher wrapper around a NMS handle.WrappedDataWatcher(List<WrappedWatchableObject> objects) Constructs a new DataWatcher using a fake egg entity and a given list of watchable objects.WrappedDataWatcher(org.bukkit.entity.Entity entity) Constructs a new DataWatcher using a real entity. -
Method Summary
Modifier and TypeMethodDescriptionasMap()Gets the contents of this DataWatcher as a map.voidclear()Clears the contents of this DataWatcher.Clone the content of the current DataWatcher.booleangetBlockState(int index) getBoolean(int index) getByte(int index) Get a watched byte.getChatComponent(int index) getDirection(int index) org.bukkit.entity.EntityRetrieve the entity associated with this data watcher.static WrappedDataWatchergetEntityWatcher(org.bukkit.entity.Entity entity) Retrieve the data watcher associated with an entity.getFloat(int index) Get a watched float.Deprecated.getInteger(int index) Get a watched integer.org.bukkit.inventory.ItemStackgetItemStack(int index) Get a watched string.getLong(int index) getNBTCompound(int index) getObject(int index) Retrieve a watchable object by index.Retrieve a watchable object by watcher object.getOptionalBlockState(int index) getOptionalChatComponent(int index) getOptionalInteger(int index) getOptionalPosition(int index) getOptionalUUID(int index) getParticle(int index) getPose(int index) getPosition(int index) getShort(int index) Get a watched short.getString(int index) Get a watched string.static Class<?> getTypeClass(int typeID) Retrieves the class associated with a given type ID.static IntegerRetrieves the type ID associated with a given class.getVector3F(int index) getVillagerData(int index) getWatchableObject(int index) Gets the item at a given index.Gets a list of the contents of this DataWatcher.inthashCode()booleanhasIndex(int index) Whether or not this DataWatcher has an object at a given index.indexSet()Deprecated.iterator()remove(int index) Removes the item at a given index.removeObject(int index) Deprecated.voidsetBlockState(int index, WrappedBlockData blockData, boolean update) voidsetBoolean(int index, Boolean value, boolean update) voidsetByte(int index, byte value, boolean update) voidsetChatComponent(int index, WrappedChatComponent value, boolean update) voidsetDirection(int index, EnumWrappers.Direction direction, boolean update) voidsetEntity(org.bukkit.entity.Entity entity) Set the entity associated with this data watcher.voidvoidsetInteger(int index, Integer value, boolean update) voidsetItemStack(int index, org.bukkit.inventory.ItemStack itemStack, boolean update) voidvoidsetNBTCompound(int index, NbtCompound nbt, boolean update) voidsetObject(int index, WrappedDataWatcher.Serializer serializer, Object value) voidsetObject(int index, WrappedDataWatcher.Serializer serializer, Object value, boolean update) Sets the DataWatcher Item at a given index to a new value.voidsetObject(int index, WrappedWatchableObject value) voidsetObject(int index, WrappedWatchableObject value, boolean update) Sets the DataWatcher Item at a given index to a new value.voidShortcut forsetObject(int, Object, boolean)voidSets the DataWatcher Item at a given index to a new value.voidvoidsetObject(WrappedDataWatcher.WrappedDataWatcherObject object, WrappedWatchableObject value, boolean update) Sets the DataWatcher Item associated with a given watcher object to a new value.voidsetObject(WrappedDataWatcher.WrappedDataWatcherObject object, Object value) Shortcut forsetObject(WrappedDataWatcherObject, Object, boolean)voidsetObject(WrappedDataWatcher.WrappedDataWatcherObject object, Object value, boolean update) Sets the DataWatcher Item associated with a given watcher object to a new value.voidsetOptionalBlockState(int index, Optional<WrappedBlockData> value, boolean update) voidsetOptionalChatComponent(int index, Optional<WrappedChatComponent> value, boolean update) voidsetOptionalInteger(int index, Optional<Integer> value, boolean update) voidsetOptionalPosition(int index, Optional<BlockPosition> position, boolean update) voidsetOptionalUUID(int index, Optional<UUID> uuid, boolean update) voidsetParticle(int index, WrappedParticle<?> particle, boolean update) voidsetPose(int index, EnumWrappers.EntityPose pose, boolean update) voidsetPosition(int index, BlockPosition position, boolean update) voidvoidsetVector3F(int index, Vector3F vector, boolean update) voidsetVillagerData(int index, WrappedVillagerData data, boolean update) intsize()Gets the size of this DataWatcher's contents.Exports the contents of this data watcher to a list of WrappedDataValues for use in the ENTITY_METADATA packettoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
WrappedDataWatcher
Constructs a new DataWatcher wrapper around a NMS handle. The resulting DataWatcher will likely have existing values that can be removed withclear().- Parameters:
handle- DataWatcher handle
-
WrappedDataWatcher
public WrappedDataWatcher()Constructs a new DataWatcher using a fake egg entity. The resulting DataWatcher will not have any keys or values and new ones will have to be added using watcher objects. -
WrappedDataWatcher
public WrappedDataWatcher(org.bukkit.entity.Entity entity) Constructs a new DataWatcher using a real entity. The resulting DataWatcher will not have any keys or values and new ones will have to be added using watcher objects.- Parameters:
entity- The entity
-
WrappedDataWatcher
Constructs a new DataWatcher using a fake egg entity and a given list of watchable objects.- Parameters:
objects- The list of objects
-
-
Method Details
-
asMap
Gets the contents of this DataWatcher as a map.- Specified by:
asMapin interfaceIDataWatcher- Returns:
- The contents
-
getIndexes
Deprecated.Gets a set containing the registered indexes.- Specified by:
getIndexesin interfaceIDataWatcher- Returns:
- The set
-
getWatchableObjects
Gets a list of the contents of this DataWatcher.- Specified by:
getWatchableObjectsin interfaceIDataWatcher- Returns:
- The contents
-
iterator
- Specified by:
iteratorin interfaceIterable<WrappedWatchableObject>
-
size
public int size()Gets the size of this DataWatcher's contents.- Specified by:
sizein interfaceIDataWatcher- Returns:
- The size
-
getWatchableObject
Gets the item at a given index.- Specified by:
getWatchableObjectin interfaceIDataWatcher- Parameters:
index- Index to get- Returns:
- The watchable object, or null if none exists
-
removeObject
Deprecated.Renamed toremove(int) -
remove
Removes the item at a given index.- Specified by:
removein interfaceIDataWatcher- Parameters:
index- Index to remove- Returns:
- The previous value, or null if none existed
-
hasIndex
public boolean hasIndex(int index) Whether or not this DataWatcher has an object at a given index.- Specified by:
hasIndexin interfaceIDataWatcher- Parameters:
index- Index to check for- Returns:
- True if it does, false if not
-
indexSet
Deprecated.Returns a set containing all the registered indexes- Returns:
- The set
-
clear
public void clear()Clears the contents of this DataWatcher. The watcher will be empty after this operation is called.- Specified by:
clearin interfaceIDataWatcher
-
getByte
Get a watched byte.- Parameters:
index- - index of the watched byte.- Returns:
- The watched byte, or NULL if this value doesn't exist.
-
setByte
public void setByte(int index, byte value, boolean update) -
getShort
Get a watched short.- Parameters:
index- - index of the watched short.- Returns:
- The watched short, or NULL if this value doesn't exist.
-
getInteger
Get a watched integer.- Parameters:
index- - index of the watched integer.- Returns:
- The watched integer, or NULL if this value doesn't exist.
-
setInteger
-
getLong
-
setLong
-
getFloat
Get a watched float.- Parameters:
index- - index of the watched float.- Returns:
- The watched float, or NULL if this value doesn't exist.
-
setFloat
-
getString
Get a watched string.- Parameters:
index- - index of the watched string.- Returns:
- The watched string, or NULL if this value doesn't exist.
-
setString
-
getChatComponent
-
setChatComponent
-
getOptionalChatComponent
-
setOptionalChatComponent
public void setOptionalChatComponent(int index, Optional<WrappedChatComponent> value, boolean update) -
getItemStack
public org.bukkit.inventory.ItemStack getItemStack(int index) Get a watched string.- Parameters:
index- - index of the watched string.- Returns:
- The watched string, or NULL if this value doesn't exist.
-
setItemStack
public void setItemStack(int index, org.bukkit.inventory.ItemStack itemStack, boolean update) -
getBoolean
-
setBoolean
-
getPosition
-
setPosition
-
getOptionalPosition
-
setOptionalPosition
-
getDirection
-
setDirection
-
getOptionalUUID
-
setOptionalUUID
-
getBlockState
-
setBlockState
-
getOptionalBlockState
-
setOptionalBlockState
-
getNBTCompound
-
setNBTCompound
-
getParticle
-
setParticle
-
getVillagerData
-
setVillagerData
-
getOptionalInteger
-
setOptionalInteger
-
getPose
-
setPose
-
getVector3F
-
setVector3F
-
getObject
Retrieve a watchable object by index.- Specified by:
getObjectin interfaceIDataWatcher- Parameters:
index- Index of the object to retrieve.- Returns:
- The watched object or null if it doesn't exist.
-
getObject
Retrieve a watchable object by watcher object.- Specified by:
getObjectin interfaceIDataWatcher- Parameters:
object- The watcher object- Returns:
- The watched object or null if it doesn't exist.
-
setObject
Sets the DataWatcher Item at a given index to a new value. In 1.9 and up, you cannot register objects without a watcher object.- Parameters:
index- Index of the object to setvalue- New valueupdate- Whether or not to inform the client- Throws:
IllegalArgumentException- in 1.9 and up if there isn't already an object at this index- See Also:
-
setObject
Shortcut forsetObject(int, Object, boolean) -
setObject
public void setObject(int index, WrappedDataWatcher.Serializer serializer, Object value, boolean update) Sets the DataWatcher Item at a given index to a new value.- Parameters:
index- Index of the object to setserializer- Serializer fromWrappedDataWatcher.Registry.get(Class)value- New valueupdate- Whether or not to inform the client- See Also:
-
setObject
-
setObject
Sets the DataWatcher Item at a given index to a new value.- Parameters:
index- Index of the object to setvalue- New valueupdate- Whether or not to inform the client- See Also:
-
setObject
-
setObject
public void setObject(WrappedDataWatcher.WrappedDataWatcherObject object, WrappedWatchableObject value, boolean update) Sets the DataWatcher Item associated with a given watcher object to a new value.- Specified by:
setObjectin interfaceIDataWatcher- Parameters:
object- Associated watcher objectvalue- Wrapped valueupdate- Whether or not to inform the client- See Also:
-
setObject
public void setObject(WrappedDataWatcher.WrappedDataWatcherObject object, WrappedWatchableObject value) -
setObject
public void setObject(WrappedDataWatcher.WrappedDataWatcherObject object, Object value, boolean update) Sets the DataWatcher Item associated with a given watcher object to a new value. If there is not already an object at this index, the specified watcher object must have a serializer.- Specified by:
setObjectin interfaceIDataWatcher- Parameters:
object- Associated watcher objectvalue- New value- Throws:
IllegalArgumentException- If the watcher object is null or must have a serializer and does not have one.
-
setObject
Shortcut forsetObject(WrappedDataWatcherObject, Object, boolean) -
deepClone
Clone the content of the current DataWatcher.- Specified by:
deepClonein interfaceIDataWatcher- Returns:
- A cloned data watcher.
-
getHandle
- Specified by:
getHandlein interfaceIDataWatcher- Returns:
-
getEntityWatcher
Retrieve the data watcher associated with an entity.- Parameters:
entity- - the entity to read from.- Returns:
- Associated data watcher.
-
getEntity
public org.bukkit.entity.Entity getEntity()Retrieve the entity associated with this data watcher.- Specified by:
getEntityin interfaceIDataWatcher- Returns:
- The entity, or NULL.
-
setEntity
public void setEntity(org.bukkit.entity.Entity entity) Set the entity associated with this data watcher.- Specified by:
setEntityin interfaceIDataWatcher- Parameters:
entity- - the new entity.
-
toDataValueCollection
Exports the contents of this data watcher to a list of WrappedDataValues for use in the ENTITY_METADATA packet- Returns:
- The data value collection
-
getTypeID
Retrieves the type ID associated with a given class. No longer supported in 1.9 and up due to the removal of type IDs.- Parameters:
clazz- Class to find ID for- Returns:
- The ID, or null if not found
-
getTypeClass
Retrieves the class associated with a given type ID. No longer supported in 1.9 and up due to the removal of type IDs.- Parameters:
typeID- ID to find Class for- Returns:
- The Class, or null if not found
-
equals
-
hashCode
public int hashCode() -
toString
-
remove(int)