From 615a4e6e376e81542dc2469e28e931f36728570c Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 27 Feb 2016 22:48:11 -0500 Subject: [PATCH] Use the correct Gson class in 1.7.10 --- ProtocolLib/pom.xml | 7 ++++ .../protocol/utility/MinecraftReflection.java | 41 ++++++++++++++----- .../io/NbtConfigurationSerializerTest.java | 5 +-- modules/TinyProtocol/pom.xml | 12 ++++-- pom.xml | 4 ++ 5 files changed, 52 insertions(+), 17 deletions(-) diff --git a/ProtocolLib/pom.xml b/ProtocolLib/pom.xml index 898dadc9..2fe3081d 100644 --- a/ProtocolLib/pom.xml +++ b/ProtocolLib/pom.xml @@ -219,6 +219,13 @@ + org.spigotmc spigot-api 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 695c9fe6..e5f20495 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java @@ -1652,22 +1652,18 @@ public class MinecraftReflection { return getMinecraftClass("TileEntity"); } - private static Class gsonClass = null; - /** * Retrieve the Gson class used by Minecraft. * @return The Gson class. */ public static Class getMinecraftGsonClass() { - if (gsonClass == null) { - try { - return gsonClass = getClass("org.bukkit.craftbukkit.libs.com.google.gson.Gson"); - } catch (RuntimeException e) { - return gsonClass = getClass("com.google.gson.Gson"); - } + try { + return getMinecraftLibraryClass("com.google.gson.Gson"); + } catch (RuntimeException e) { + Class match = FuzzyReflection.fromClass(PacketType.Status.Server.OUT_SERVER_INFO.getPacketClass(), true) + .getFieldByType("(.*)(google.gson.Gson)").getType(); + return setMinecraftLibraryClass("com.google.gson.Gson", match); } - - return gsonClass; } /** @@ -1998,6 +1994,31 @@ public class MinecraftReflection { } } + /** + * Retrieve the class object of a specific Minecraft library class. + * @param className - the specific library Minecraft class. + * @return Class object. + * @throws RuntimeException If we are unable to find the given class. + */ + public static Class getMinecraftLibraryClass(String className) { + if (libraryPackage == null) + libraryPackage = new CachedPackage("", getClassSource()); + return libraryPackage.getPackageClass(className); + } + + /** + * Set the class object for the specific library class. + * @param className - name of the Minecraft library class. + * @param clazz - the new class object. + * @return The provided clazz object. + */ + private static Class setMinecraftLibraryClass(String className, Class clazz) { + if (libraryPackage == null) + libraryPackage = new CachedPackage("", getClassSource()); + libraryPackage.setPackageClass(className, clazz); + return clazz; + } + /** * Dynamically retrieve the NetworkManager name. * @return Name of the NetworkManager class. diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializerTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializerTest.java index 8a2232bd..f037f698 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializerTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/nbt/io/NbtConfigurationSerializerTest.java @@ -16,14 +16,13 @@ public class NbtConfigurationSerializerTest { public static void initializeBukkit() { BukkitInitialization.initializePackage(); } - - @SuppressWarnings("unchecked") + @Test public void testSerialization() { NbtCompound compound = NbtFactory.ofCompound("hello"); compound.put("age", (short) 30); compound.put("name", "test"); - compound.put("values", new int[] { 1, 2, 3}); + compound.put("values", new int[] { 1, 2, 3 }); compound.put(NbtFactory.ofList("telephone", "12345678", "81549300")); compound.put(NbtFactory.ofList("lists", NbtFactory.ofList("", "a", "a", "b", "c"))); diff --git a/modules/TinyProtocol/pom.xml b/modules/TinyProtocol/pom.xml index e08b0248..027464f0 100644 --- a/modules/TinyProtocol/pom.xml +++ b/modules/TinyProtocol/pom.xml @@ -7,6 +7,10 @@ TinyProtocol Intercept packets without ProtocolLib. + + UTF-8 + + com.comphenix.protocol ProtocolLib-Parent @@ -38,8 +42,8 @@ maven-compiler-plugin 3.0 - 1.6 - 1.6 + 1.7 + 1.7 @@ -77,12 +81,12 @@ org.spigotmc spigot-api - 1.8.7-R0.1-SNAPSHOT + 1.8.8-R0.1-SNAPSHOT org.spigotmc spigot - 1.8.7-R0.1-SNAPSHOT + 1.8.8-R0.1-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index 5f4a90f5..361fe62d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,10 @@ v3-SNAPSHOT ProtocolLib-Parent + + UTF-8 + + ProtocolLib modules/v1_7_R4