Skip to content

Commit 9433ea5

Browse files
committed
Add some debug info for exception caught messages
Also added support for deprecated block id's and suppressed some compiler warnings with Java 7.
1 parent 0d3867c commit 9433ea5

File tree

7 files changed

+93
-14
lines changed

7 files changed

+93
-14
lines changed

ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/independent/NettyChannelInjector.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.netty.channel.socket.SocketChannel;
2828
import io.netty.handler.codec.ByteToMessageDecoder;
2929
import io.netty.handler.codec.MessageToByteEncoder;
30+
import io.netty.util.ReferenceCountUtil;
3031
import io.netty.util.concurrent.GenericFutureListener;
3132
import io.netty.util.internal.TypeParameterMatcher;
3233

@@ -285,9 +286,24 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
285286
ChannelHandlerAdapter exceptionHandler = new ChannelHandlerAdapter() {
286287
@Override
287288
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
289+
if (channelListener.isDebug()) {
290+
// People were complaining about this on the forums, figure I might as well figure out the cause
291+
System.out.println("------------ ProtocolLib Debug ------------");
292+
System.out.println("Caught an exception in " + playerName + "\'s channel pipeline.");
293+
System.out.println("Context: " + ctx);
294+
System.out.println("The exception was: " + cause);
295+
System.out.println("Stack trace:");
296+
cause.printStackTrace(System.out);
297+
System.out.println("Please create an issue on GitHub with the above message.");
298+
System.out.println("https://github.com/dmulloy2/ProtocolLib/issues");
299+
System.out.println("-------------------------------------------");
300+
}
301+
288302
if (cause instanceof ClosedChannelException) {
289-
// Ignore
303+
// This is what the DefaultChannelPipeline does
304+
ReferenceCountUtil.release(cause);
290305
} else {
306+
// We only care about closed channel exceptions, pass everything else along
291307
super.exceptionCaught(ctx, cause);
292308
}
293309
}

ProtocolLib/src/main/java/com/comphenix/protocol/reflect/FuzzyReflection.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ public Set<Constructor<?>> getConstructors() {
602602
}
603603

