<commit_before>package uk.co.eluinhost.UltraHardcore.features;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.Bukkit;

import uk.co.eluinhost.UltraHardcore.UltraHardcore;
import uk.co.eluinhost.UltraHardcore.exceptions.FeatureIDConflictException;
import uk.co.eluinhost.UltraHardcore.exceptions.FeatureIDNotFoundException;
import uk.co.eluinhost.UltraHardcore.exceptions.InvalidFeatureIDException;
import uk.co.eluinhost.UltraHardcore.features.events.UHCFeatureInitEvent;

public class FeatureManager {

    /**
     * Stores a list of all the features loaded on the server
     */
    private static ArrayList<UHCFeature> features = new ArrayList<UHCFeature>();

    /**
     * Only allow features with this pattern as an ID
     */
    private final static Pattern name_pattern = Pattern.compile("^[\\w]++$");

    /**
     * Add a UHC feature to the manager
     *
     * @param feature UHCFeature the feature to be added
     * @param enabled Whether the feature should be enabled or not after init
     * @throws FeatureIDConflictException when feature with the same ID already exists
     * @throws InvalidFeatureIDException  when the feature has an invalid ID name
     */
    public static void addFeature(UHCFeature feature, boolean enabled) throws FeatureIDConflictException, InvalidFeatureIDException {

        //check for alphanumerics
        Matcher mat = name_pattern.matcher(feature.getFeatureID());
        if (!mat.matches()) {
            throw new InvalidFeatureIDException();
        }

        //check for existing feature of the same name
        for (UHCFeature f : features) {
            if (f.getFeatureID().equals(feature.getFeatureID())) {
                throw new FeatureIDConflictException();
            }
        }

        //Make an init event for the feature creation
        UHCFeatureInitEvent uhc_init_event = new UHCFeatureInitEvent(feature);

        //call the event
        Bukkit.getServer().getPluginManager().callEvent(uhc_init_event);

        //if it was cancelled return
        if (!uhc_init_event.isAllowed()) {
            return;
        }

        //add the feature

        //TODO change this >.>
        features.add(feature);
        if (feature.isEnabled()) {
            feature.enableFeature();
        } else {
            feature.disableFeature();
        }

        //Register the feature for plugin events
        Bukkit.getPluginManager().registerEvents(feature, UltraHardcore.getInstance());
    }

    /**
     * Check if a feature is enabled by it's ID
     *
     * @param ID String the ID to check for
     * @return boolean true if enabled, false otherwise
     * @throws FeatureIDNotFoundException when feature not found
     */
    public static boolean isEnabled(String ID) throws FeatureIDNotFoundException {
        for (UHCFeature feature : features) {
            if (feature.getFeatureID().equals(ID)) {
                return feature.isEnabled();
            }
        }
        throw new FeatureIDNotFoundException();
    }

    /**
     * Get the UHCFeature based on it's ID
     *
     * @param ID String the ID to check for
     * @return UHCFeature the returned feature
     * @throws FeatureIDNotFoundException when feature ID not found
     */
    public static UHCFeature getFeature(String ID) throws FeatureIDNotFoundException {
        for (UHCFeature feature : features) {
            if (feature.getFeatureID().equals(ID)) {
                return feature;
            }
        }
        throw new FeatureIDNotFoundException();
    }

    /**
     * Returns all of the features loaded
     *
     * @return ArrayList
     */
    public static ArrayList<UHCFeature> getFeatures() {
        return features;
    }

    /**
     * Get a list of all the used feature names
     *
     * @return List String
     */
    public static List<String> getFeatureNames() {
        ArrayList<String> f = new ArrayList<String>();
        for (UHCFeature uhc : features) {
            f.add(uhc.getFeatureID());
        }
        return f;
    }
}
<commit_msg>same old<commit_after>package uk.co.eluinhost.UltraHardcore.features;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.Bukkit;

