From a75d3830011a6d6c3418a6d2d10a83f4069c0034 Mon Sep 17 00:00:00 2001 From: Pasqual Koschmieder Date: Wed, 3 Aug 2022 02:59:33 +0200 Subject: [PATCH] fix injection exception when plugin is disabled (#1798) --- .../InjectionChannelInboundHandler.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/comphenix/protocol/injector/netty/manager/InjectionChannelInboundHandler.java b/src/main/java/com/comphenix/protocol/injector/netty/manager/InjectionChannelInboundHandler.java index fd27d06e..b69bca2c 100644 --- a/src/main/java/com/comphenix/protocol/injector/netty/manager/InjectionChannelInboundHandler.java +++ b/src/main/java/com/comphenix/protocol/injector/netty/manager/InjectionChannelInboundHandler.java @@ -31,14 +31,19 @@ final class InjectionChannelInboundHandler extends ChannelInboundHandlerAdapter ctx.fireChannelActive(); // the channel is now active, at this point minecraft has eventually prepared everything in the connection - // of the player so that we can come in and hook as we are after the minecraft handler - try { - this.factory.fromChannel(ctx.channel(), this.listener, this.playerFactory).inject(); - } catch (Exception exception) { - this.listener.getReporter().reportDetailed(this.listener, Report.newBuilder(CANNOT_INJECT_CHANNEL) - .messageParam(ctx.channel()) - .error(exception) - .build()); + // of the player so that we can come in and hook as we are after the minecraft handler. + // We're first checking if the factory is still open, just might be a delay between accepting the connection + // (which adds this handler to the pipeline) and the actual channelActive call. If the injector is closed at + // that point we might accidentally trigger class loads which result in exceptions. + if (!this.factory.isClosed()) { + try { + this.factory.fromChannel(ctx.channel(), this.listener, this.playerFactory).inject(); + } catch (Exception exception) { + this.listener.getReporter().reportDetailed(this, Report.newBuilder(CANNOT_INJECT_CHANNEL) + .messageParam(ctx.channel()) + .error(exception) + .build()); + } } // remove this handler from the pipeline now to prevent multiple injections