604604
// Prevent duplicate fields
605+
606+
// @SafeVarargs
607+
@SuppressWarnings("unchecked")
605608
private static <T> Set<T> setUnion(T[]... array) {
606609
Set<T> result = new LinkedHashSet<T>();
607610

ProtocolLib/src/main/java/com/comphenix/protocol/utility/Util.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public static List<Player> getOnlinePlayers() {
7474
* @param elements Array to convert
7575
* @return The list
7676
*/
77+
// @SafeVarargs
78+
@SuppressWarnings("unchecked")
7779
public static <E> List<E> asList(E... elements) {
7880
List<E> list = new ArrayList<E>(elements.length);
7981
for (E element : elements) {

ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/BukkitConverters.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,29 @@ public Class<WrappedStatistic> getSpecificType() {
781781
* @return A converter for block instances.
782782
*/
783783
public static EquivalentConverter<Material> getBlockConverter() {
784+
return new IgnoreNullConverter<Material>() {
785+
@Override
786+
protected Object getGenericValue(Class<?> genericType, Material specific) {
787+
return getBlockIDConverter().getGeneric(genericType, specific.getId());
788+
}
789+
790+
@Override
791+
protected Material getSpecificValue(Object generic) {
792+
return Material.getMaterial(getBlockIDConverter().getSpecific(generic));
793+
}
794+
795+
@Override
796+
public Class<Material> getSpecificType() {
797+
return Material.class;
798+
}
799+
};
800+
}
801+
802+
/**
803+
* @deprecated ID's are deprecated
804+
*/
805+
@Deprecated
806+
public static EquivalentConverter<Integer> getBlockIDConverter() {
784807
// Initialize if we have't already
785808
if (GET_BLOCK == null || GET_BLOCK_ID == null) {
786809
Class<?> block = MinecraftReflection.getBlockClass();
@@ -798,20 +821,20 @@ public static EquivalentConverter<Material> getBlockConverter() {
798821
GET_BLOCK_ID = Accessors.getMethodAccessor(FuzzyReflection.fromClass(block).getMethod(getIdContract));
799822
}
800823

801-
return new IgnoreNullConverter<Material>() {
824+
return new IgnoreNullConverter<Integer>() {
802825
@Override
803-
protected Object getGenericValue(Class<?> genericType, Material specific) {
804-
return GET_BLOCK.invoke(null, specific.getId());
826+
protected Object getGenericValue(Class<?> genericType, Integer specific) {
827+
return GET_BLOCK.invoke(null, specific);
805828
}
806829

807830
@Override
808-
protected Material getSpecificValue(Object generic) {
809-
return Material.getMaterial((Integer) GET_BLOCK_ID.invoke(null, generic));
831+
protected Integer getSpecificValue(Object generic) {
832+
return (Integer) GET_BLOCK_ID.invoke(null, generic);
810833
}
811834

812835
@Override
813-
public Class<Material> getSpecificType() {
814-
return Material.class;
836+
public Class<Integer> getSpecificType() {
837+
return Integer.class;
815838
}
816839
};
817840
}

ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedBlockData.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ public Material getType() {
8181
return BukkitConverters.getBlockConverter().getSpecific(block);
8282
}
8383

84+
/**
85+
* Retrieves the type id of this BlockData.
86+
* @return The type id of this BlockData.
87+
* @deprecated ID's are deprecated
88+
*/
89+
@Deprecated
90+
public int getTypeId() {
91+
Object block = GET_BLOCK.invoke(handle);
92+
return BukkitConverters.getBlockIDConverter().getSpecific(block);
93+
}
94+
8495
/**
8596
* Retrieves the data of this BlockData.
8697
* @return The data of this BlockData.
@@ -98,6 +109,14 @@ public void setType(Material type) {
98109
setTypeAndData(type, 0);
99110
}
100111

112+
/**
113+
* Sets the data of this BlockData.
114+
* @param data New data
115+
*/
116+
public void setData(int data) {
117+
setTypeAndData(getType(), data);
118+
}
119+
101120
/**
102121
* Sets the type and data of this BlockData.
103122
* @param type New type

ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ public static NbtCompound ofCompound(String name) {
449449
* @param elements - elements to add.
450450
* @return The new filled NBT list.
451451
*/
452+
// @SafeVarargs
453+
@SuppressWarnings("unchecked")
452454
public static <T> NbtList<T> ofList(String name, T... elements) {
453455
return WrappedList.fromArray(name, elements);
454456
}

modules/v1_7_R4/src/main/java/com/comphenix/protocol/compat/netty/shaded/ShadedChannelInjector.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import net.minecraft.util.io.netty.channel.socket.SocketChannel;
4141
import net.minecraft.util.io.netty.handler.codec.ByteToMessageDecoder;
4242
import net.minecraft.util.io.netty.handler.codec.MessageToByteEncoder;
43+
import net.minecraft.util.io.netty.util.ReferenceCountUtil;
4344
import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
4445
import net.minecraft.util.io.netty.util.internal.TypeParameterMatcher;
4546
import net.sf.cglib.proxy.Factory;
@@ -283,13 +284,26 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
283284

284285
ChannelHandlerAdapter exceptionHandler = new ChannelHandlerAdapter() {
285286
@Override
286-
public void exceptionCaught(ChannelHandlerContext context, Throwable ex) throws Exception {
287-
if (ex instanceof ClosedChannelException) {
288-
// Ignore
287+
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
288+
if (channelListener.isDebug()) {
289+
// People were complaining about this on the forums, figure I might as well figure out the cause
290+
System.out.println("------------ ProtocolLib Debug ------------");
291+
System.out.println("Caught an exception in " + playerName + "\'s channel pipeline.");
292+
System.out.println("Context: " + ctx);
293+
System.out.println("The exception was: " + cause);
294+
System.out.println("Stack trace:");
295+
cause.printStackTrace(System.out);
296+
System.out.println("Please create an issue on GitHub with the above message.");
297+
System.out.println("https://github.com/dmulloy2/ProtocolLib/issues");
298+
System.out.println("-------------------------------------------");
299+
}
300+
301+
if (cause instanceof ClosedChannelException) {
302+
// This is what the DefaultChannelPipeline does
303+
ReferenceCountUtil.release(cause);
289304
} else {
290-
// TODO Actually handle exceptions?
291-
System.err.println("[ProtocolLib] Encountered an uncaught exception in the channel pipeline:");
292-
ex.printStackTrace();
305+
// We only care about closed channel exceptions, pass everything else along
306+
super.exceptionCaught(ctx, cause);
293307
}
294308
}
295309
};

0 commit comments

Comments
 (0)