- * The secondary value may be NULL if this custom type does not contain a secondary value. - * @param value - the value. - * @param secondary - optional secondary value. - * @return - */ - Object newInstance(Object value, Object secondary) { - Preconditions.checkNotNull(value, "value cannot be NULL."); - - if (hasSecondary()) { - return constructor.invoke(value, secondary); - } else { - if (secondary != null) { - throw new IllegalArgumentException("Cannot construct " + this + " with a secondary value"); - } - return constructor.invoke(value); - } - } - - /** - * Set the secondary value of a given type. - * @param instance - the instance. - * @param secondary - the secondary value. - */ - void setSecondary(Object instance, Object secondary) { - if (!hasSecondary()) { - throw new IllegalArgumentException(this + " does not have a secondary value."); - } - secondaryValue.set(instance, secondary); - } - - /** - * Get the secondary value of a type. - * @param instance - the instance. - * @return The secondary value. - */ - Object getSecondary(Object instance) { - if (!hasSecondary()) { - throw new IllegalArgumentException(this + " does not have a secondary value."); - } - return secondaryValue.get(instance); - } - - /** - * Determine if this type has a secondary value. - * @return TRUE if it does, FALSE otherwise. - */ - public boolean hasSecondary() { - return secondaryValue != null; - } - - /** - * Underlying Spigot class. - * @return The class. - */ - public Class> getSpigotClass() { - return spigotClass; - } - - /** - * The equivalent type ID. - * @return The equivalent ID. - */ - public int getTypeId() { - return typeId; - } - - /** - * Retrieve the custom Spigot type of a value. - * @param value - the value. - * @return The Spigot type, or NULL if not found. - */ - @Spigot(minimumBuild = 1628) - public static CustomType fromValue(Object value) { - for (CustomType type : CustomType.values()) { - if (type.getSpigotClass().isInstance(value)) { - return type; - } - } - return null; - } - } +// /** +// * Every custom watchable type in Spigot #1628 and above. +// * @author Kristian +// */ +// public enum CustomType { +// BYTE_SHORT("org.spigotmc.ProtocolData$ByteShort", 0, short.class), +// DUAL_BYTE("org.spigotmc.ProtocolData$DualByte", 0, byte.class, byte.class), +// HIDDEN_BYTE("org.spigotmc.ProtocolData$HiddenByte", 0, byte.class), +// INT_BYTE("org.spigotmc.ProtocolData$IntByte", 2, int.class, byte.class), +// DUAL_INT("org.spigotmc.ProtocolData$DualInt", 2, int.class, int.class); +// +// private Class> spigotClass; +// private ConstructorAccessor constructor; +// private FieldAccessor secondaryValue; +// private int typeId; +// +// private CustomType(String className, int typeId, Class>... parameters) { +// try { +// this.spigotClass = Class.forName(className); +// this.constructor = Accessors.getConstructorAccessor(spigotClass, parameters); +// this.secondaryValue = parameters.length > 1 ? Accessors.getFieldAccessor(spigotClass, "value2", true) : null; +// +// } catch (ClassNotFoundException e) { +// System.out.println("[ProtocolLib] Unable to find " + className); +// this.spigotClass = null; +// } +// this.typeId = typeId; +// } +// +// /** +// * Construct a new instance of this Spigot type. +// * @param value - the value. Cannot be NULL. +// * @return The instance to construct. +// */ +// Object newInstance(Object value) { +// return newInstance(value, null); +// } +// +// /** +// * Construct a new instance of this Spigot type. +// *
+// * The secondary value may be NULL if this custom type does not contain a secondary value.
+// * @param value - the value.
+// * @param secondary - optional secondary value.
+// * @return
+// */
+// Object newInstance(Object value, Object secondary) {
+// Preconditions.checkNotNull(value, "value cannot be NULL.");
+//
+// if (hasSecondary()) {
+// return constructor.invoke(value, secondary);
+// } else {
+// if (secondary != null) {
+// throw new IllegalArgumentException("Cannot construct " + this + " with a secondary value");
+// }
+// return constructor.invoke(value);
+// }
+// }
+//
+// /**
+// * Set the secondary value of a given type.
+// * @param instance - the instance.
+// * @param secondary - the secondary value.
+// */
+// void setSecondary(Object instance, Object secondary) {
+// if (!hasSecondary()) {
+// throw new IllegalArgumentException(this + " does not have a secondary value.");
+// }
+// secondaryValue.set(instance, secondary);
+// }
+//
+// /**
+// * Get the secondary value of a type.
+// * @param instance - the instance.
+// * @return The secondary value.
+// */
+// Object getSecondary(Object instance) {
+// if (!hasSecondary()) {
+// throw new IllegalArgumentException(this + " does not have a secondary value.");
+// }
+// return secondaryValue.get(instance);
+// }
+//
+// /**
+// * Determine if this type has a secondary value.
+// * @return TRUE if it does, FALSE otherwise.
+// */
+// public boolean hasSecondary() {
+// return secondaryValue != null;
+// }
+//
+// /**
+// * Underlying Spigot class.
+// * @return The class.
+// */
+// public Class> getSpigotClass() {
+// return spigotClass;
+// }
+//
+// /**
+// * The equivalent type ID.
+// * @return The equivalent ID.
+// */
+// public int getTypeId() {
+// return typeId;
+// }
+//
+// /**
+// * Retrieve the custom Spigot type of a value.
+// * @param value - the value.
+// * @return The Spigot type, or NULL if not found.
+// */
+// public static CustomType fromValue(Object value) {
+// for (CustomType type : CustomType.values()) {
+// if (type.getSpigotClass().isInstance(value)) {
+// return type;
+// }
+// }
+// return null;
+// }
+// }
/**
* Used to assign integer IDs to given types.
@@ -434,23 +428,10 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable
- * This is only applicable for certain {@link CustomType}.
- * @return The secondary value, or NULL if not found.
- */
- @Spigot(minimumBuild = 1628)
- public Object getSecondaryValue() {
- CustomType type = getCustomType();
- return type != null ? type.getSecondary(getValue()) : null;
- }
-
- /**
- * Set the secondary value.
- * @param secondary - the secondary value.
- * @throws IllegalStateException If this watchable object does not have a secondary value.
- */
- @Spigot(minimumBuild = 1628)
- public void setSecondaryValue(Object secondary) {
- CustomType type = getCustomType();
-
- if (type == null) {
- throw new IllegalStateException(this + " does not have a custom type.");
- }
- type.setSecondary(getValue(), secondary);
- }
+// /**
+// * Retrieve the secondary value associated with this watchable object.
+// *
+// * This is only applicable for certain {@link CustomType}.
+// * @return The secondary value, or NULL if not found.
+// */
+// public Object getSecondaryValue() {
+// CustomType type = getCustomType();
+// return type != null ? type.getSecondary(getValue()) : null;
+// }
+//
+// /**
+// * Set the secondary value.
+// * @param secondary - the secondary value.
+// * @throws IllegalStateException If this watchable object does not have a secondary value.
+// */
+// public void setSecondaryValue(Object secondary) {
+// CustomType type = getCustomType();
+//
+// if (type == null) {
+// throw new IllegalStateException(this + " does not have a custom type.");
+// }
+// type.setSecondary(getValue(), secondary);
+// }
/**
* Set whether or not the value must be synchronized with the client.