<commit_before>package io.github.thatsmusic99.headsplus.managers;

import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import io.github.thatsmusic99.headsplus.HeadsPlus;
import io.github.thatsmusic99.headsplus.config.ConfigMasks;
import io.github.thatsmusic99.headsplus.config.MainConfig;
import io.github.thatsmusic99.headsplus.util.FlagHandler;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.*;
import java.util.concurrent.CompletableFuture;

public class MaskManager {

    private final HashMap<String, MaskInfo> masks = new HashMap<>();
    private static MaskManager instance;
    private final HashMap<String, BukkitRunnable> runningTasks = new HashMap<>();

    public MaskManager() {
        instance = this;
        init();
    }

    public static MaskManager get() {
        return instance;
    }

    public void reload() {
        reset();
        init();
    }

    public void resetMask(Player player) {
        if (!runningTasks.containsKey(player.getUniqueId().toString())) return;
        runningTasks.get(player.getUniqueId().toString()).cancel();
    }

    public void reset() {
        masks.clear();
        runningTasks.values().forEach(BukkitRunnable::cancel);
        runningTasks.clear();
    }

    public void registerMask(String key, MaskInfo headInfo) {
        masks.put(key, headInfo);
    }

    public MaskInfo getMaskInfo(String key) {
        if (key.startsWith("HPM#")) {
            key = key.substring(4);
        }
        return (MaskInfo) masks.getOrDefault(key, new MaskInfo()).clone();
    }

    public boolean isMaskRegistered(String key) {
        if (key.startsWith("HPM#")) {
            key = key.substring(4);
        }
        return masks.containsKey(key);
    }

    public void init() {
        ConfigMasks masksConfig = ConfigMasks.get();
        // Get the config section
        ConfigSection masksSection = masksConfig.getConfigSection("masks");
        if (masksSection == null) return;
        // Get each mask
        for (String key : masksSection.getKeys(false)) {
            try {
                ConfigSection maskSection = masksSection.getConfigSection(key);
                if (maskSection == null) continue;
                //
                MaskInfo info;
                String headInfoStr = Objects.requireNonNull(maskSection.getString("idle"), "No idle texture for " + key + " found!");
                HeadManager.HeadInfo headInfo = HeadManager.get().getHeadInfo(headInfoStr);
                String type = Objects.requireNonNull(maskSection.getString("type"), "No mask type for " + key + " found!");
                switch (type.toLowerCase()) {
                    case "potion":
                        info = new PotionMask(key, headInfo);
                        for (String effectStr : maskSection.getStringList("effects")) {
                            HeadsPlus.debug("Effect: " + effectStr);
                            String[] content = effectStr.split(":");
                            PotionEffectType effectType = PotionEffectType.getByName(content[0]);
                            if (effectType == null)
                                throw new IllegalArgumentException("Mask effect " + content[0] + " is not an existing potion effect! (Mask: " + key + ")");
                            int amplifier = 0;
                            if (content.length > 1) {
                                HeadsPlus.debug("Selected amplifier for " + effectStr + ": " + content[1]);
                                amplifier = Integer.parseInt(content[1]) - 1;
                            }
                            PotionEffect effect = new PotionEffect(effectType, MainConfig.get().getMasks().EFFECT_LENGTH, amplifier);
                            ((PotionMask) info).addEffect(effect);
                        }
                        break;
                    default:
                        throw new IllegalArgumentException("Mask type " + type + " for " + key + " does not exist!");
                }

                registerMask(key, info);
            } catch (NullPointerException | IllegalArgumentException ex) {
                HeadsPlus.get().getLogger().warning("Error received when registering mask " + key + ": " + ex.getMessage());
            }
        }
    }

    public static class MaskInfo extends HeadManager.HeadInfo {

        protected String id;

        public MaskInfo() {
            super();
        }

        public MaskInfo(HeadManager.HeadInfo info, String id) {
            super();
            this.id = id;
            withDisplayName(info.getDisplayName());
            setLore(info.getLore());
            withTexture(info.getPlayer() == null ? info.getTexture() : info.getPlayer());
            withMaterial(info.getMaterial());
        }

        public void run(Player player) {
        }

        @Override
        public CompletableFuture<ItemStack> buildHead() {
            return super.buildHead().thenApply(item -> {
                PersistenceManager.get().setMaskType(item, id);
                HeadsPlus.debug("Implemented mask type " + id);
                return item;
            });
        }

        @Override
        public ItemStack forceBuildHead() {
            ItemStack item = super.forceBuildHead();
            PersistenceManager.get().setMaskType(item, id);
            HeadsPlus.debug("Implemented mask type " + id);
            return item;
        }
    }

    public class PotionMask extends MaskInfo {

        private List<PotionEffect> effects;

        public PotionMask(String id, HeadManager.HeadInfo info) {
            super(info, id);
            this.effects = new ArrayList<>();
        }
<commit_msg>Fixed heads not dropping, whoops<commit_after>package io.github.thatsmusic99.headsplus.managers;

import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import io.github.thatsmusic99.headsplus.HeadsPlus;
import io.github.thatsmusic99.headsplus.config.ConfigMasks;
import io.github.thatsmusic99.headsplus.config.MainConfig;
import io.github.thatsmusic99.headsplus.util.FlagHandler;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.*;
import java.util.concurrent.CompletableFuture;

public class MaskManager {

