Add some debug info for exception caught messages

Also added support for deprecated block id's and suppressed some
compiler warnings with Java 7.
This commit is contained in:
Dan Mulloy 2015-10-07 18:12:50 -04:00
parent 0d3867c6f1
commit 9433ea5e48
7 changed files with 93 additions and 14 deletions

View File

@ -27,6 +27,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.internal.TypeParameterMatcher; import io.netty.util.internal.TypeParameterMatcher;
@ -285,9 +286,24 @@ public class NettyChannelInjector extends ByteToMessageDecoder implements Channe
ChannelHandlerAdapter exceptionHandler = new ChannelHandlerAdapter() { ChannelHandlerAdapter exceptionHandler = new ChannelHandlerAdapter() {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (channelListener.isDebug()) {
// People were complaining about this on the forums, figure I might as well figure out the cause
System.out.println("------------ ProtocolLib Debug ------------");
System.out.println("Caught an exception in " + playerName + "\'s channel pipeline.");
System.out.println("Context: " + ctx);
System.out.println("The exception was: " + cause);
System.out.println("Stack trace:");
cause.printStackTrace(System.out);
System.out.println("Please create an issue on GitHub with the above message.");
System.out.println("https://github.com/dmulloy2/ProtocolLib/issues");
System.out.println("-------------------------------------------");
}
if (cause instanceof ClosedChannelException) { if (cause instanceof ClosedChannelException) {
// Ignore // This is what the DefaultChannelPipeline does
ReferenceCountUtil.release(cause);
} else { } else {
// We only care about closed channel exceptions, pass everything else along
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
} }
} }

View File

