diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitDecodeHandler.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitDecodeHandler.java index 150c2e428..700f3e79d 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitDecodeHandler.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitDecodeHandler.java @@ -6,6 +6,7 @@ import io.netty.handler.codec.ByteToMessageDecoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.exception.CancelDecoderException; +import us.myles.ViaVersion.exception.ViaCodecException; import us.myles.ViaVersion.util.PipelineUtil; import java.lang.reflect.InvocationTargetException; @@ -52,7 +53,8 @@ public class BukkitDecodeHandler extends ByteToMessageDecoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (PipelineUtil.containsCause(cause, CancelDecoderException.class)) return; // ProtocolLib compat + if (PipelineUtil.containsCause(cause, ViaCodecException.class)) return; // ProtocolLib compat + super.exceptionCaught(ctx, cause); if (!NMSUtil.isDebugPropertySet()) { cause.printStackTrace(); // Print if CB doesn't already do it diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitEncodeHandler.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitEncodeHandler.java index 8a003b1ea..13099db01 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitEncodeHandler.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitEncodeHandler.java @@ -6,6 +6,7 @@ import io.netty.handler.codec.MessageToByteEncoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.exception.CancelEncoderException; +import us.myles.ViaVersion.exception.ViaCodecException; import us.myles.ViaVersion.handlers.ChannelHandlerContextWrapper; import us.myles.ViaVersion.handlers.ViaHandler; import us.myles.ViaVersion.util.PipelineUtil; @@ -33,7 +34,6 @@ public class BukkitEncodeHandler extends MessageToByteEncoder implements ViaHand this.minecraftEncoder = minecraftEncoder; } - @Override protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception { if (versionField != null) { @@ -65,7 +65,8 @@ public class BukkitEncodeHandler extends MessageToByteEncoder implements ViaHand @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (PipelineUtil.containsCause(cause, CancelEncoderException.class)) return; // ProtocolLib compat + if (PipelineUtil.containsCause(cause, ViaCodecException.class)) return; // ProtocolLib compat + super.exceptionCaught(ctx, cause); if (!NMSUtil.isDebugPropertySet()) { cause.printStackTrace(); // Print if CB doesn't already do it diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java index d0b1f4b42..24b8f00b2 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java @@ -6,6 +6,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.exception.CancelDecoderException; +import us.myles.ViaVersion.exception.ViaCodecException; import java.util.List; @@ -36,7 +37,7 @@ public class BungeeDecodeHandler extends MessageToMessageDecoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (cause instanceof CancelDecoderException) return; + if (cause instanceof ViaCodecException) return; super.exceptionCaught(ctx, cause); } } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java index 862c302ec..1ad87bcd6 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java @@ -7,6 +7,7 @@ import io.netty.handler.codec.MessageToMessageEncoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.bungee.util.BungeePipelineUtil; import us.myles.ViaVersion.exception.CancelEncoderException; +import us.myles.ViaVersion.exception.ViaCodecException; import java.util.List; @@ -77,7 +78,7 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (cause instanceof CancelEncoderException) return; + if (cause instanceof ViaCodecException) return; super.exceptionCaught(ctx, cause); } } diff --git a/common/src/main/java/us/myles/ViaVersion/exception/CancelDecoderException.java b/common/src/main/java/us/myles/ViaVersion/exception/CancelDecoderException.java index 11b5522ab..c35e46199 100644 --- a/common/src/main/java/us/myles/ViaVersion/exception/CancelDecoderException.java +++ b/common/src/main/java/us/myles/ViaVersion/exception/CancelDecoderException.java @@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.Via; * Thrown during packet decoding when an incoming packet should be cancelled. * Specifically extends {@link DecoderException} to prevent netty from wrapping the exception. */ -public class CancelDecoderException extends DecoderException { +public class CancelDecoderException extends DecoderException implements ViaCodecException { public static final CancelDecoderException CACHED = new CancelDecoderException("This packet is supposed to be cancelled; If you have debug enabled, you can ignore these") { @Override public Throwable fillInStackTrace() { diff --git a/common/src/main/java/us/myles/ViaVersion/exception/CancelEncoderException.java b/common/src/main/java/us/myles/ViaVersion/exception/CancelEncoderException.java index 9e548084b..047eb1e76 100644 --- a/common/src/main/java/us/myles/ViaVersion/exception/CancelEncoderException.java +++ b/common/src/main/java/us/myles/ViaVersion/exception/CancelEncoderException.java @@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.Via; * Thrown during packet encoding when an outgoing packet should be cancelled. * Specifically extends {@link EncoderException} to prevent netty from wrapping the exception. */ -public class CancelEncoderException extends EncoderException { +public class CancelEncoderException extends EncoderException implements ViaCodecException { public static final CancelEncoderException CACHED = new CancelEncoderException("This packet is supposed to be cancelled; If you have debug enabled, you can ignore these") { @Override public Throwable fillInStackTrace() { diff --git a/common/src/main/java/us/myles/ViaVersion/exception/ViaCodecException.java b/common/src/main/java/us/myles/ViaVersion/exception/ViaCodecException.java new file mode 100644 index 000000000..13e6b6543 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/exception/ViaCodecException.java @@ -0,0 +1,10 @@ +package us.myles.ViaVersion.exception; + +/** + * Shared dummy interface for {@link CancelDecoderException} and {@link CancelEncoderException}. + * + * @see CancelEncoderException + * @see CancelDecoderException + */ +public interface ViaCodecException { +} diff --git a/common/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java b/common/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java index bf5f63cb2..4662812c7 100644 --- a/common/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java +++ b/common/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java @@ -91,13 +91,14 @@ public class PipelineUtil { * @param c The exception to look for * @return True if the stack trace contained it as its cause or if t is an instance of c. */ - public static boolean containsCause(Throwable t, Class c) { - do { - if (t != null) { - if (c.isAssignableFrom(t.getClass())) return true; - t = t.getCause(); + public static boolean containsCause(Throwable t, Class c) { + while (t != null) { + if (c.isAssignableFrom(t.getClass())) { + return true; } - } while (t != null); + + t = t.getCause(); + } return false; } diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java index 8ba9fceaf..88747ff4c 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java @@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.exception.CancelDecoderException; +import us.myles.ViaVersion.exception.ViaCodecException; import us.myles.ViaVersion.util.PipelineUtil; import java.lang.reflect.InvocationTargetException; @@ -52,7 +53,7 @@ public class SpongeDecodeHandler extends ByteToMessageDecoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (cause instanceof CancelDecoderException) return; + if (cause instanceof ViaCodecException) return; super.exceptionCaught(ctx, cause); } } diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeEncodeHandler.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeEncodeHandler.java index c5a54dc44..eb6a9e9a6 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeEncodeHandler.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeEncodeHandler.java @@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.exception.CancelEncoderException; +import us.myles.ViaVersion.exception.ViaCodecException; import us.myles.ViaVersion.handlers.ChannelHandlerContextWrapper; import us.myles.ViaVersion.handlers.ViaHandler; import us.myles.ViaVersion.util.PipelineUtil; @@ -48,7 +49,7 @@ public class SpongeEncodeHandler extends MessageToByteEncoder implements @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (cause instanceof CancelEncoderException) return; + if (cause instanceof ViaCodecException) return; super.exceptionCaught(ctx, cause); } } diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java index 873068556..1c55e6b2b 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java @@ -6,6 +6,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.exception.CancelDecoderException; +import us.myles.ViaVersion.exception.ViaCodecException; import java.util.List; @@ -36,7 +37,7 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (cause instanceof CancelDecoderException) return; + if (cause instanceof ViaCodecException) return; super.exceptionCaught(ctx, cause); } } diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityEncodeHandler.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityEncodeHandler.java index cf6ab39c2..c0091228c 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityEncodeHandler.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityEncodeHandler.java @@ -8,6 +8,7 @@ import io.netty.handler.codec.MessageToMessageDecoder; import io.netty.handler.codec.MessageToMessageEncoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.exception.CancelEncoderException; +import us.myles.ViaVersion.exception.ViaCodecException; import us.myles.ViaVersion.util.PipelineUtil; import java.lang.reflect.InvocationTargetException; @@ -80,7 +81,7 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (cause instanceof CancelEncoderException) return; + if (cause instanceof ViaCodecException) return; super.exceptionCaught(ctx, cause); } }