From 5605c3817e2e469165365b450358c7bd2c7f47ae Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Wed, 31 Dec 2014 18:26:35 -0500 Subject: [PATCH] Fix issues with determining async packets Fixes #27 --- .../comphenix/protocol/async/AsyncMarker.java | 16 ++++++++++++++-- .../protocol/utility/MinecraftVersion.java | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java index 584ef6f9..e919c5a1 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java @@ -419,8 +419,20 @@ public class AsyncMarker implements Serializable, Comparable { alwaysSync = true; } else if (MinecraftVersion.getCurrentVersion().equals(MinecraftVersion.BOUNTIFUL_UPDATE)) { // The centralized async marker was removed in 1.8 - // The only packet I know for sure is async is incoming chat - return event.getPacketType() == PacketType.Play.Client.CHAT; + // Incoming chat packets can be async + if (event.getPacketType() == PacketType.Play.Client.CHAT) { + String content = event.getPacket().getStrings().readSafely(0); + if (content != null) { + // Incoming chat packets are async only if they aren't commands + return ! content.startsWith("/"); + } else { + System.err.println("[ProtocolLib] Failed to determine contents of incoming chat packet!"); + alwaysSync = true; + } + } else { + // TODO: Find more cases of async packets + return false; + } } else { System.err.println("[ProtocolLib] Cannot determine asynchronous state of packets!"); alwaysSync = true; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java index 4578f268..1e6c575c 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java @@ -316,7 +316,7 @@ public class MinecraftVersion implements Comparable, Serializa public static MinecraftVersion getCurrentVersion() { if (currentVersion == null) { - currentVersion = new MinecraftVersion(Bukkit.getVersion()); + currentVersion = fromServerVersion(Bukkit.getVersion()); } return currentVersion;