packets: Add packet listener

This commit is contained in:
Oliver
2025-06-15 17:57:51 +02:00
committed by Oliver
parent 8c569f90d5
commit 627f50467c
10 changed files with 256 additions and 2 deletions

View File

@@ -0,0 +1,30 @@
package de.oliver.fancysitula.api.packets;
import net.kyori.adventure.key.Key;
import java.util.Optional;
public class FS_ServerboundCustomClickActionPacket extends FS_ServerboundPacket {
private final Key id;
private final Optional<String> payload;
public FS_ServerboundCustomClickActionPacket(Type type, Key id, Optional<String> payload) {
super(type);
this.id = id;
this.payload = payload;
}
public Key getId() {
return id;
}
public Optional<String> getPayload() {
return payload;
}
@Override
public Type getType() {
return super.getType();
}
}

View File

@@ -0,0 +1,30 @@
package de.oliver.fancysitula.api.packets;
public abstract class FS_ServerboundPacket {
protected final Type type;
public FS_ServerboundPacket(Type type) {
this.type = type;
}
public Type getType() {
return type;
}
public enum Type {
ALL("*"),
CUSTOM_CLICK_ACTION("ServerboundCustomClickActionPacket"),
;
private String packetClassName;
Type(String packetClassName) {
this.packetClassName = packetClassName;
}
public String getPacketClassName() {
return packetClassName;
}
}
}

View File

@@ -0,0 +1,35 @@
package de.oliver.fancysitula.api.utils;
import de.oliver.fancysitula.api.packets.FS_ServerboundPacket;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public abstract class FS_PacketListener {
protected final FS_ServerboundPacket.Type packet;
protected final List<Consumer<PacketReceivedEvent>> listeners;
public FS_PacketListener(FS_ServerboundPacket.Type packet) {
this.packet = packet;
this.listeners = new ArrayList<>();
}
public abstract void inject(Player player);
public void addListener(Consumer<PacketReceivedEvent> listener) {
listeners.add(listener);
}
public FS_ServerboundPacket.Type getPacket() {
return packet;
}
public record PacketReceivedEvent(
FS_ServerboundPacket packet,
Player player
) {
}
}