public class WrappedDataWatcher extends java.lang.Object implements java.lang.Iterable<WrappedWatchableObject>
Modifier and Type | Field and Description |
---|---|
protected java.lang.Object |
handle |
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 |
---|---|
WrappedDataWatcher |
deepClone()
Clone the content of the current DataWatcher.
|
java.lang.Byte |
getByte(int index)
Get a watched byte.
|
WrappedChunkCoordinate |
getChunkCoordinate(int index)
Get a watched string.
|
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.Object |
getHandle()
Retrieves the underlying data watcher.
|
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.
|
java.util.Set<java.lang.Integer> |
indexSet()
Retrieve a copy of every index associated with a watched object.
|
java.util.Iterator<WrappedWatchableObject> |
iterator() |
WrappedWatchableObject |
removeObject(int index)
Remove a given object from the underlying DataWatcher.
|
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.
|
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 java.lang.Object getHandle()
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 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>