package eu.mhsl.minenet.minigames.skin;

import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.PlayerSkin;
import net.minestom.server.timer.TaskSchedule;

import java.util.HashMap;
import java.util.Map;

public class SkinCache {
    private static final Map<String, PlayerSkin> skins = new HashMap<>();

    public static PlayerSkin getSkin(String p) {
        if(!skins.containsKey(p)) skins.put(p, PlayerSkin.fromUsername(p));
        return skins.get(p);
    }

    public static void applySkin(Player p) {
        MinecraftServer.getSchedulerManager().scheduleTask(() -> {
            p.setSkin(SkinCache.getSkin(p.getUsername()));
            return TaskSchedule.stop();
        }, TaskSchedule.millis(500));
    }
}
