fancydialogs: Add packet listener for custom click actions

This commit is contained in:
Oliver
2025-06-17 21:39:38 +02:00
parent 9e8431938c
commit 31f03ae252
2 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package com.fancyinnovations.fancydialogs.listener;
import de.oliver.fancysitula.api.packets.FS_ServerboundCustomClickActionPacket;
import de.oliver.fancysitula.api.packets.FS_ServerboundPacket;
import de.oliver.fancysitula.api.utils.FS_PacketListener;
import de.oliver.fancysitula.factories.FancySitula;
public class CustomClickActionPacketListener {
private static CustomClickActionPacketListener INSTANCE;
private final FS_PacketListener packetListener;
public CustomClickActionPacketListener() {
packetListener = FancySitula.PACKET_LISTENER_FACTORY.createPacketListener(FS_ServerboundPacket.Type.CUSTOM_CLICK_ACTION);
packetListener.addListener(this::onPacketReceived);
}
public static CustomClickActionPacketListener get() {
if (INSTANCE == null) {
INSTANCE = new CustomClickActionPacketListener();
}
return INSTANCE;
}
private void onPacketReceived(FS_PacketListener.PacketReceivedEvent event) {
if (!(event.packet() instanceof FS_ServerboundCustomClickActionPacket packet)) {
return; // Ignore if the packet is not of the expected type
}
if (!packet.getId().namespace().equals("fancysitula") && !packet.getId().namespace().equals("fancydialogs_dialog_action")) {
return; // Ignore packets not related to FancyDialogs
}
}
public FS_PacketListener getPacketListener() {
return packetListener;
}
}

View File

@@ -10,6 +10,8 @@ public class PlayerJoinListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
CustomClickActionPacketListener.get().getPacketListener().inject(event.getPlayer());
boolean isNewPlayer = !event.getPlayer().hasPlayedBefore();
if (FancyDialogsPlugin.get().getFancyDialogsConfig().getLogLevel().equalsIgnoreCase("debug")) {
isNewPlayer = true;