Skip to content

Commit bd4352f

Browse files
committed
Fix cloning data watchers
Addresses #224
1 parent 05ffeb8 commit bd4352f

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

modules/API/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable<Wrap
5656
private static final Class<?> HANDLE_TYPE = MinecraftReflection.getDataWatcherClass();
5757

5858
private static MethodAccessor GETTER = null;
59-
public static MethodAccessor SETTER = null;
60-
public static MethodAccessor REGISTER = null;
59+
private static MethodAccessor SETTER = null;
60+
private static MethodAccessor REGISTER = null;
6161

6262
private static FieldAccessor ENTITY_DATA_FIELD = null;
6363
private static FieldAccessor ENTITY_FIELD = null;
@@ -389,17 +389,20 @@ public Object getObject(WrappedDataWatcherObject object) {
389389
// ---- Object Setters
390390

391391
/**
392-
* Sets the DataWatcher Item at a given index to a new value.
392+
* Sets the DataWatcher Item at a given index to a new value. In 1.9 and up,
393+
* you cannot register objects without a watcher object.
393394
*
394395
* @param index Index of the object to set
395396
* @param value New value
396397
* @param update Whether or not to inform the client
397398
*
398399
* @see {@link #setObject(WrappedDataWatcherObject, Object, boolean)}
400+
* @throws IllegalArgumentException in 1.9 and up if there isn't already an
401+
* object at this index
399402
*/
400403
public void setObject(int index, Object value, boolean update) {
401404
if (MinecraftReflection.watcherObjectExists() && !hasIndex(index)) {
402-
throw new IllegalArgumentException("You cannot register objects without the watcher object!");
405+
throw new IllegalArgumentException("You cannot register objects without a watcher object!");
403406
}
404407

405408
setObject(WrappedDataWatcherObject.fromIndex(index), value, update);
@@ -427,10 +430,30 @@ public void setObject(int index, Serializer serializer, Object value, boolean up
427430
}
428431

429432
/**
430-
* Shortcut for {@link #setObject(int, Serializer, Object, boolean)}
433+
* Alias for {@link #setObject(int, Serializer, Object, boolean)}
431434
*/
432435
public void setObject(int index, Serializer serializer, Object value) {
433-
setObject(index, serializer, value, false);
436+
setObject(new WrappedDataWatcherObject(index, serializer), value, false);
437+
}
438+
439+
/**
440+
* Sets the DataWatcher Item at a given index to a new value.
441+
*
442+
* @param index Index of the object to set
443+
* @param value New value
444+
* @param update Whether or not to inform the client
445+
*
446+
* @see {@link #setObject(int, Object, boolean)}
447+
*/
448+
public void setObject(int index, WrappedWatchableObject value, boolean update) {
449+
setObject(index, value.getRawValue(), update);
450+
}
451+
452+
/**
453+
* Alias for {@link #setObject(int, WrappedWatchableObject, boolean)}
454+
*/
455+
public void setObject(int index, WrappedWatchableObject value) {
456+
setObject(index, value.getRawValue(), false);
434457
}
435458

436459
/**
@@ -450,7 +473,7 @@ public void setObject(WrappedDataWatcherObject object, WrappedWatchableObject va
450473
* Shortcut for {@link #setObject(WrappedDataWatcherObject, WrappedWatchableObject, boolean)}
451474
*/
452475
public void setObject(WrappedDataWatcherObject object, WrappedWatchableObject value) {
453-
setObject(object, value, false);
476+
setObject(object, value.getRawValue(), false);
454477
}
455478

456479
/**

0 commit comments

Comments
 (0)