    private final HashMap<String, MaskInfo> masks = new HashMap<>();
    private static MaskManager instance;
    private final HashMap<String, BukkitRunnable> runningTasks = new HashMap<>();

    public MaskManager() {
        instance = this;
        init();
    }

    public static MaskManager get() {
        return instance;
    }

    public void reload() {
        reset();
        init();
    }

    public void resetMask(Player player) {
        if (!runningTasks.containsKey(player.getUniqueId().toString())) return;
        runningTasks.get(player.getUniqueId().toString()).cancel();
    }

    public void reset() {
        masks.clear();
        runningTasks.values().forEach(BukkitRunnable::cancel);
        runningTasks.clear();
    }

    public void registerMask(String key, MaskInfo headInfo) {
        masks.put(key, headInfo);
    }

    public MaskInfo getMaskInfo(String key) {
        if (key.startsWith("HPM#")) {
            key = key.substring(4);
        }
        return (MaskInfo) masks.getOrDefault(key, new MaskInfo()).clone();
    }

    public boolean isMaskRegistered(String key) {
        if (key.startsWith("HPM#")) {
            key = key.substring(4);
        }
        return masks.containsKey(key);
    }

    public void init() {
        ConfigMasks masksConfig = ConfigMasks.get();
        // Get the config section
        ConfigSection masksSection = masksConfig.getConfigSection("masks");
        if (masksSection == null) return;
        // Get each mask
        for (String key : masksSection.getKeys(false)) {
            try {
                ConfigSection maskSection = masksSection.getConfigSection(key);
                if (maskSection == null) continue;
                //
                MaskInfo info;
                String headInfoStr = Objects.requireNonNull(maskSection.getString("idle"), "No idle texture for " + key + " found!");
                HeadManager.HeadInfo headInfo = HeadManager.get().getHeadInfo(headInfoStr);
                String type = Objects.requireNonNull(maskSection.getString("type"), "No mask type for " + key + " found!");
                switch (type.toLowerCase()) {
                    case "potion":
                        info = new PotionMask(key, headInfo);
                        for (String effectStr : maskSection.getStringList("effects")) {
                            HeadsPlus.debug("Effect: " + effectStr);
                            String[] content = effectStr.split(":");
                            PotionEffectType effectType = PotionEffectType.getByName(content[0]);
                            if (effectType == null)
                                throw new IllegalArgumentException("Mask effect " + content[0] + " is not an existing potion effect! (Mask: " + key + ")");
                            int amplifier = 0;
                            if (content.length > 1) {
                                HeadsPlus.debug("Selected amplifier for " + effectStr + ": " + content[1]);
                                amplifier = Integer.parseInt(content[1]) - 1;
                            }
                            PotionEffect effect = new PotionEffect(effectType, MainConfig.get().getMasks().EFFECT_LENGTH, amplifier);
                            ((PotionMask) info).addEffect(effect);
                        }
                        break;
                    default:
                        throw new IllegalArgumentException("Mask type " + type + " for " + key + " does not exist!");
                }

                registerMask(key, info);
            } catch (NullPointerException | IllegalArgumentException ex) {
                HeadsPlus.get().getLogger().warning("Error received when registering mask " + key + ": " + ex.getMessage());
            }
        }
    }

    public static class MaskInfo extends HeadManager.HeadInfo {

        protected String id;

        public MaskInfo() {
            super();
        }

        public MaskInfo(HeadManager.HeadInfo info, String id) {
            super();
            this.id = id;
            withDisplayName(info.getDisplayName());
            setLore(info.getLore());
            withTexture(info.getPlayer() == null ? info.getTexture() : info.getPlayer());
            withMaterial(info.getMaterial());
        }

        public void run(Player player) {
        }

        @Override
        public CompletableFuture<ItemStack> buildHead() {
            return super.buildHead().thenApply(item -> {
                if (id == null) return item;
                PersistenceManager.get().setMaskType(item, id);
                HeadsPlus.debug("Implemented mask type " + id);
                return item;
            });
        }

        @Override
        public ItemStack forceBuildHead() {
            ItemStack item = super.forceBuildHead();
            if (id == null) return item;
            PersistenceManager.get().setMaskType(item, id);
            HeadsPlus.debug("Implemented mask type " + id);
            return item;
        }
    }

    public class PotionMask extends MaskInfo {

        private List<PotionEffect> effects;

        public PotionMask(String id, HeadManager.HeadInfo info) {
            super(info, id);
            this.effects = new ArrayList<>();
        }

{'fraction_non_alphanumeric': 0.10733316417153006, 'fraction_numerical': 0.003552397868561279, 'mean_word_length': 1.9420253794476239, 'pattern_counts': {'":': 8, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1374986', 'n_tokens_mistral': 3090, 'n_tokens_neox': 2960, 'n_words': 662}