package net.minecraft.server.players;

import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.WorldServer;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.nbt.NBTTagCompound;

import com.bergerkiller.bukkit.common.nbt.CommonTagCompound;

class PlayerList {
    public final (List<org.bukkit.entity.Player) List<EntityPlayer> players;

    //TODO: Is this actually used for anything at the moment?
#if version >= 1.21.9
    public int getMaxPlayers();
    public void setMaxPlayers(int maxPlayers) {
        // Defer to server
        ((net.minecraft.server.dedicated.DedicatedServer) instance.getServer()).setMaxPlayers(maxPlayers);
    }
#else
    #require PlayerList protected int maxPlayers;

    public int getMaxPlayers() { return instance#maxPlayers; }
    public void setMaxPlayers(int maxPlayers) { instance#maxPlayers = maxPlayers; }
#endif

    public (CommonTagCompound) NBTTagCompound migratePlayerData((CommonTagCompound) NBTTagCompound playerProfileData) {
#if version >= 1.20.5
        #require net.minecraft.world.level.storage.WorldNBTStorage protected final com.mojang.datafixers.DataFixer fixerUpper;
        net.minecraft.world.level.storage.WorldNBTStorage storage = instance.playerIo;
        com.mojang.datafixers.DataFixer fixerUpper = storage#fixerUpper;

        int dataVersion = net.minecraft.nbt.GameProfileSerializer.getDataVersion(playerProfileData, -1);
        return net.minecraft.util.datafix.DataFixTypes.PLAYER.updateToCurrentVersion(fixerUpper, playerProfileData, dataVersion);
#else
        return playerProfileData;
#endif
    }

#if version >= 1.18
    public void savePlayers:saveAll();
    protected void savePlayerFile:save((org.bukkit.entity.Player) EntityPlayer entityplayer);
#else
    public void savePlayers();
    protected void savePlayerFile((org.bukkit.entity.Player) EntityPlayer entityplayer);
#endif

#if version >= 1.18
    public void sendRawPacketNearby((org.bukkit.World) WorldServer world, double x, double y, double z, double radius, (Object) Packet<?> packet) {
        instance.broadcast((EntityHuman) null, x, y, z, radius, world.dimension(), packet);
    }
#elseif version >= 1.16
    public void sendRawPacketNearby((org.bukkit.World) WorldServer world, double x, double y, double z, double radius, (Object) Packet<?> packet) {
        instance.sendPacketNearby((EntityHuman) null, x, y, z, radius, world.getDimensionKey(), packet);
    }
#elseif version >= 1.14.1
    public void sendRawPacketNearby((org.bukkit.World) WorldServer world, double x, double y, double z, double radius, (Object) Packet<?> packet) {
        instance.sendPacketNearby((EntityHuman) null, x, y, z, radius, world.worldProvider.getDimensionManager().getType(), packet);
    }
#elseif version >= 1.9
    public void sendRawPacketNearby((org.bukkit.World) WorldServer world, double x, double y, double z, double radius, (Object) Packet<?> packet) {
        instance.sendPacketNearby((EntityHuman) null, x, y, z, radius, world.dimension, packet);
    }
#else
    public void sendRawPacketNearby((org.bukkit.World) WorldServer world, double x, double y, double z, double radius, (Object) Packet packet) {
        instance.sendPacketNearby((EntityHuman) null, x, y, z, radius, world.dimension, packet);
    }
#endif
}
