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