package dev.latvian.mods.kubejs.net;

import dev.latvian.mods.kubejs.player.KubePlayerEvent;
import dev.latvian.mods.kubejs.typings.Info;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
import org.jspecify.annotations.Nullable;

@Info("""
	Invoked when a network packet is received.
	
	Note that the behaviour of this event is depending on the **script type**.
	
	In `server_scripts`, this event is invoked on the server side when a packet is received from a client.
	
	In `client_scripts`, this event is invoked on the client side when a packet is received from the server.
	""")
public class NetworkKubeEvent implements KubePlayerEvent {
	private final Player player;
	private final String channel;
	private final @Nullable CompoundTag data;

	public NetworkKubeEvent(Player p, String c, @Nullable CompoundTag d) {
		player = p;
		channel = c;
		data = d;
	}

	@Override
	@Info("The player that sent the packet. Always `Minecraft.player` in `client_scripts`.")
	public Player getEntity() {
		return player;
	}

	@Info("The channel of the packet.")
	public String getChannel() {
		return channel;
	}

	@Nullable
	@Info("The data of the packet.")
	public CompoundTag getData() {
		return data;
	}
}