mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancydialogs: Add packet listener for custom click actions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user