public class WrappedDataWatcher extends AbstractWrapper implements java.lang.Iterable<WrappedWatchableObject>
handle, handleType
Constructor and Description |
---|
WrappedDataWatcher()
Initialize a new data watcher.
|
WrappedDataWatcher(java.util.List<WrappedWatchableObject> watchableObjects)
Create a new data watcher for a list of watchable objects.
|
WrappedDataWatcher(java.lang.Object handle)
Create a wrapper for a given data watcher.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.Integer,WrappedWatchableObject> |
asMap()
Retrieve a view of this DataWatcher as a map.
|
WrappedDataWatcher |
deepClone()
Clone the content of the current DataWatcher.
|
boolean |
equals(java.lang.Object obj) |
java.lang.Byte |
getByte(int index)
Get a watched byte.
|
WrappedChunkCoordinate |
getChunkCoordinate(int index)
Get a watched string.
|
org.bukkit.entity.Entity |
getEntity()
Retrieve the entity associated with this data watcher.
|
static WrappedDataWatcher |
getEntityWatcher(org.bukkit.entity.Entity entity)
Retrieve the data watcher associated with an entity.
|
java.lang.Float |
getFloat(int index)
Get a watched float.
|
java.lang.Integer |
getInteger(int index)
Get a watched integer.
|
org.bukkit.inventory.ItemStack |
getItemStack(int index)
Get a watched string.
|
java.lang.Object |
getObject(int index)
Retrieve a watchable object by index.
|
protected java.util.concurrent.locks.ReadWriteLock |
getReadWriteLock()
Retrieve the current read write lock.
|
java.lang.Short |
getShort(int index)
Get a watched short.
|
java.lang.String |
getString(int index)
Get a watched string.
|
static java.lang.Class<?> |
getTypeClass(int id)
Retrieve the type of a given ID, if it's allowed to be watched.
|
static java.lang.Integer |
getTypeID(java.lang.Class<?> clazz)
Retrieve the ID of a given type, if it's allowed to be watched.
|
protected java.util.Map<java.lang.Integer,java.lang.Object> |
getWatchableObjectMap()
Retrieve the underlying map of key values that stores watchable objects.
|
java.util.List<WrappedWatchableObject> |
getWatchableObjects()
Retrieve every watchable object in this watcher.
|
int |
hashCode() |
java.util.Set<java.lang.Integer> |
indexSet()
Retrieve a copy of every index associated with a watched object.
|
java.util.Iterator<WrappedWatchableObject> |
iterator() |
static WrappedDataWatcher |
newWithEntity(org.bukkit.entity.Entity entity)
Construct a new data watcher with the given entity.
|
WrappedWatchableObject |
removeObject(int index)
Remove a given object from the underlying DataWatcher.
|
void |
setEntity(org.bukkit.entity.Entity entity)
Set the entity associated with this data watcher.
|
void |
setObject(int index,
java.lang.Object newValue)
Set a watched byte.
|
void |
setObject(int index,
java.lang.Object newValue,
boolean update)
Set a watched byte.
|
int |
size()
Retrieve the number of watched objects.
|
java.lang.String |
toString() |
getHandle, getHandleType, setHandle
public WrappedDataWatcher()
FieldAccessException
- If we're unable to wrap a DataWatcher.public WrappedDataWatcher(java.lang.Object handle)
handle
- - the data watcher to wrap.FieldAccessException
- If we're unable to wrap a DataWatcher.public WrappedDataWatcher(java.util.List<WrappedWatchableObject> watchableObjects) throws FieldAccessException
Note that the watchable objects are not cloned, and will be modified in place. Use "deepClone" if that is not desirable.
The removeObject(int)
method will not modify the given list, however.
watchableObjects
- - list of watchable objects that will be copied.FieldAccessException
- Unable to read watchable objects.public static WrappedDataWatcher newWithEntity(org.bukkit.entity.Entity entity)
In 1.6.4 and ealier, this will fall back to using WrappedDataWatcher()
.
entity
- - the entity.public static java.lang.Integer getTypeID(java.lang.Class<?> clazz) throws FieldAccessException
FieldAccessException
- If we cannot initialize the reflection machinery.public static java.lang.Class<?> getTypeClass(int id) throws FieldAccessException
FieldAccessException
- If we cannot initialize the reflection machinery.public java.lang.Byte getByte(int index) throws FieldAccessException
index
- - index of the watched byte.FieldAccessException
- Cannot read underlying field.public java.lang.Short getShort(int index) throws FieldAccessException
index
- - index of the watched short.FieldAccessException
- Cannot read underlying field.public java.lang.Integer getInteger(int index) throws FieldAccessException
index
- - index of the watched integer.FieldAccessException
- Cannot read underlying field.public java.lang.Float getFloat(int index) throws FieldAccessException
index
- - index of the watched float.FieldAccessException
- Cannot read underlying field.public java.lang.String getString(int index) throws FieldAccessException
index
- - index of the watched string.FieldAccessException
- Cannot read underlying field.public org.bukkit.inventory.ItemStack getItemStack(int index) throws FieldAccessException
index
- - index of the watched string.FieldAccessException
- Cannot read underlying field.public WrappedChunkCoordinate getChunkCoordinate(int index) throws FieldAccessException
index
- - index of the watched string.FieldAccessException
- Cannot read underlying field.public java.lang.Object getObject(int index) throws FieldAccessException
index
- - index of the object to retrieve.FieldAccessException
- Cannot read underlying field.public java.util.List<WrappedWatchableObject> getWatchableObjects() throws FieldAccessException
FieldAccessException
- If reflection failed.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.util.Set<java.lang.Integer> indexSet() throws FieldAccessException
FieldAccessException
- If we're unable to read the underlying object.public WrappedDataWatcher deepClone()
public int size() throws FieldAccessException
FieldAccessException
- If we're unable to read the underlying object.public WrappedWatchableObject removeObject(int index)
index
- - index of the object to remove.public void setObject(int index, java.lang.Object newValue) throws FieldAccessException
index
- - index of the watched byte.newValue
- - the new watched value.FieldAccessException
- Cannot read underlying field.public void setObject(int index, java.lang.Object newValue, boolean update) throws FieldAccessException
index
- - index of the watched byte.newValue
- - the new watched value.update
- - whether or not to refresh every listening clients.FieldAccessException
- Cannot read underlying field.protected java.util.concurrent.locks.ReadWriteLock getReadWriteLock() throws FieldAccessException
FieldAccessException
- If we're unable to read the underlying field.protected java.util.Map<java.lang.Integer,java.lang.Object> getWatchableObjectMap() throws FieldAccessException
FieldAccessException
- If we don't have permission to perform reflection.public static WrappedDataWatcher getEntityWatcher(org.bukkit.entity.Entity entity) throws FieldAccessException
entity
- - the entity to read from.FieldAccessException
- Reflection failed.public java.util.Iterator<WrappedWatchableObject> iterator()
iterator
in interface java.lang.Iterable<WrappedWatchableObject>
public java.util.Map<java.lang.Integer,WrappedWatchableObject> asMap()
Any changes to the map will be reflected in this DataWatcher, and vice versa.
public java.lang.String toString()
toString
in class java.lang.Object
public org.bukkit.entity.Entity getEntity()
Warning: This is only supported on 1.7.2 and above.
public void setEntity(org.bukkit.entity.Entity entity)
Warning: This is only supported on 1.7.2 and above.
entity
- - the new entity.