@ -602,6 +602,9 @@ public class FuzzyReflection {
} }
// Prevent duplicate fields // Prevent duplicate fields
// @SafeVarargs
@SuppressWarnings("unchecked")
private static <T> Set<T> setUnion(T[]... array) { private static <T> Set<T> setUnion(T[]... array) {
Set<T> result = new LinkedHashSet<T>(); Set<T> result = new LinkedHashSet<T>();

View File

@ -74,6 +74,8 @@ public class Util {
* @param elements Array to convert * @param elements Array to convert
* @return The list * @return The list
*/ */
// @SafeVarargs
@SuppressWarnings("unchecked")
public static <E> List<E> asList(E... elements) { public static <E> List<E> asList(E... elements) {
List<E> list = new ArrayList<E>(elements.length); List<E> list = new ArrayList<E>(elements.length);
for (E element : elements) { for (E element : elements) {

View File

@ -781,6 +781,29 @@ public class BukkitConverters {
* @return A converter for block instances. * @return A converter for block instances.
*/ */
public static EquivalentConverter<Material> getBlockConverter() { public static EquivalentConverter<Material> getBlockConverter() {
return new IgnoreNullConverter<Material>() {
@Override
protected Object getGenericValue(Class<?> genericType, Material specific) {
return getBlockIDConverter().getGeneric(genericType, specific.getId());
}
@Override
protected Material getSpecificValue(Object generic) {
return Material.getMaterial(getBlockIDConverter().getSpecific(generic));
}
@Override
public Class<Material> getSpecificType() {
return Material.class;
}
};
}
/**
* @deprecated ID's are deprecated
*/
@Deprecated
public static EquivalentConverter<Integer> getBlockIDConverter() {
// Initialize if we have't already // Initialize if we have't already
if (GET_BLOCK == null || GET_BLOCK_ID == null) { if (GET_BLOCK == null || GET_BLOCK_ID == null) {
Class<?> block = MinecraftReflection.getBlockClass(); Class<?> block = MinecraftReflection.getBlockClass();
@ -798,20 +821,20 @@ public class BukkitConverters {
GET_BLOCK_ID = Accessors.getMethodAccessor(FuzzyReflection.fromClass(block).getMethod(getIdContract)); GET_BLOCK_ID = Accessors.getMethodAccessor(FuzzyReflection.fromClass(block).getMethod(getIdContract));
} }
return new IgnoreNullConverter<Material>() { return new IgnoreNullConverter<Integer>() {
@Override @Override
protected Object getGenericValue(Class<?> genericType, Material specific) { protected Object getGenericValue(Class<?> genericType, Integer specific) {
return GET_BLOCK.invoke(null, specific.getId()); return GET_BLOCK.invoke(null, specific);
} }
@Override @Override
protected Material getSpecificValue(Object generic) { protected Integer getSpecificValue(Object generic) {
return Material.getMaterial((Integer) GET_BLOCK_ID.invoke(null, generic)); return (Integer) GET_BLOCK_ID.invoke(null, generic);
} }
@Override @Override
public Class<Material> getSpecificType() { public Class<Integer> getSpecificType() {
return Material.class; return Integer.class;
} }
}; };
} }

View File

@ -81,6 +81,17 @@ public class WrappedBlockData extends AbstractWrapper {
return BukkitConverters.getBlockConverter().getSpecific(block); return BukkitConverters.getBlockConverter().getSpecific(block);
} }
/**
* Retrieves the type id of this BlockData.
* @return The type id of this BlockData.
* @deprecated ID's are deprecated
*/
@Deprecated
public int getTypeId() {
Object block = GET_BLOCK.invoke(handle);
return BukkitConverters.getBlockIDConverter().getSpecific(block);
}
/** /**
* Retrieves the data of this BlockData. * Retrieves the data of this BlockData.
* @return The data of this BlockData. * @return The data of this BlockData.
@ -98,6 +109,14 @@ public class WrappedBlockData extends AbstractWrapper {
setTypeAndData(type, 0); setTypeAndData(type, 0);
} }
/**
* Sets the data of this BlockData.
* @param data New data
*/
public void setData(int data) {
setTypeAndData(getType(), data);
}
/** /**
* Sets the type and data of this BlockData. * Sets the type and data of this BlockData.
* @param type New type * @param type New type

View File

@ -449,6 +449,8 @@ public class NbtFactory {
* @param elements - elements to add. * @param elements - elements to add.
* @return The new filled NBT list. * @return The new filled NBT list.
*/ */
// @SafeVarargs
@SuppressWarnings("unchecked")
public static <T> NbtList<T> ofList(String name, T... elements) { public static <T> NbtList<T> ofList(String name, T... elements) {
return WrappedList.fromArray(name, elements); return WrappedList.fromArray(name, elements);
} }

View File

@ -40,6 +40,7 @@ import net.minecraft.util.io.netty.channel.ChannelPromise;
import net.minecraft.util.io.netty.channel.socket.SocketChannel; import net.minecraft.util.io.netty.channel.socket.SocketChannel;
import net.minecraft.util.io.netty.handler.codec.ByteToMessageDecoder; import net.minecraft.util.io.netty.handler.codec.ByteToMessageDecoder;
import net.minecraft.util.io.netty.handler.codec.MessageToByteEncoder; import net.minecraft.util.io.netty.handler.codec.MessageToByteEncoder;
import net.minecraft.util.io.netty.util.ReferenceCountUtil;
import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener; import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.util.io.netty.util.internal.TypeParameterMatcher; import net.minecraft.util.io.netty.util.internal.TypeParameterMatcher;
import net.sf.cglib.proxy.Factory; import net.sf.cglib.proxy.Factory;
@ -283,13 +284,26 @@ public class ShadedChannelInjector extends ByteToMessageDecoder implements Chann
ChannelHandlerAdapter exceptionHandler = new ChannelHandlerAdapter() { ChannelHandlerAdapter exceptionHandler = new ChannelHandlerAdapter() {
@Override @Override
public void exceptionCaught(ChannelHandlerContext context, Throwable ex) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (ex instanceof ClosedChannelException) { if (channelListener.isDebug()) {
// Ignore // People were complaining about this on the forums, figure I might as well figure out the cause
System.out.println("------------ ProtocolLib Debug ------------");
System.out.println("Caught an exception in " + playerName + "\'s channel pipeline.");
System.out.println("Context: " + ctx);
System.out.println("The exception was: " + cause);
System.out.println("Stack trace:");
cause.printStackTrace(System.out);
System.out.println("Please create an issue on GitHub with the above message.");
System.out.println("https://github.com/dmulloy2/ProtocolLib/issues");
System.out.println("-------------------------------------------");
}
if (cause instanceof ClosedChannelException) {
// This is what the DefaultChannelPipeline does
ReferenceCountUtil.release(cause);
} else { } else {
// TODO Actually handle exceptions? // We only care about closed channel exceptions, pass everything else along
System.err.println("[ProtocolLib] Encountered an uncaught exception in the channel pipeline:"); super.exceptionCaught(ctx, cause);
ex.printStackTrace();
} }
} }
}; };