import uk.co.eluinhost.UltraHardcore.UltraHardcore;
import uk.co.eluinhost.UltraHardcore.exceptions.FeatureIDConflictException;
import uk.co.eluinhost.UltraHardcore.exceptions.FeatureIDNotFoundException;
import uk.co.eluinhost.UltraHardcore.exceptions.InvalidFeatureIDException;
import uk.co.eluinhost.UltraHardcore.features.events.UHCFeatureInitEvent;

/**
 * Feature Manager Class
 * TODO make this not a utility class
 */
public final class FeatureManager {

    /**
     * Stores a list of all the UHC_FEATURES loaded on the server
     */
    private static final List<UHCFeature> UHC_FEATURES = new ArrayList<UHCFeature>();

    /**
     * Only allow UHC_FEATURES with this pattern as an ID
     */
    private static final Pattern NAME_PATTERN = Pattern.compile("^[\\w]++$");

    /**
     * Don't allow constuct
     */
    private FeatureManager() {}

    /**
     * Add a UHC feature to the manager
     *
     * @param feature UHCFeature the feature to be added
     * @param enabled Whether the feature should be enabled or not after init
     * @throws FeatureIDConflictException when feature with the same ID already exists
     * @throws InvalidFeatureIDException  when the feature has an invalid ID name
     */
    public static void addFeature(UHCFeature feature, boolean enabled) throws FeatureIDConflictException, InvalidFeatureIDException {

        //check for alphanumerics
        Matcher mat = NAME_PATTERN.matcher(feature.getFeatureID());
        if (!mat.matches()) {
            throw new InvalidFeatureIDException();
        }

        //check for existing feature of the same name
        for (UHCFeature uhcFeature : UHC_FEATURES) {
            if (uhcFeature.getFeatureID().equals(feature.getFeatureID())) {
                throw new FeatureIDConflictException();
            }
        }

        //Make an init event for the feature creation
        UHCFeatureInitEvent initEvent = new UHCFeatureInitEvent(feature);

        //call the event
        Bukkit.getServer().getPluginManager().callEvent(initEvent);

        //if it was cancelled return
        if (!initEvent.isAllowed()) {
            return;
        }

        //add the feature

        //TODO change this >.>
        UHC_FEATURES.add(feature);
        if (feature.isEnabled()) {
            feature.enableFeature();
        } else {
            feature.disableFeature();
        }

        //Register the feature for plugin events
        Bukkit.getPluginManager().registerEvents(feature, UltraHardcore.getInstance());
    }

    /**
     * Check if a feature is enabled by it's ID
     *
     * @param featureID String the ID to check for
     * @return boolean true if enabled, false otherwise
     * @throws FeatureIDNotFoundException when feature not found
     */
    public static boolean isEnabled(String featureID) throws FeatureIDNotFoundException {
        for (UHCFeature feature : UHC_FEATURES) {
            if (feature.getFeatureID().equals(featureID)) {
                return feature.isEnabled();
            }
        }
        throw new FeatureIDNotFoundException();
    }

    /**
     * Get the UHCFeature based on it's ID
     *
     * @param featureID String the ID to check for
     * @return UHCFeature the returned feature
     * @throws FeatureIDNotFoundException when feature ID not found
     */
    public static UHCFeature getFeature(String featureID) throws FeatureIDNotFoundException {
        for (UHCFeature feature : UHC_FEATURES) {
            if (feature.getFeatureID().equals(featureID)) {
                return feature;
            }
        }
        throw new FeatureIDNotFoundException();
    }

    /**
     * Returns an unmodifiable list of all of the UHC_FEATURES loaded
     *
     * @return List
     */
    public static List<UHCFeature> getFeatures() {
        return Collections.unmodifiableList(UHC_FEATURES);
    }

    /**
     * Get a list of all the used feature names
     *
     * @return List String
     */
    public static List<String> getFeatureNames() {
        List<String> features = new ArrayList<String>();
        for (UHCFeature uhc : UHC_FEATURES) {
            features.add(uhc.getFeatureID());
        }
        return features;
    }
}

{'fraction_non_alphanumeric': 0.08600396224216292, 'fraction_numerical': 0.0, 'mean_word_length': 2.4971475142624286, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '936489', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2293, 'n_words': 664}