/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.core;

import com.destroystokyo.paper.profile.PlayerProfile;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

public class FlatteningWrapper21 extends FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper {

    @Override
    public ItemStack setSkullOwner(String player) {
        ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
        head.editMeta(SkullMeta.class, skullMeta -> {
            try {
                OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.startsWith(".") ? player.substring(1) : player);
                PlayerProfile playerProfile = offlinePlayer.getPlayerProfile();
                playerProfile.complete();
                skullMeta.setPlayerProfile(playerProfile);
            } catch (Exception e) {
                // Ignore
            }
        });
        return head;
    }

    protected static final Object shooting = entityPose.getEnumConstants()[16];
    @Override
    public Object getPose(FlatteningWrapper.EntityPose pose) {
        if (pose == FlatteningWrapper.EntityPose.SHOOTING) return shooting;
        return super.getPose(pose);
    }
}
