<commit_before>package com.forgeessentials.servervote;

import com.forgeessentials.core.moduleLauncher.config.IConfigLoader.ConfigLoaderBase;
import com.forgeessentials.util.OutputHandler;
import cpw.mods.fml.common.registry.GameData;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;

import javax.xml.bind.DatatypeConverter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.RSAKeyGenParameterSpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;

public class ConfigServerVote extends ConfigLoaderBase {
    private static final String category = "ServerVote";


    public static boolean allowOfflineVotes;
    public static String msgAll = "";
    public static String msgVoter = "";
    public static ArrayList<ItemStack> freeStuff = new ArrayList<ItemStack>();

    public File keyFolder;

    public KeyPair keyPair;
    public static PrivateKey privateKey;
    public PublicKey publicKey;

    public static String hostname;
    public static Integer port;

    public boolean flatfileLog;

    @Override
    public void load(Configuration config, boolean isReload)
    {
        String subcat = category + ".Votifier";
        config.addCustomCategoryComment(subcat, "This is for votifier compatibility only.");

        hostname = config.get(subcat, "hostname", "").getString();
        port = config.get(subcat, "port", "8192").getInt();

        allowOfflineVotes = config.get(category, "allowOfflineVotes", true, "If false, votes of offline players will be canceled.").getBoolean(true);
        msgAll = config.get(category, "msgAll", "%player has voted for this server on %service.", "You can use color codes (&), %player and %service")
                .getString();
        msgVoter = config.get(category, "msgVoter", "Thanks for voting for our server!", "You can use color codes (&), %player and %service").getString();

        flatfileLog = config.get(category, "flatFileLog", true, "Log the votes in \"votes.log\"").getBoolean(true);

        String[] tempArray = config.get(category, "rewards", new String[] { }, "Format is like this: [amount]x<id>[:meta]").getStringList();

        freeStuff.clear();
        for (String temp : tempArray)
        {
            int amount = 1;
            int meta = 0;

            if (temp.contains("x"))
            {
                String[] temp2 = temp.split("x");
                amount = Integer.parseInt(temp2[0]);
                temp = temp2[1];
            }

            if (temp.contains(":"))
            {
                String[] temp2 = temp.split(":");
                meta = Integer.parseInt(temp2[2]);
                temp = temp2[0] + ":" + temp2[1];
            }

            Item item = GameData.getItemRegistry().getObject(temp);

            ItemStack stack = new ItemStack(item, amount, meta);

            OutputHandler.felog.finer(stack.toString());

            freeStuff.add(stack);
        }

        loadKeys();
    }

    private void loadKeys()
    {
        keyFolder = new File(ModuleServerVote.moduleDir, "RSA");
        File publicFile = new File(keyFolder, "public.key");
        File privateFile = new File(keyFolder, "private.key");

        if (!keyFolder.exists() || !publicFile.exists() || !privateFile.exists())
        {<commit_msg>Fix #1317<commit_after>package com.forgeessentials.servervote;

import com.forgeessentials.core.moduleLauncher.config.IConfigLoader.ConfigLoaderBase;
import com.forgeessentials.util.OutputHandler;
import cpw.mods.fml.common.registry.GameData;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;

import javax.xml.bind.DatatypeConverter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.RSAKeyGenParameterSpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;

public class ConfigServerVote extends ConfigLoaderBase {
    private static final String category = "ServerVote";


    public static boolean allowOfflineVotes;
    public static String msgAll = "";
    public static String msgVoter = "";
    public static ArrayList<ItemStack> freeStuff = new ArrayList<ItemStack>();

    public File keyFolder;

    public KeyPair keyPair;
    public static PrivateKey privateKey;
    public PublicKey publicKey;

    public static String hostname;
    public static Integer port;

    public boolean flatfileLog;

    @Override
    public void load(Configuration config, boolean isReload)
    {
        String subcat = category + ".Votifier";
        config.addCustomCategoryComment(subcat, "This is for votifier compatibility only.");

        hostname = config.get(subcat, "hostname", "").getString();
        port = config.get(subcat, "port", "8192").getInt();

        allowOfflineVotes = config.get(category, "allowOfflineVotes", true, "If false, votes of offline players will be canceled.").getBoolean(true);
        msgAll = config.get(category, "msgAll", "%player has voted for this server on %service.", "You can use color codes (&), %player and %service")
                .getString();
        msgVoter = config.get(category, "msgVoter", "Thanks for voting for our server!", "You can use color codes (&), %player and %service").getString();

        flatfileLog = config.get(category, "flatFileLog", true, "Log the votes in \"votes.log\"").getBoolean(true);

        String[] tempArray = config.get(category, "rewards", new String[] { }, "Format is like this: [amount]x<id>[:meta]").getStringList();

        freeStuff.clear();
        for (String temp : tempArray)
        {
            int amount = 1;
            int meta = 0;

            if (temp.contains("x"))
            {
                String[] temp2 = temp.split("x");
                amount = Integer.parseInt(temp2[0]);
                temp = temp2[1];
            }

            if (temp.contains(":"))
            {
                String[] temp2 = temp.split(":");
                meta = Integer.parseInt(temp2[2]);
                temp = temp2[0] + ":" + temp2[1];
            }

            Item item = GameData.getItemRegistry().getObject(temp);

            ItemStack stack = new ItemStack(item, amount, meta);

            OutputHandler.felog.finer(stack.getUnlocalizedName());

            freeStuff.add(stack);
        }

        loadKeys();
    }

    private void loadKeys()
    {
        keyFolder = new File(ModuleServerVote.moduleDir, "RSA");
        File publicFile = new File(keyFolder, "public.key");
        File privateFile = new File(keyFolder, "private.key");

        if (!keyFolder.exists() || !publicFile.exists() || !privateFile.exists())
        {
{'fraction_non_alphanumeric': 0.11825726141078838, 'fraction_numerical': 0.006639004149377593, 'mean_word_length': 3.0083148558758315, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7487799', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1979, 'n_words': 505}