diff --git a/forge/src/main/java/me/lucko/luckperms/forge/LPForgePlugin.java b/forge/src/main/java/me/lucko/luckperms/forge/LPForgePlugin.java index 55356d5e9..e45fee008 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/LPForgePlugin.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/LPForgePlugin.java @@ -49,6 +49,7 @@ import me.lucko.luckperms.forge.listeners.ForgeCommandListUpdater; import me.lucko.luckperms.forge.listeners.ForgeConnectionListener; import me.lucko.luckperms.forge.listeners.ForgePlatformListener; import me.lucko.luckperms.forge.messaging.ForgeMessagingFactory; +import me.lucko.luckperms.forge.messaging.PluginMessageMessenger; import me.lucko.luckperms.forge.service.ForgePermissionHandlerListener; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; @@ -100,6 +101,8 @@ public class LPForgePlugin extends AbstractLuckPermsPlugin { this.commandManager = new ForgeCommandExecutor(this); this.bootstrap.registerListeners(this.commandManager); + + PluginMessageMessenger.registerChannel(); } @Override diff --git a/forge/src/main/java/me/lucko/luckperms/forge/messaging/PluginMessageMessenger.java b/forge/src/main/java/me/lucko/luckperms/forge/messaging/PluginMessageMessenger.java index 604865019..6b8278225 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/messaging/PluginMessageMessenger.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/messaging/PluginMessageMessenger.java @@ -45,10 +45,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; public class PluginMessageMessenger extends AbstractPluginMessageMessenger implements Messenger { - private static final ResourceLocation CHANNEL = new ResourceLocation(AbstractPluginMessageMessenger.CHANNEL); + private static final ResourceLocation CHANNEL_ID = new ResourceLocation(AbstractPluginMessageMessenger.CHANNEL); + private static final EventNetworkChannel CHANNEL = ChannelBuilder.named(CHANNEL_ID).eventNetworkChannel(); private final LPForgePlugin plugin; - private EventNetworkChannel channel; public PluginMessageMessenger(LPForgePlugin plugin, IncomingMessageConsumer consumer) { super(consumer); @@ -56,8 +56,7 @@ public class PluginMessageMessenger extends AbstractPluginMessageMessenger imple } public void init() { - this.channel = ChannelBuilder.named(CHANNEL).eventNetworkChannel(); - this.channel.addListener(event -> { + CHANNEL.addListener(event -> { byte[] buf = new byte[event.getPayload().readableBytes()]; event.getPayload().readBytes(buf); @@ -83,7 +82,7 @@ public class PluginMessageMessenger extends AbstractPluginMessageMessenger imple FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer()); byteBuf.writeBytes(buf); - this.channel.send(byteBuf, PacketDistributor.PLAYER.with(player)); + CHANNEL.send(byteBuf, PacketDistributor.PLAYER.with(player)); SchedulerTask t = taskRef.getAndSet(null); if (t != null) { @@ -93,4 +92,9 @@ public class PluginMessageMessenger extends AbstractPluginMessageMessenger imple taskRef.set(task); } + public static void registerChannel() { + // do nothing - the channels are registered in the static initializer, we just + // need to make sure that is called (which it will be if this method runs) + } + }