<commit_before>/******************************************************************************
 * Copyright (c) 2014, <NAME>                                         *
 *                                                                            *
 * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 ******************************************************************************/

package info.faceland.beast;

import info.faceland.api.FacePlugin;
import info.faceland.facecore.shade.nun.ivory.config.VersionedIvoryConfiguration;
import info.faceland.facecore.shade.nun.ivory.config.VersionedIvoryYamlConfiguration;
import info.faceland.facecore.shade.nun.ivory.config.settings.IvorySettings;
import info.faceland.utils.StringConverter;
import net.objecthunter.exp4j.ExpressionBuilder;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;
import org.bukkit.event.HandlerList;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BeastPlugin extends FacePlugin {

    private Map<EntityType, BeastData> beastDataMap;
    private VersionedIvoryYamlConfiguration configYAML;
    private VersionedIvoryYamlConfiguration monstersYAML;
    private VersionedIvoryYamlConfiguration replacementsYAML;
    private IvorySettings settings;
    private BeastTask task;

    @Override
    public void preEnable() {
        beastDataMap = new HashMap<>();

        configYAML = new VersionedIvoryYamlConfiguration(new File(getDataFolder(), "config.yml"),
                                                         getResource("config.yml"),
                                                         VersionedIvoryConfiguration.VersionUpdateType
                                                                 .BACKUP_AND_UPDATE);
        if (configYAML.update()) {
            getLogger().info("Updating config.yml");
        }
        monstersYAML = new VersionedIvoryYamlConfiguration(new File(getDataFolder(), "monsters.yml"),
                                                           getResource("monsters.yml"),
                                                           VersionedIvoryConfiguration.VersionUpdateType
                                                                   .BACKUP_AND_UPDATE);
        if (monstersYAML.update()) {
            getLogger().info("Updating monsters.yml");
        }
        replacementsYAML = new VersionedIvoryYamlConfiguration(new File(getDataFolder(), "replacements.yml"),
                                                               getResource("replacements.yml"),
                                                               VersionedIvoryConfiguration.VersionUpdateType
                                                                       .BACKUP_AND_UPDATE);
        if (replacementsYAML.update()) {
            getLogger().info("Updating replacements.yml");
        }

        settings = new IvorySettings();

        task = new BeastTask(this);
    }

    @Override
    public void enable() {
        settings.load(configYAML, replacementsYAML, monstersYAML);

        for (String key : monstersYAML.getKeys(false)) {
            if (!monstersYAML.isConfigurationSection(key)) {
                continue;
            }
            EntityType entityType = EntityType.fromName(key);
            if (entityType == null) {
                continue;
            }
            ConfigurationSection cs = monstersYAML.getConfigurationSection(key);
            BeastData data = new BeastData(entityType);
            data.setNameFormat(cs.getString("name"));
            String healthExpStr = cs.getString("health");
            String damageExpStr = cs.getString("damage");
            String experienceExpStr = cs.getString("experience");
            data.setHealthExpression(new ExpressionBuilder(healthExpStr).variables("LEVEL").build());
            data.setDamageExpression(new ExpressionBuilder(damageExpStr).variables("LEVEL").build());
            data.setExperienceExpression(new ExpressionBuilder(experienceExpStr).variables("LEVEL").build());
            if (cs.isConfigurationSection("potion-effects")) {
                Map<Integer, List<PotionEffect>> effects = new HashMap<>();
                ConfigurationSection peCS = cs.getConfigurationSection("potion-effects");
                for (String k : peCS.getKeys(false)) {
                    List<String> list = peCS.getStringList(k);
                    List<PotionEffect> pe = new ArrayList<>();
                    for (String s : list) {
                        PotionEffect pot = parsePotionEffect(s);
                        if (pot != null) {
                            pe.add(pot);
                        }
                    }
                    effects.put(StringConverter.toInt(k), pe);
                }
                data.setPotionEffectMap(effects);
            }
            if (cs.isConfigurationSection("drops")) {
                List<DropData> drops = new ArrayList<>();
                ConfigurationSection dCS = cs.getConfigurationSection("drops");
                for (String k : dCS.getKeys(false)) {
                    if (!dCS.isConfigurationSection(k)) {
                        continue;
                    }
                    ConfigurationSection inner = dCS.getConfigurationSection(k);
                    DropData dropData = new DropData(StringConverter.toMaterial(k), inner.getInt("min-amount"),
                                                     inner.getInt("max-amount"), inner.getDouble("chance"));
                    drops.add(dropData);
                }
                data.setDrops(drops);
            }
            beastDataMap.put(entityType, data);
        }
    }

    @Override
    public void postEnable() {
        Bukkit.getPluginManager().registerEvents(new BeastListener(this), this);
        task.runTaskTimer(this, 20L * 5, 20L * 5);
    }

    @Override
    public void preDisable() {<commit_msg>never have AIR for DropData<commit_after>/******************************************************************************
 * Copyright (c) 2014, <NAME>                                         *
 *                                                                            *
 * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 ******************************************************************************/

package info.faceland.beast;

import info.faceland.api.FacePlugin;
import info.faceland.facecore.shade.nun.ivory.config.VersionedIvoryConfiguration;
import info.faceland.facecore.shade.nun.ivory.config.VersionedIvoryYamlConfiguration;
import info.faceland.facecore.shade.nun.ivory.config.settings.IvorySettings;
import info.faceland.utils.StringConverter;
import net.objecthunter.exp4j.ExpressionBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;
import org.bukkit.event.HandlerList;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class BeastPlugin extends FacePlugin {

    private Map<EntityType, BeastData> beastDataMap;
    private VersionedIvoryYamlConfiguration configYAML;
    private VersionedIvoryYamlConfiguration monstersYAML;
    private VersionedIvoryYamlConfiguration replacementsYAML;
    private IvorySettings settings;
    private BeastTask task;

    @Override
    public void preEnable() {
        beastDataMap = new HashMap<>();

        configYAML = new VersionedIvoryYamlConfiguration(new File(getDataFolder(), "config.yml"),
                                                         getResource("config.yml"),
                                                         VersionedIvoryConfiguration.VersionUpdateType
                                                                 .BACKUP_AND_UPDATE);
        if (configYAML.update()) {
            getLogger().info("Updating config.yml");
        }
        monstersYAML = new VersionedIvoryYamlConfiguration(new File(getDataFolder(), "monsters.yml"),
                                                           getResource("monsters.yml"),
                                                           VersionedIvoryConfiguration.VersionUpdateType
                                                                   .BACKUP_AND_UPDATE);
        if (monstersYAML.update()) {
            getLogger().info("Updating monsters.yml");
        }
        replacementsYAML = new VersionedIvoryYamlConfiguration(new File(getDataFolder(), "replacements.yml"),
                                                               getResource("replacements.yml"),
                                                               VersionedIvoryConfiguration.VersionUpdateType
                                                                       .BACKUP_AND_UPDATE);
        if (replacementsYAML.update()) {
            getLogger().info("Updating replacements.yml");
        }

        settings = new IvorySettings();

        task = new BeastTask(this);
    }

    @Override
    public void enable() {
        settings.load(configYAML, replacementsYAML, monstersYAML);

        for (String key : monstersYAML.getKeys(false)) {
            if (!monstersYAML.isConfigurationSection(key)) {
                continue;
            }
            EntityType entityType = EntityType.fromName(key);
            if (entityType == null) {
                continue;
            }
            ConfigurationSection cs = monstersYAML.getConfigurationSection(key);
            BeastData data = new BeastData(entityType);
            data.setNameFormat(cs.getString("name"));
            String healthExpStr = cs.getString("health");
            String damageExpStr = cs.getString("damage");
            String experienceExpStr = cs.getString("experience");
            data.setHealthExpression(new ExpressionBuilder(healthExpStr).variables("LEVEL").build());
            data.setDamageExpression(new ExpressionBuilder(damageExpStr).variables("LEVEL").build());
            data.setExperienceExpression(new ExpressionBuilder(experienceExpStr).variables("LEVEL").build());
            if (cs.isConfigurationSection("potion-effects")) {
                Map<Integer, List<PotionEffect>> effects = new HashMap<>();
                ConfigurationSection peCS = cs.getConfigurationSection("potion-effects");
                for (String k : peCS.getKeys(false)) {
                    List<String> list = peCS.getStringList(k);
                    List<PotionEffect> pe = new ArrayList<>();
                    for (String s : list) {
                        PotionEffect pot = parsePotionEffect(s);
                        if (pot != null) {
                            pe.add(pot);
                        }
                    }
                    effects.put(StringConverter.toInt(k), pe);
                }
                data.setPotionEffectMap(effects);
            }
            if (cs.isConfigurationSection("drops")) {
                List<DropData> drops = new ArrayList<>();
                ConfigurationSection dCS = cs.getConfigurationSection("drops");
                for (String k : dCS.getKeys(false)) {
                    if (!dCS.isConfigurationSection(k)) {
                        continue;
                    }
                    ConfigurationSection inner = dCS.getConfigurationSection(k);
                    DropData dropData = new DropData(StringConverter.toMaterial(k), inner.getInt("min-amount"),
                                                     inner.getInt("max-amount"), inner.getDouble("chance"));
                    if (dropData.getMaterial() == Material.AIR) {
                        continue;
                    }
                    drops.add(dropData);
                }
                data.setDrops(drops);
            }
            beastDataMap.put(entityType, data);
        }
    }

    @Override
    public void postEnable() {
        Bukkit.getPluginManager().registerEvents(new BeastListener(this), this);
        task.runTaskTimer(this, 20L * 5, 20L * 5);
    }

    @Override
    public void preDisable() {
{'fraction_non_alphanumeric': 0.1060474537037037, 'fraction_numerical': 0.001591435185185185, 'mean_word_length': 1.8766125676238037, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '129715', 'n_tokens_mistral': 3298, 'n_tokens_neox': 3060, 'n_words': 712}