<commit_before>package net.acomputerdog.BlazeLoader.mod;

import net.acomputerdog.BlazeLoader.api.general.ApiGeneral;
import net.acomputerdog.BlazeLoader.main.BlazeLoader;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Stores and loads mods, distributes events, and allows access to loaded mods.
 */
public class ModList {
    private static final List<Mod> loadedMods = new ArrayList<Mod>();
    private static final List<Class<? extends Mod>> unloadedMods = new ArrayList<Class<? extends Mod>>();
    private static final List<ModData> modData = new ArrayList<ModData>();

    public static List<Mod> getLoadedMods() {
        return loadedMods;
    }

    public static List<Class<? extends Mod>> getUnloadedMods() {
        return unloadedMods;
    }

    public static List<ModData> getModData() {
        return modData;
    }

    private static Mod getCompatibleModFromList(Mod mod) {
        if (mod != null) {
            for (Mod m : loadedMods) {
                BlazeLoader.currActiveMod = mod;
                if (mod.getModId().equals(m.getModId())) return m;
            }
            BlazeLoader.currActiveMod = null;
        }
        return null;
    }

    public static void load() {
        ApiGeneral.theProfiler.startSection("init_mods");
        Iterator<Class<? extends Mod>> iterator = unloadedMods.iterator();
        while (iterator.hasNext()) {
            Class<? extends Mod> cls = iterator.next();
            Mod mod = null;
            try {
                mod = cls.newInstance();
                if (mod.isCompatibleWithBLVersion()) {
                    Mod sameMod = getCompatibleModFromList(mod);
                    boolean useNewMod = true;
                    if (sameMod != null) {
                        BlazeLoader.getLogger().logWarning("Duplicate mod: " + mod.getModName() + "!  Newest version will be used!");
                        if (sameMod.getIntModVersion() < mod.getIntModVersion()) {
                            sameMod.stop();
                            loadedMods.remove(sameMod);
                        } else {
                            useNewMod = false;
                        }
                    }
                    if (useNewMod) {
                        mod.load();
                        loadedMods.add(mod);
                        ModData data = new ModData(mod, cls, new File(cls.getProtectionDomain().getCodeSource().getLocation().toURI()), mod.getModId());
                        modData.add(data);<commit_msg>Mod events are now auto-detected<commit_after>package net.acomputerdog.BlazeLoader.mod;

import net.acomputerdog.BlazeLoader.api.general.ApiGeneral;
import net.acomputerdog.BlazeLoader.event.EventHandler;
import net.acomputerdog.BlazeLoader.main.BlazeLoader;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Stores and loads mods, distributes events, and allows access to loaded mods.
 */
public class ModList {
    private static final List<Mod> loadedMods = new ArrayList<Mod>();
    private static final List<Class<? extends Mod>> unloadedMods = new ArrayList<Class<? extends Mod>>();
    private static final List<ModData> modData = new ArrayList<ModData>();

    public static List<Mod> getLoadedMods() {
        return loadedMods;
    }

    public static List<Class<? extends Mod>> getUnloadedMods() {
        return unloadedMods;
    }

    public static List<ModData> getModData() {
        return modData;
    }

    private static Mod getCompatibleModFromList(Mod mod) {
        if (mod != null) {
            for (Mod m : loadedMods) {
                BlazeLoader.currActiveMod = mod;
                if (mod.getModId().equals(m.getModId())) return m;
            }
            BlazeLoader.currActiveMod = null;
        }
        return null;
    }

    public static void load() {
        ApiGeneral.theProfiler.startSection("init_mods");
        Iterator<Class<? extends Mod>> iterator = unloadedMods.iterator();
        while (iterator.hasNext()) {
            Class<? extends Mod> cls = iterator.next();
            Mod mod = null;
            try {
                mod = cls.newInstance();
                if (mod.isCompatibleWithBLVersion()) {
                    Mod sameMod = getCompatibleModFromList(mod);
                    boolean useNewMod = true;
                    if (sameMod != null) {
                        BlazeLoader.getLogger().logWarning("Duplicate mod: " + mod.getModName() + "!  Newest version will be used!");
                        if (sameMod.getIntModVersion() < mod.getIntModVersion()) {
                            sameMod.stop();
                            loadedMods.remove(sameMod);
                        } else {
                            useNewMod = false;
                        }
                    }
                    if (useNewMod) {
                        EventHandler.addMod(mod);
                        mod.load();
                        loadedMods.add(mod);
                        ModData data = new ModData(mod, cls, new File(cls.getProtectionDomain().getCodeSource().getLocation().toURI()), mod.getModId());
                        modData.add(data);
{'fraction_non_alphanumeric': 0.10456019843541309, 'fraction_numerical': 0.0, 'mean_word_length': 1.855119825708061, 'pattern_counts': {'":': 0, '<': 35, '<?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': '2557572', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1380, 'n_words': 324}