From a65eac6471a6cd72ada8ba2afb9e333ab69bd56a Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Mon, 14 Apr 2014 13:56:04 +0200 Subject: [PATCH] Use the newer server ping version (5) in 1.7.8 --- .../protocol/wrappers/WrappedServerPing.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java index 33a86a1a..e1102045 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedServerPing.java @@ -7,7 +7,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; - import javax.imageio.ImageIO; import org.bukkit.Bukkit; @@ -21,6 +20,8 @@ import net.minecraft.util.io.netty.handler.codec.base64.Base64; import net.minecraft.util.io.netty.util.IllegalReferenceCountException; import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.injector.BukkitUnwrapper; import com.comphenix.protocol.reflect.EquivalentConverter; import com.comphenix.protocol.reflect.accessors.Accessors; @@ -33,6 +34,7 @@ import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.io.ByteStreams; @@ -41,6 +43,16 @@ import com.google.common.io.ByteStreams; * @author Kristian */ public class WrappedServerPing extends AbstractWrapper { + /** + * Lookup of Minecraft versions and ping version numbers. + */ + private static ImmutableMap VERSION_NUMBERS = + ImmutableMap.builder(). + put(MinecraftVersion.WORLD_UPDATE, 4). + put(MinecraftVersion.SKIN_UPDATE, 5). + build(); + private static MinecraftVersion LAST_VERSION = MinecraftVersion.SKIN_UPDATE; + // Server ping fields private static Class SERVER_PING = MinecraftReflection.getServerPingClass(); private static ConstructorAccessor SERVER_PING_CONSTRUCTOR = Accessors.getConstructorAccessor(SERVER_PING); @@ -114,7 +126,14 @@ public class WrappedServerPing extends AbstractWrapper { * Reset the version string to the default state. */ protected void resetVersion() { - version = VERSION_CONSTRUCTOR.invoke(MinecraftVersion.WORLD_UPDATE.toString(), 4); + ProtocolManager manager = ProtocolLibrary.getProtocolManager(); + MinecraftVersion minecraftVersion = LAST_VERSION; + + // Fetch the latest known version + if (manager != null) { + minecraftVersion = manager.getMinecraftVersion(); + } + version = VERSION_CONSTRUCTOR.invoke(minecraftVersion.toString(), VERSION_NUMBERS.get(minecraftVersion)); VERSION.set(handle, version); } @@ -356,6 +375,11 @@ public class WrappedServerPing extends AbstractWrapper { return (String) GSON_TO_JSON.invoke(PING_GSON.get(null), handle); } + @Override + public String toString() { + return "WrappedServerPing< " + toJson() + ">"; + } + /** * Represents a compressed favicon. * @author Kristian