Fix Forge plugin msg messenger (#3894)

Co-authored-by: powercas_gamer <cas@mizule.dev>
This commit is contained in:
Luck 2024-05-26 14:19:36 +01:00
parent b5400f885b
commit c3802c2a5a
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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)
}
}