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 34ffb2667..e8106a9f1 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 @@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageEncoder; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.bungee.util.BungeePipelineUtil; @@ -28,7 +29,7 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder { @Override protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List out) throws Exception { if (bytebuf.readableBytes() == 0) { - throw new CancelException(); + throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED; } boolean needsCompress = false; if (!handledCompression) { diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index f66c43693..ad248bf26 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -167,8 +167,9 @@ public abstract class Protocol { // remap if (protocolPacket.getRemapper() != null) { protocolPacket.getRemapper().remap(packetWrapper); - if (packetWrapper.isCancelled()) - throw new CancelException(); + if (packetWrapper.isCancelled()) { + throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED; + } } } diff --git a/common/src/main/java/us/myles/ViaVersion/exception/CancelException.java b/common/src/main/java/us/myles/ViaVersion/exception/CancelException.java index b71016854..93b5a7349 100644 --- a/common/src/main/java/us/myles/ViaVersion/exception/CancelException.java +++ b/common/src/main/java/us/myles/ViaVersion/exception/CancelException.java @@ -1,4 +1,29 @@ package us.myles.ViaVersion.exception; public class CancelException extends Exception { + public static final CancelException CACHED = new CancelException("Cached - Enable /viaver debug to not use cached exception") { + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } + }; + + public CancelException() { + } + + public CancelException(String message) { + super(message); + } + + public CancelException(String message, Throwable cause) { + super(message, cause); + } + + public CancelException(Throwable cause) { + super(cause); + } + + public CancelException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } } 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 5db88d64a..41beb84e9 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 @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.exception.CancelException; @@ -37,7 +38,7 @@ public class SpongeEncodeHandler extends MessageToByteEncoder { } } if (bytebuf.readableBytes() == 0) { - throw new CancelException(); + throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED; } // Increment sent info.incrementSent(); 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 b671159c5..2ec4e2525 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 @@ -9,6 +9,7 @@ import io.netty.handler.codec.MessageToMessageEncoder; import lombok.NonNull; import lombok.RequiredArgsConstructor; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.exception.CancelException; @@ -28,7 +29,7 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder { @Override protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List out) throws Exception { if (bytebuf.readableBytes() == 0) { - throw new CancelException(); + throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED; } boolean needsCompress = false; if (!handledCompression