From 37123c0aa138328aa60fa90503258fe3fcc9c236 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sun, 22 Mar 2015 15:26:01 -0400 Subject: [PATCH] Make async packets less scary --- .../com/comphenix/protocol/async/AsyncMarker.java | 6 +++--- .../com/comphenix/protocol/reflect/MethodInfo.java | 11 ++++++----- .../comphenix/protocol/utility/MinecraftVersion.java | 7 +++++++ 3 files changed, 16 insertions(+), 8 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 1d559db2..3c74919e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java @@ -404,7 +404,6 @@ public class AsyncMarker implements Serializable, Comparable { * @return TRUE if it does, FALSE otherwise. */ public boolean isMinecraftAsync(PacketEvent event) throws FieldAccessException { - if (isMinecraftAsync == null && !alwaysSync) { try { isMinecraftAsync = FuzzyReflection.fromClass(MinecraftReflection.getPacketClass()).getMethodByName("a_.*"); @@ -419,7 +418,7 @@ public class AsyncMarker implements Serializable, Comparable { } else if (methods.size() == 1) { // We're in 1.2.5 alwaysSync = true; - } else if (MinecraftVersion.getCurrentVersion().equals(MinecraftVersion.BOUNTIFUL_UPDATE)) { + } else if (MinecraftVersion.getCurrentVersion().isAtLeast(MinecraftVersion.BOUNTIFUL_UPDATE)) { // The centralized async marker was removed in 1.8 // Incoming chat packets can be async if (event.getPacketType() == PacketType.Play.Client.CHAT) { @@ -436,7 +435,8 @@ public class AsyncMarker implements Serializable, Comparable { return false; } } else { - ProtocolLibrary.log(Level.WARNING, "Cannot determine asynchronous state of packets!"); + ProtocolLibrary.log(Level.INFO, "Could not determine asynchronous state of packets."); + ProtocolLibrary.log(Level.INFO, "This can probably be ignored."); alwaysSync = true; } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/MethodInfo.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/MethodInfo.java index 8b6598cd..53528714 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/MethodInfo.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/MethodInfo.java @@ -17,6 +17,7 @@ import com.google.common.collect.Lists; * * @author Kristian */ +@SuppressWarnings("unused") // Java 8 compat public abstract class MethodInfo implements GenericDeclaration, Member { /** * Wraps a method as a MethodInfo object. @@ -222,7 +223,7 @@ public abstract class MethodInfo implements GenericDeclaration, Member { public abstract String toGenericString(); /** - * Returns an array of Class objects that represent the types of the exceptions declared to be thrown by the + * Returns an array of Class objects that represent the types of the exceptions declared to be thrown by the * underlying method or constructor represented by this MethodInfo object. * @return The exception types declared as being thrown by the method or constructor this object represents. * @see Method#getExceptionTypes() @@ -231,8 +232,8 @@ public abstract class MethodInfo implements GenericDeclaration, Member { public abstract Class[] getExceptionTypes(); /** - * Returns a Class object that represents the formal return type of the method or constructor - * represented by this MethodInfo object. + * Returns a Class object that represents the formal return type of the method or constructor + * represented by this MethodInfo object. *

* This is always {@link Void} for constructors. * @return The return value, or Void if a constructor. @@ -241,10 +242,10 @@ public abstract class MethodInfo implements GenericDeclaration, Member { public abstract Class getReturnType(); /** - * Returns an array of Class objects that represent the formal parameter types, in declaration order, + * Returns an array of Class objects that represent the formal parameter types, in declaration order, * of the method or constructor represented by this MethodInfo object. * @return The parameter types for the method or constructor this object represents. - * @see Method#getParameterTypes() + * @see Method#getParameterTypes() * @see Constructor#getParameterTypes() */ public abstract Class[] getParameterTypes(); 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 50638315..ff7df9ed 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftVersion.java @@ -255,6 +255,13 @@ public class MinecraftVersion implements Comparable, Serializa compare(getSnapshot(), o.getSnapshot(), Ordering.natural().nullsFirst()). result(); } + + public boolean isAtLeast(MinecraftVersion other) { + if (other == null) + return false; + + return compareTo(other) >= 0; + } @Override public boolean equals(Object obj) {