<commit_before>package net.wayward_realms.waywardprofessions;

import net.wayward_realms.waywardlib.character.Character;
import net.wayward_realms.waywardlib.professions.ProfessionsPlugin;
import net.wayward_realms.waywardlib.professions.ToolType;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class WaywardProfessions extends JavaPlugin implements ProfessionsPlugin {

    private Map<Integer, ProfessionInfo> professionInfo = new HashMap<>();

    @Override
    public void onEnable() {
        ConfigurationSerialization.registerClass(ProfessionInfo.class);
        registerListeners(new BlockBreakListener(this), new EnchantItemListener(), new InventoryClickListener(this), new PrepareItemCraftListener(this));
        getCommand("efficiency").setExecutor(new EfficiencyCommand(this));
        getCommand("durability").setExecutor(new DurabilityCommand(this));
        getCommand("profession").setExecutor(new ProfessionCommand(this));
    }

    @Override
    public void onDisable() {
        saveState();
    }

    private void registerListeners(Listener... listeners) {
        for (Listener listener : listeners) {
            getServer().getPluginManager().registerEvents(listener, this);
        }
    }

    @Override
    public int getMaxToolDurability(Character character, ToolType toolType) {
        initialiseProfessionInfo(character);
        return professionInfo.get(character.getId()).getMaxToolDurability(toolType);
    }

    public void setMaxToolDurability(Character character, ToolType toolType, int durability) {
        initialiseProfessionInfo(character);
        if (getMaxToolDurability(character, toolType) < durability) {
            if (character.getPlayer().isOnline()) {
                character.getPlayer().getPlayer().sendMessage(getPrefix() + ChatColor.GREEN + "+" + (durability - getMaxToolDurability(character, toolType)) + " maximum " + toolType.toString().toLowerCase().replace('_', ' ') + " durability");
            }
        }
        professionInfo.get(character.getId()).setMaxToolDurability(toolType, durability);
    }

    @Override
    public int getCraftEfficiency(Character character, Material material) {
        initialiseProfessionInfo(character);
        return professionInfo.get(character.getId()).getCraftEfficiency(material);
    }

    public void setCraftEfficiency(Character character, Material material, int efficiency) {
        initialiseProfessionInfo(character);
        if (getCraftEfficiency(character, material) < efficiency) {
            if (character.getPlayer().isOnline()) {
                character.getPlayer().getPlayer().sendMessage(getPrefix() + ChatColor.GREEN + "+" + (efficiency - getCraftEfficiency(character, material)) + " " + material.toString().toLowerCase().replace('_', ' ') + " crafting efficiency");
            }
        }
        professionInfo.get(character.getId()).setCraftEfficiency(material, efficiency);
    }

    @Override
    public int getMiningEfficiency(Character character, Material material) {
        initialiseProfessionInfo(character);
        return professionInfo.get(character.getId()).getMiningEfficiency(material);
    }

    public void setMiningEfficiency(Character character, Material material, int efficiency) {
        initialiseProfessionInfo(character);
        if (getMiningEfficiency(character, material) < efficiency) {
            if (character.getPlayer().isOnline()) {
                character.getPlayer().getPlayer().sendMessage(getPrefix() + ChatColor.GREEN + "+" + (efficiency - getMiningEfficiency(character, material)) + " " + material.toString().toLowerCase().replace('_', ' ') + " mining efficiency");
            }
        }
        professionInfo.get(character.getId()).setMiningEfficiency(material, efficiency);
    }

    @Override
    public int getBrewingEfficiency(Character character) {
        initialiseProfessionInfo(character);
        return professionInfo.get(character.getId()).getBrewingEfficiency();
    }

    public void setBrewingEfficiency(Character character, int efficiency) {
        initialiseProfessionInfo(character);
        if (getBrewingEfficiency(character) < efficiency) {
            if (character.getPlayer().isOnline()) {
                character.getPlayer().getPlayer().sendMessage(getPrefix() + ChatColor.GREEN + "+" + (efficiency - getBrewingEfficiency(character)) + " brewing efficiency");
            }
        }
        professionInfo.get(character.getId()).setBrewingEfficiency(efficiency);
    }

    private void initialiseProfessionInfo(Character character) {
        if (professionInfo.get(character.getId()) == null) {
            professionInfo.put(character.getId(), new ProfessionInfo());
        }
    }

    @Override
    public String getPrefix() {
        return "";
    }

    @Override
    public void loadState() {
        File characterDirectory = new File(getDataFolder(), "characters");
        if (characterDirectory.exists()) {
            for (File file : characterDirectory.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.getPath().endsWith(".yml");
                }
            })) {
                YamlConfiguration characterConfig = new YamlConfiguration();
                try {
                    characterConfig.load(file);
                } catch (IOException | InvalidConfigurationException exception) {
                    exception.printStackTrace();
                }
                ProfessionInfo professionInfo = (ProfessionInfo) characterConfig.get("profession-info");
                try {
                    int characterId = Integer.parseInt(file.getName().replace(".yml", ""));
                    this.professionInfo.put(characterId, professionInfo);
                } catch (NumberFormatException ignore) {}
            }
        }
    }

    @Override
    public void saveState() {
        File characterDirectory = new File(getDataFolder(), "characters");
        for (Map.Entry<Integer, ProfessionInfo> entry : professionInfo.entrySet()) {
            File professionInfoFile = new File(characterDirectory, entry.getKey() + ".yml");
            YamlConfiguration professionInfoConfig = new YamlConfiguration();
            professionInfoConfig.set("profession-info", entry.getValue());
            try {
                professionInfoConfig.save(professionInfoFile);
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
    }

}
<commit_msg>Only send efficiency messages when efficiency is less than 100%, fixes #4<commit_after>package net.wayward_realms.waywardprofessions;

import net.wayward_realms.waywardlib.character.Character;
import net.wayward_realms.waywardlib.professions.ProfessionsPlugin;
import net.wayward_realms.waywardlib.professions.ToolType;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class WaywardProfessions extends JavaPlugin implements ProfessionsPlugin {

    private Map<Integer, ProfessionInfo> professionInfo = new HashMap<>();

    @Override
    public void onEnable() {
        ConfigurationSerialization.registerClass(ProfessionInfo.class);
        registerListeners(new BlockBreakListener(this), new EnchantItemListener(), new InventoryClickListener(this), new PrepareItemCraftListener(this));
        getCommand("efficiency").setExecutor(new EfficiencyCommand(this));
        getCommand("durability").setExecutor(new DurabilityCommand(this));
        getCommand("profession").setExecutor(new ProfessionCommand(this));
    }

    @Override
    public void onDisable() {
        saveState();
    }

    private void registerListeners(Listener... listeners) {
        for (Listener listener : listeners) {
            getServer().getPluginManager().registerEvents(listener, this);
        }
    }

    @Override
    public int getMaxToolDurability(Character character, ToolType toolType) {
        initialiseProfessionInfo(character);
        return professionInfo.get(character.getId()).getMaxToolDurability(toolType);
    }

    public void setMaxToolDurability(Character character, ToolType toolType, int durability) {
        initialiseProfessionInfo(character);
        if (getMaxToolDurability(character, toolType) < durability) {
            if (character.getPlayer().isOnline()) {
                character.getPlayer().getPlayer().sendMessage(getPrefix() + ChatColor.GREEN + "+" + (durability - getMaxToolDurability(character, toolType)) + " maximum " + toolType.toString().toLowerCase().replace('_', ' ') + " durability");
            }
        }
        professionInfo.get(character.getId()).setMaxToolDurability(toolType, durability);
    }

    @Override
    public int getCraftEfficiency(Character character, Material material) {
        initialiseProfessionInfo(character);
        return professionInfo.get(character.getId()).getCraftEfficiency(material);
    }

    public void setCraftEfficiency(Character character, Material material, int efficiency) {
        initialiseProfessionInfo(character);
        if (getCraftEfficiency(character, material) < efficiency && getCraftEfficiency(character, material) < 100) {
            if (character.getPlayer().isOnline()) {
                character.getPlayer().getPlayer().sendMessage(getPrefix() + ChatColor.GREEN + "+" + (efficiency - getCraftEfficiency(character, material)) + " " + material.toString().toLowerCase().replace('_', ' ') + " crafting efficiency");
            }
        }
        professionInfo.get(character.getId()).setCraftEfficiency(material, efficiency);
    }

    @Override
    public int getMiningEfficiency(Character character, Material material) {
        initialiseProfessionInfo(character);
        return professionInfo.get(character.getId()).getMiningEfficiency(material);
    }

    public void setMiningEfficiency(Character character, Material material, int efficiency) {
        initialiseProfessionInfo(character);
        if (getMiningEfficiency(character, material) < efficiency && getMiningEfficiency(character, material) < 100) {
            if (character.getPlayer().isOnline()) {
                character.getPlayer().getPlayer().sendMessage(getPrefix() + ChatColor.GREEN + "+" + (efficiency - getMiningEfficiency(character, material)) + " " + material.toString().toLowerCase().replace('_', ' ') + " mining efficiency");
            }
        }
        professionInfo.get(character.getId()).setMiningEfficiency(material, efficiency);
    }

    @Override
    public int getBrewingEfficiency(Character character) {
        initialiseProfessionInfo(character);
        return professionInfo.get(character.getId()).getBrewingEfficiency();
    }

    public void setBrewingEfficiency(Character character, int efficiency) {
        initialiseProfessionInfo(character);
        if (getBrewingEfficiency(character) < efficiency && getBrewingEfficiency(character) < 100) {
            if (character.getPlayer().isOnline()) {
                character.getPlayer().getPlayer().sendMessage(getPrefix() + ChatColor.GREEN + "+" + (efficiency - getBrewingEfficiency(character)) + " brewing efficiency");
            }
        }
        professionInfo.get(character.getId()).setBrewingEfficiency(efficiency);
    }

    private void initialiseProfessionInfo(Character character) {
        if (professionInfo.get(character.getId()) == null) {
            professionInfo.put(character.getId(), new ProfessionInfo());
        }
    }

    @Override
    public String getPrefix() {
        return "";
    }

    @Override
    public void loadState() {
        File characterDirectory = new File(getDataFolder(), "characters");
        if (characterDirectory.exists()) {
            for (File file : characterDirectory.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.getPath().endsWith(".yml");
                }
            })) {
                YamlConfiguration characterConfig = new YamlConfiguration();
                try {
                    characterConfig.load(file);
                } catch (IOException | InvalidConfigurationException exception) {
                    exception.printStackTrace();
                }
                ProfessionInfo professionInfo = (ProfessionInfo) characterConfig.get("profession-info");
                try {
                    int characterId = Integer.parseInt(file.getName().replace(".yml", ""));
                    this.professionInfo.put(characterId, professionInfo);
                } catch (NumberFormatException ignore) {}
            }
        }
    }

    @Override
    public void saveState() {
        File characterDirectory = new File(getDataFolder(), "characters");
        for (Map.Entry<Integer, ProfessionInfo> entry : professionInfo.entrySet()) {
            File professionInfoFile = new File(characterDirectory, entry.getKey() + ".yml");
            YamlConfiguration professionInfoConfig = new YamlConfiguration();
            professionInfoConfig.set("profession-info", entry.getValue());
            try {
                professionInfoConfig.save(professionInfoFile);
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
    }

}

{'fraction_non_alphanumeric': 0.10866789615548304, 'fraction_numerical': 0.0009221166122854305, 'mean_word_length': 3.1614521841794567, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 9, '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': '2410029', 'n_tokens_mistral': 3618, 'n_tokens_neox': 3477, 'n_words': 629}