Archiviert
13
0

Add some debug info for exception caught messages

Also added support for deprecated block id's and suppressed some
compiler warnings with Java 7.
Dieser Commit ist enthalten in:
Dan Mulloy 2015-10-07 18:12:50 -04:00
Ursprung 0d3867c6f1
Commit 9433ea5e48
7 geänderte Dateien mit 93 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -27,6 +27,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.internal.TypeParameterMatcher;
@ -285,9 +286,24 @@ public class NettyChannelInjector extends ByteToMessageDecoder implements Channe
ChannelHandlerAdapter exceptionHandler = new ChannelHandlerAdapter() {
@Override
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) {
// Ignore
// This is what the DefaultChannelPipeline does
ReferenceCountUtil.release(cause);
} else {
// We only care about closed channel exceptions, pass everything else along
super.exceptionCaught(ctx, cause);
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -781,6 +781,29 @@ public class BukkitConverters {
* @return A converter for block instances.
*/
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
if (GET_BLOCK == null || GET_BLOCK_ID == null) {
Class<?> block = MinecraftReflection.getBlockClass();
@ -798,20 +821,20 @@ public class BukkitConverters {
GET_BLOCK_ID = Accessors.getMethodAccessor(FuzzyReflection.fromClass(block).getMethod(getIdContract));
}
return new IgnoreNullConverter<Material>() {
return new IgnoreNullConverter<Integer>() {
@Override
protected Object getGenericValue(Class<?> genericType, Material specific) {
return GET_BLOCK.invoke(null, specific.getId());
protected Object getGenericValue(Class<?> genericType, Integer specific) {
return GET_BLOCK.invoke(null, specific);
}
@Override
protected Material getSpecificValue(Object generic) {
return Material.getMaterial((Integer) GET_BLOCK_ID.invoke(null, generic));
protected Integer getSpecificValue(Object generic) {
return (Integer) GET_BLOCK_ID.invoke(null, generic);
}
@Override
public Class<Material> getSpecificType() {
return Material.class;
public Class<Integer> getSpecificType() {
return Integer.class;
}
};
}

Datei anzeigen

@ -81,6 +81,17 @@ public class WrappedBlockData extends AbstractWrapper {
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.
* @return The data of this BlockData.
@ -98,6 +109,14 @@ public class WrappedBlockData extends AbstractWrapper {
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.
* @param type New type

Datei anzeigen

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

Datei anzeigen

@ -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.handler.codec.ByteToMessageDecoder;
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.internal.TypeParameterMatcher;
import net.sf.cglib.proxy.Factory;
@ -283,13 +284,26 @@ public class ShadedChannelInjector extends ByteToMessageDecoder implements Chann
ChannelHandlerAdapter exceptionHandler = new ChannelHandlerAdapter() {
@Override
public void exceptionCaught(ChannelHandlerContext context, Throwable ex) throws Exception {
if (ex instanceof ClosedChannelException) {
// Ignore
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) {
// This is what the DefaultChannelPipeline does
ReferenceCountUtil.release(cause);
} else {
// TODO Actually handle exceptions?
System.err.println("[ProtocolLib] Encountered an uncaught exception in the channel pipeline:");
ex.printStackTrace();
// We only care about closed channel exceptions, pass everything else along
super.exceptionCaught(ctx, cause);
}
}
};