Package com.comphenix.protocol.wrappers
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
-
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. -
Field Summary
Fields inherited from class com.comphenix.protocol.wrappers.AbstractWrapper
handle, handleType -
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.booleangetByte(int index) Get a watched byte.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.Gets a set containing the registered indexes.getInteger(int index) Get a watched integer.org.bukkit.inventory.ItemStackgetItemStack(int index) Get a watched string.getObject(int index) Retrieve a watchable object by index.Retrieve a watchable object by watcher object.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.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()Returns a set containing all the registered indexesiterator()remove(int index) Removes the item at a given index.removeObject(int index) Deprecated.voidsetEntity(org.bukkit.entity.Entity entity) Set the entity associated with this data watcher.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.intsize()Gets the size of this DataWatcher's contents.toString()Methods inherited from class com.comphenix.protocol.wrappers.AbstractWrapper
getHandle, getHandleType, setHandleMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.comphenix.protocol.wrappers.ClonableWrapper
getHandleMethods 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.- Returns:
- The contents
-
getIndexes
Gets a set containing the registered indexes.- Returns:
- The set
-
getWatchableObjects
Gets a list of the contents of this DataWatcher.- Returns:
- The contents
-
iterator
- Specified by:
iteratorin interfaceIterable<WrappedWatchableObject>
-
size
public int size()Gets the size of this DataWatcher's contents.- Returns:
- The size
-
getWatchableObject
Gets the item at a given index.- 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.- 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
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
Get a watched byte.- Parameters:
index- - index of the watched byte.- Returns:
- The watched byte, or NULL if this value doesn't exist.
-
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.
-
getFloat
Get a watched float.- Parameters:
index- - index of the watched float.- Returns:
- The watched float, or NULL if this value doesn't exist.
-
getString
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
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
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.- 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.- 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 interfaceClonableWrapper- Returns:
- A cloned data watcher.
-
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.- 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
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
- Overrides:
equalsin classAbstractWrapper
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractWrapper
-
toString
- Overrides:
toStringin classAbstractWrapper
-
remove(int)