package me.km.networking;

import java.util.function.Supplier;
import me.km.Server;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkEvent;

public class PlayerLeftClickEmpty {
    public static void writeBytes(PlayerLeftClickEmpty pd, PacketBuffer buf) {
    }

    public static PlayerLeftClickEmpty fromBytes(PacketBuffer buf) {
        return new PlayerLeftClickEmpty();
    }

    public static void handle(PlayerLeftClickEmpty pd, Supplier<NetworkEvent.Context> context) {
        context.get().enqueueWork(() -> {
            ServerPlayerEntity p = context.get().getSender();
            if(p.getServer() != null && p.getServer().isDedicatedServer()) {
                handle(p);
            }
        });
        context.get().setPacketHandled(true);
    }

    @OnlyIn(Dist.DEDICATED_SERVER)
    private static void handle(ServerPlayerEntity p) {
        Server.scriptEvents.onEmptyLeftClick(p);
    }
}
