Class WrappedDataWatcher

java.lang.Object
com.comphenix.protocol.wrappers.WrappedDataWatcher
All Implemented Interfaces:
IDataWatcher, Iterable<WrappedWatchableObject>

public class WrappedDataWatcher extends Object implements IDataWatcher
Represents a DataWatcher
  • Constructor Details

    • WrappedDataWatcher

      public WrappedDataWatcher(Object handle)
      Constructs a new DataWatcher wrapper around a NMS handle. The resulting DataWatcher will likely have existing values that can be removed with clear().
      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

      public WrappedDataWatcher(List<WrappedWatchableObject> objects)
      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:
      asMap in interface IDataWatcher
      Returns:
      The contents
    • getIndexes

      @Deprecated public Set<Integer> getIndexes()
      Deprecated.
      Gets a set containing the registered indexes.
      Specified by:
      getIndexes in interface IDataWatcher
      Returns:
      The set
    • getWatchableObjects

      public List<WrappedWatchableObject> getWatchableObjects()
      Gets a list of the contents of this DataWatcher.
      Specified by:
      getWatchableObjects in interface IDataWatcher
      Returns:
      The contents
    • iterator

      public Iterator<WrappedWatchableObject> iterator()
      Specified by:
      iterator in interface Iterable<WrappedWatchableObject>
    • size

      public int size()
      Gets the size of this DataWatcher's contents.
      Specified by:
      size in interface IDataWatcher
      Returns:
      The size
    • getWatchableObject

      public WrappedWatchableObject getWatchableObject(int index)
      Gets the item at a given index.
      Specified by:
      getWatchableObject in interface IDataWatcher
      Parameters:
      index - Index to get
      Returns:
      The watchable object, or null if none exists
    • removeObject

      @Deprecated public WrappedWatchableObject removeObject(int index)
      Deprecated.
      Renamed to remove(int)
    • remove

      public WrappedWatchableObject remove(int index)
      Removes the item at a given index.
      Specified by:
      remove in interface IDataWatcher
      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:
      hasIndex in interface IDataWatcher
      Parameters:
      index - Index to check for
      Returns:
      True if it does, false if not
    • indexSet

      @Deprecated public Set<Integer> 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:
      clear in interface IDataWatcher
    • getByte

      public Byte getByte(int index)
      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

      public Short getShort(int index)
      Get a watched short.
      Parameters:
      index - - index of the watched short.
      Returns:
      The watched short, or NULL if this value doesn't exist.
    • getInteger

      public Integer getInteger(int index)
      Get a watched integer.
      Parameters:
      index - - index of the watched integer.
      Returns:
      The watched integer, or NULL if this value doesn't exist.
    • setInteger

      public void setInteger(int index, Integer value, boolean update)
    • getLong

      public Long getLong(int index)
    • setLong

      public void setLong(int index, Long value, boolean update)
    • getFloat

      public Float getFloat(int index)
      Get a watched float.
      Parameters:
      index - - index of the watched float.
      Returns:
      The watched float, or NULL if this value doesn't exist.
    • setFloat

      public void setFloat(int index, Float value, boolean update)
    • getString

      public String getString(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.
    • setString

      public void setString(int index, String value, boolean update)
    • getChatComponent

      public WrappedChatComponent getChatComponent(int index)
    • setChatComponent

      public void setChatComponent(int index, WrappedChatComponent value, boolean update)
    • getOptionalChatComponent

      public Optional<WrappedChatComponent> getOptionalChatComponent(int index)
    • 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

      public Boolean getBoolean(int index)
    • setBoolean

      public void setBoolean(int index, Boolean value, boolean update)
    • getPosition

      public BlockPosition getPosition(int index)
    • setPosition

      public void setPosition(int index, BlockPosition position, boolean update)
    • getOptionalPosition

      public Optional<BlockPosition> getOptionalPosition(int index)
    • setOptionalPosition

      public void setOptionalPosition(int index, Optional<BlockPosition> position, boolean update)
    • getDirection

      public EnumWrappers.Direction getDirection(int index)
    • setDirection

      public void setDirection(int index, EnumWrappers.Direction direction, boolean update)
    • getOptionalUUID

      public Optional<UUID> getOptionalUUID(int index)
    • setOptionalUUID

      public void setOptionalUUID(int index, Optional<UUID> uuid, boolean update)
    • getBlockState

      public WrappedBlockData getBlockState(int index)
    • setBlockState

      public void setBlockState(int index, WrappedBlockData blockData, boolean update)
    • getOptionalBlockState

      public Optional<WrappedBlockData> getOptionalBlockState(int index)
    • setOptionalBlockState

      public void setOptionalBlockState(int index, Optional<WrappedBlockData> value, boolean update)
    • getNBTCompound

      public NbtCompound getNBTCompound(int index)
    • setNBTCompound

      public void setNBTCompound(int index, NbtCompound nbt, boolean update)
    • getParticle

      public WrappedParticle<?> getParticle(int index)
    • setParticle

      public void setParticle(int index, WrappedParticle<?> particle, boolean update)
    • getVillagerData

      public WrappedVillagerData getVillagerData(int index)
    • setVillagerData

      public void setVillagerData(int index, WrappedVillagerData data, boolean update)
    • getOptionalInteger

      public Optional<Integer> getOptionalInteger(int index)
    • setOptionalInteger

      public void setOptionalInteger(int index, Optional<Integer> value, boolean update)
    • getPose

      public EnumWrappers.EntityPose getPose(int index)
    • setPose

      public void setPose(int index, EnumWrappers.EntityPose pose, boolean update)
    • getVector3F

      public Vector3F getVector3F(int index)
    • setVector3F

      public void setVector3F(int index, Vector3F vector, boolean update)
    • getObject

      public Object getObject(int index)
      Retrieve a watchable object by index.
      Specified by:
      getObject in interface IDataWatcher
      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:
      getObject in interface IDataWatcher
      Parameters:
      object - The watcher object
      Returns:
      The watched object or null if it doesn't exist.
    • setObject

      public void setObject(int index, Object value, boolean update)
      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 set
      value - New value
      update - 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

      public void setObject(int index, Object value)
    • 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 set
      serializer - Serializer from WrappedDataWatcher.Registry.get(Class)
      value - New value
      update - Whether or not to inform the client
      See Also:
    • setObject

      public void setObject(int index, WrappedDataWatcher.Serializer serializer, Object value)
    • setObject

      public void setObject(int index, WrappedWatchableObject value, boolean update)
      Sets the DataWatcher Item at a given index to a new value.
      Parameters:
      index - Index of the object to set
      value - New value
      update - Whether or not to inform the client
      See Also:
    • setObject

      public void setObject(int index, WrappedWatchableObject value)
    • 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:
      setObject in interface IDataWatcher
      Parameters:
      object - Associated watcher object
      value - Wrapped value
      update - Whether or not to inform the client
      See Also:
    • setObject

    • 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:
      setObject in interface IDataWatcher
      Parameters:
      object - Associated watcher object
      value - New value
      Throws:
      IllegalArgumentException - If the watcher object is null or must have a serializer and does not have one.
    • setObject

      public void setObject(WrappedDataWatcher.WrappedDataWatcherObject object, Object value)
    • deepClone

      public WrappedDataWatcher deepClone()
      Clone the content of the current DataWatcher.
      Specified by:
      deepClone in interface IDataWatcher
      Returns:
      A cloned data watcher.
    • getHandle

      public Object getHandle()
      Specified by:
      getHandle in interface IDataWatcher
      Returns:
    • getEntityWatcher

      public static WrappedDataWatcher getEntityWatcher(org.bukkit.entity.Entity entity)
      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:
      getEntity in interface IDataWatcher
      Returns:
      The entity, or NULL.
    • setEntity

      public void setEntity(org.bukkit.entity.Entity entity)
      Set the entity associated with this data watcher.
      Specified by:
      setEntity in interface IDataWatcher
      Parameters:
      entity - - the new entity.
    • toDataValueCollection

      public List<WrappedDataValue> 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

      public static Integer getTypeID(Class<?> clazz)
      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

      public static Class<?> getTypeClass(int typeID)
      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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object