<commit_before>package io.minimum.minecraft.superbvote.votes.rewards.matchers;

import com.google.common.collect.ImmutableList;
import io.minimum.minecraft.superbvote.SuperbVote;
import org.bukkit.configuration.ConfigurationSection;

import javax.script.ScriptException;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;

public class RewardMatchers {
    public static List<RewardMatcher> getMatchers(ConfigurationSection section) {
        if (section == null) return Collections.emptyList();
        List<RewardMatcher> matchers = new ArrayList<>();

        // permission: <permission>
        String perm = section.getString("permission", null);
        if (perm != null) {
            if (!SuperbVote.getPlugin().getConfig().getBoolean("require-online")) {
                SuperbVote.getPlugin().getLogger().warning("'permission' vote rewards require that the player be online. Set 'require-online' to 'true' in your configuration.");
            }
            matchers.add(new PermissionRewardMatcher(perm));
        }

        // chance-fractional: <chance>
        Object chanceFracObject = section.get("chance-fractional");
        Object chanceObject = section.get("chance");
        if (chanceFracObject != null && chanceFracObject instanceof Integer) {
            if ((int) chanceFracObject < 1) {
                SuperbVote.getPlugin().getLogger().severe("Fraction " + chanceFracObject + " is not valid; must be 1 or more.");
            } else {
                matchers.add(new ChanceFractionalRewardMatcher((int) chanceFracObject));
            }
        } else if (chanceObject != null && chanceObject instanceof Integer) {
            SuperbVote.getPlugin().getLogger().warning("The 'chance' vote matcher will be switched to be based on percentages out of 100% in a future release. Use 'chance-fractional' to " +
                    "retain the current behavior, or migrate to a percentage matcher by specifying 'chance-percentage' in your configuration.");
            if ((int) chanceFracObject < 1) {
                SuperbVote.getPlugin().getLogger().severe("Fraction " + chanceObject + " is not valid; must be 1 or more.");
            } else {
                matchers.add(new ChanceFractionalRewardMatcher((int) chanceObject));
            }
        }

        // chance-percentage: <chance>
        Object chancePerObject = section.get("chance-percentage");
        if (chancePerObject != null && chancePerObject instanceof Integer) {
            int chancePerInt = (int) chancePerObject;
            if (chancePerInt > 0 && chancePerInt < 100) {
                matchers.add(new ChancePercentageRewardMatcher(chancePerInt));
            } else {
                SuperbVote.getPlugin().getLogger().severe("Percentage " + chancePerInt + " is not valid; must be between 1 and 99.");
            }
        }

        // service: <service> or services: <services>
        String service = section.getString("service", null);
        if (service != null) {
            matchers.add(new ServiceRewardMatcher(ImmutableList.of(service)));
        }
        List<String> services = section.getStringList("services");
        if (service == null && services != null && !services.isEmpty()) {
            matchers.add(new ServiceRewardMatcher(services));
        }

        // cumulative-votes: <votes>
        Object cumulativeObject = section.get("cumulative-votes");
        if (cumulativeObject != null && cumulativeObject instanceof Integer) {
            matchers.add(new CumulativeVotesRewardMatcher((int) cumulativeObject));
        }

        // script: <path>
        String script = section.getString("script");
        if (script != null) {
            try {
                matchers.add(new ScriptRewardMatcher(Paths.get(script)));
            } catch (IOException | ScriptException e) {
                SuperbVote.getPlugin().getLogger().log(Level.SEVERE, "Unable to parse script " + script, e);
            }
        }

        // world: <world> or worlds: <worlds>
        String world = section.getString("world", null);
        if (world != null) {
            matchers.add(new WorldRewardMatcher(ImmutableList.of(world)));
        }
        List<String> worlds = section.getStringList("worlds");
        if (world == null && worlds != null && !worlds.isEmpty()) {
            matchers.add(new WorldRewardMatcher(worlds));
        }

        return matchers;
    }
}
<commit_msg>Fix #30<commit_after>package io.minimum.minecraft.superbvote.votes.rewards.matchers;

