From 16c7ebef73ffb8e969b0971c3f0e380611daf5ab Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Mon, 7 Mar 2016 19:05:58 -0500 Subject: [PATCH] A few minor tweaks --- .../reflect/cloning/BukkitCloner.java | 2 +- .../reflect/cloning/ImmutableDetector.java | 2 +- .../protocol/utility/MinecraftReflection.java | 48 +++++++++++-------- .../protocol/wrappers/WrappedDataWatcher.java | 2 +- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java index c6164f61..1544e280 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java @@ -57,7 +57,7 @@ public class BukkitCloner implements Cloner { addClass(4, MinecraftReflection.getServerPingClass()); } - if (MinecraftReflection.dataWatcherItemExists()) { + if (MinecraftReflection.watcherObjectExists()) { addClass(5, MinecraftReflection.getDataWatcherSerializerClass()); addClass(6, MinecraftReflection.getMinecraftKeyClass()); } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/ImmutableDetector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/ImmutableDetector.java index 1a03909b..342784f1 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/ImmutableDetector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/ImmutableDetector.java @@ -89,7 +89,7 @@ public class ImmutableDetector implements Cloner { } // Check for known immutable classes in 1.9 - if (MinecraftReflection.dataWatcherItemExists()) { + if (MinecraftReflection.watcherObjectExists()) { if (type.equals(MinecraftReflection.getDataWatcherSerializerClass()) || type.equals(MinecraftReflection.getMinecraftClass("SoundEffect"))) { return true; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java index 74ef8809..e516329f 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java @@ -1286,14 +1286,20 @@ public class MinecraftReflection { /** * Retrieve the WatchableObject class. * @return The WatchableObject class. + * @deprecated Replaced by {@link #getDataWatcherItemClass()} */ + @Deprecated public static Class getWatchableObjectClass() { - if (dataWatcherItemExists()) { - return getDataWatcherItemClass(); - } + return getDataWatcherItemClass(); + } + /** + * Retrieve the DataWatcher Item class. + * @return The class + */ + public static Class getDataWatcherItemClass() { try { - return getMinecraftClass("WatchableObject", "DataWatcher$WatchableObject"); + return getMinecraftClass("DataWatcher$Item", "DataWatcher$WatchableObject", "WatchableObject"); } catch (RuntimeException e) { Method selected = FuzzyReflection.fromClass(getDataWatcherClass(), true). getMethod(FuzzyMethodContract.newBuilder(). @@ -1303,32 +1309,36 @@ public class MinecraftReflection { build()); // Use the second parameter - return setMinecraftClass("WatchableObject", selected.getParameterTypes()[1]); + return setMinecraftClass("DataWatcher$Item", selected.getParameterTypes()[1]); } } - public static Class getDataWatcherItemClass() { - // TODO Implement a fallback - return getMinecraftClass("DataWatcher$Item"); - } - public static Class getDataWatcherObjectClass() { // TODO Implement a fallback return getMinecraftClass("DataWatcherObject"); } + public static boolean watcherObjectExists() { + try { + return getDataWatcherObjectClass() != null; + } catch (RuntimeException e) { + return false; + } + } + public static Class getDataWatcherSerializerClass() { // TODO Implement a fallback return getMinecraftClass("DataWatcherSerializer"); } - public static boolean dataWatcherItemExists() { - try { - getDataWatcherItemClass(); - return true; - } catch (RuntimeException e) { - return false; - } + public static Class getDataWatcherRegistryClass() { + // TODO Implement a fallback + return getMinecraftClass("DataWatcherRegistry"); + } + + public static Class getMinecraftKeyClass() { + // TODO Implement a fallback + return getMinecraftClass("MinecraftKey"); } /** @@ -2077,8 +2087,4 @@ public class MinecraftReflection { throw new RuntimeException("Cannot construct packet serializer.", e); } } - - public static Class getMinecraftKeyClass() { - return getMinecraftClass("MinecraftKey"); - } } \ No newline at end of file diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java index 3992eaab..5617dbd5 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedDataWatcher.java @@ -674,7 +674,7 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable candidates = FuzzyReflection.fromClass(MinecraftReflection.getMinecraftClass("DataWatcherRegistry"), true) + List candidates = FuzzyReflection.fromClass(MinecraftReflection.getDataWatcherRegistryClass(), true) .getFieldListByType(MinecraftReflection.getDataWatcherSerializerClass()); for (Field candidate : candidates) { Type generic = candidate.getGenericType();