Class WrappedDataWatcher

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

public class WrappedDataWatcher extends AbstractWrapper implements Iterable<WrappedWatchableObject>, ClonableWrapper
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.
      Returns:
      The contents
    • getIndexes

      public Set<Integer> getIndexes()
      Gets a set containing the registered indexes.
      Returns:
      The set
    • getWatchableObjects

      public List<WrappedWatchableObject> getWatchableObjects()
      Gets a list of the contents of this DataWatcher.
      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.
      Returns:
      The size
    • getWatchableObject

      public WrappedWatchableObject getWatchableObject(int index)
      Gets the item at a given index.
      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.
      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.
      Parameters:
      index - Index to check for
      Returns:
      True if it does, false if not
    • indexSet

      public Set<Integer> indexSet()
      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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • getObject

      public Object getObject(int index)
      Retrieve a watchable object by index.
      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.
      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.
      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.
      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 ClonableWrapper
      Returns:
      A cloned data watcher.
    • 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.
      Returns:
      The entity, or NULL.
    • setEntity

      public void setEntity(org.bukkit.entity.Entity entity)
      Set the entity associated with this data watcher.
      Parameters:
      entity - - the new entity.
    • 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 AbstractWrapper
    • hashCode

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

      public String toString()
      Overrides:
      toString in class AbstractWrapper