import com.google.common.collect.ImmutableList;
import io.minimum.minecraft.superbvote.SuperbVote;
import org.bukkit.configuration.ConfigurationSection;

import javax.script.ScriptException;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;

public class RewardMatchers {
    public static List<RewardMatcher> getMatchers(ConfigurationSection section) {
        if (section == null) return Collections.emptyList();
        List<RewardMatcher> matchers = new ArrayList<>();

        // permission: <permission>
        String perm = section.getString("permission", null);
        if (perm != null) {
            if (!SuperbVote.getPlugin().getConfig().getBoolean("require-online")) {
                SuperbVote.getPlugin().getLogger().warning("'permission' vote rewards require that the player be online. Set 'require-online' to 'true' in your configuration.");
            }
            matchers.add(new PermissionRewardMatcher(perm));
        }

        // chance-fractional: <chance>
        Object chanceFracObject = section.get("chance-fractional");
        Object chanceObject = section.get("chance");
        if (chanceFracObject != null && chanceFracObject instanceof Integer) {
            if ((int) chanceFracObject < 1) {
                SuperbVote.getPlugin().getLogger().severe("Fraction " + chanceFracObject + " is not valid; must be 1 or more.");
            } else {
                matchers.add(new ChanceFractionalRewardMatcher((int) chanceFracObject));
            }
        } else if (chanceObject != null && chanceObject instanceof Integer) {
            SuperbVote.getPlugin().getLogger().warning("The 'chance' vote matcher will be switched to be based on percentages out of 100% in a future release. Use 'chance-fractional' to " +
                    "retain the current behavior, or migrate to a percentage matcher by specifying 'chance-percentage' in your configuration.");
            if ((int) chanceObject < 1) {
                SuperbVote.getPlugin().getLogger().severe("Fraction " + chanceObject + " is not valid; must be 1 or more.");
            } else {
                matchers.add(new ChanceFractionalRewardMatcher((int) chanceObject));
            }
        }

        // chance-percentage: <chance>
        Object chancePerObject = section.get("chance-percentage");
        if (chancePerObject != null && chancePerObject instanceof Integer) {
            int chancePerInt = (int) chancePerObject;
            if (chancePerInt > 0 && chancePerInt < 100) {
                matchers.add(new ChancePercentageRewardMatcher(chancePerInt));
            } else {
                SuperbVote.getPlugin().getLogger().severe("Percentage " + chancePerInt + " is not valid; must be between 1 and 99.");
            }
        }

        // service: <service> or services: <services>
        String service = section.getString("service", null);
        if (service != null) {
            matchers.add(new ServiceRewardMatcher(ImmutableList.of(service)));
        }
        List<String> services = section.getStringList("services");
        if (service == null && services != null && !services.isEmpty()) {
            matchers.add(new ServiceRewardMatcher(services));
        }

        // cumulative-votes: <votes>
        Object cumulativeObject = section.get("cumulative-votes");
        if (cumulativeObject != null && cumulativeObject instanceof Integer) {
            matchers.add(new CumulativeVotesRewardMatcher((int) cumulativeObject));
        }

        // script: <path>
        String script = section.getString("script");
        if (script != null) {
            try {
                matchers.add(new ScriptRewardMatcher(Paths.get(script)));
            } catch (IOException | ScriptException e) {
                SuperbVote.getPlugin().getLogger().log(Level.SEVERE, "Unable to parse script " + script, e);
            }
        }

        // world: <world> or worlds: <worlds>
        String world = section.getString("world", null);
        if (world != null) {
            matchers.add(new WorldRewardMatcher(ImmutableList.of(world)));
        }
        List<String> worlds = section.getStringList("worlds");
        if (world == null && worlds != null && !worlds.isEmpty()) {
            matchers.add(new WorldRewardMatcher(worlds));
        }

        return matchers;
    }
}

{'fraction_non_alphanumeric': 0.11782243816254417, 'fraction_numerical': 0.0033127208480565372, 'mean_word_length': 2.591197462331483, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 33, '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': '3025295', 'n_tokens_mistral': 2466, 'n_tokens_neox': 2358, 'n_words': 571}