use of io.discloader.discloader.common.discovery.ModContainer in project DiscLoader by R3alCl0ud.
the class ModRegistry method preInit.
public static void preInit() {
int i = 1;
for (ModContainer mod : preInitMods.values()) {
ProgressLogger.step(i, preInitMods.size(), String.format("Mod: %s", mod.modInfo.modid()));
if (mods.containsKey(mod.modInfo.modid())) {
i++;
continue;
}
loadMod(mod.modInfo.modid());
// activeMod = null;
}
// DLPreInitEvent event = new DLPreInitEvent(loader);
logger.info("" + (loader != null));
// loader.emit(event);
ProgressLogger.phase(3, 3, "Init");
logger.info("Now swiching to the Init phase");
ProgressLogger.stage(1, 3, "Waiting to Login");
logger.info("Waiting to Login");
// loader.doneLoading();
resetStep();
loaded.complete((Void) null);
}
use of io.discloader.discloader.common.discovery.ModContainer in project DiscLoader by R3alCl0ud.
the class CommandMods method execute.
@Override
public void execute(MessageCreateEvent e, String[] args) {
IMessage message = e.getMessage();
RichEmbed embed = new RichEmbed().setColor(0x55cdF2);
ModContainer mc;
try {
if (args.length == 1 && (mc = ModRegistry.mods.get(args[0])) != null) {
if (mc != null) {
embed.setThumbnail(DLUtil.MissingTexture);
embed.addField("Description", mc.modInfo.desc(), true).addField("Version", mc.modInfo.version(), true).addField("Author(s)", mc.modInfo.author(), true);
}
} else {
ArrayList<String> modList = new ArrayList<String>();
for (ModContainer mcs : ModRegistry.mods.values()) {
modList.add(String.format("%s", mcs.modInfo.name()));
}
embed.setThumbnail(getResourceLocation());
String mods = Arrays.toString(modList.toArray());
mods = mods.substring(1, mods.length() - 1);
embed.addField("Mods", mods);
}
} catch (Exception ex) {
ex.printStackTrace();
}
message.getChannel().sendEmbed(embed);
}
use of io.discloader.discloader.common.discovery.ModContainer in project DiscLoader by R3alCl0ud.
the class ModRegistry method loadMod.
public static void loadMod(String modid) {
ModContainer mod = preInitMods.get(modid);
ProgressLogger.progress(1, 3, "Checking if another mod is currently active");
logger.info("Checking if another mod is currently active");
if (activeMod != null) {
loadMod.put(mod.modInfo.modid(), activeMod.modInfo.modid());
}
ProgressLogger.progress(2, 3, "Setting active mod");
logger.info("Setting active mod");
activeMod = mod;
ProgressLogger.progress(3, 3, "Executing PreInit handler in: " + mod.modInfo.modid());
logger.info("Executing PreInit handler in: " + mod.modInfo.modid());
mods.put(mod.modInfo.modid(), mod);
DLPreInitEvent event = new DLPreInitEvent(loader);
mod.emit("preInit", event);
if (loadMod.containsKey(mod.modInfo.modid())) {
activeMod = preInitMods.get(loadMod.get(mod.modInfo.modid()));
} else {
activeMod = null;
}
mod.loaded = true;
}
use of io.discloader.discloader.common.discovery.ModContainer in project DiscLoader by R3alCl0ud.
the class ModRegistry method checkCandidates.
public static CompletableFuture<Void> checkCandidates(List<ModCandidate> mcs) {
Thread modLoader = new Thread("ModLoader") {
public void run() {
ProgressLogger.step(1, 2, "Checking candidates for @Mod annotation");
logger.info("Checking candidates for @Mod annotation");
List<ModContainer> containers = new ArrayList<ModContainer>();
for (int i = 0; i < mcs.size(); i++) {
activeMod = null;
ModCandidate candidate = mcs.get(i);
Class<?> cls = candidate.getModClass();
ProgressLogger.progress(i + 1, mcs.size(), cls.getName());
logger.info(cls.getName());
boolean isMod = cls.isAnnotationPresent(Mod.class);
if (isMod) {
ProgressLogger.progress(i + 1, mcs.size(), String.format("Found @Mod Annotation: %s", cls.getName()));
logger.info(String.format("Found @Mod Annotation: %s", cls.getName()));
ModContainer mc = new ModContainer(candidate);
activeMod = mc;
containers.add(mc);
}
}
ProgressLogger.step(2, 2, "Registering uninitialized mods");
logger.info("Registering uninitialized mods");
for (int i = 0; i < containers.size(); i++) {
ModContainer mc = containers.get(i);
activeMod = mc;
ProgressLogger.progress(i + 1, containers.size(), mc.modInfo.modid());
logger.info(mc.modInfo.modid());
if (preInitMods.containsKey(mc.modInfo.modid())) {
logger.severe(String.format("Mod with duplicate id found. \nHALTING STARTUP\nDuplicate ID: %s\n", mc.modInfo.modid()));
System.exit(1);
}
preInitMods.put(mc.modInfo.modid(), mc);
}
activeMod = null;
ProgressLogger.stage(3, 3, "Registering Mod EventHandlers");
logger.info("Registering Mod EventHandlers");
int n = 1;
for (ModContainer mc : preInitMods.values()) {
activeMod = mc;
ProgressLogger.step(n, preInitMods.size(), mc.modInfo.modid());
logger.info(String.format("Registrying event handlers in: %s", mc.modInfo.modid()));
mc.discoverHandlers();
n++;
}
activeMod = null;
ProgressLogger.phase(2, 3, "PreINIT");
logger.info("PreINIT");
ProgressLogger.stage(1, 3, "Begin PreINIT");
logger.info("Begin PreINIT");
ProgressLogger.stage(2, 3, "Registering Default Language");
logger.info("Registering Default Language");
LanguageRegistry.registerLanguage(DLUtil.enUS);
ProgressLogger.stage(3, 3, "Execute PreINIT");
logger.info("Execute PreINIT");
preInit();
}
};
modLoader.start();
return loaded;
}
use of io.discloader.discloader.common.discovery.ModContainer in project DiscLoader by R3alCl0ud.
the class CommandRegistry method addPrefix.
public static String addPrefix(String name) {
int index = name.lastIndexOf(":");
String oldPrefix = index == -1 ? "" : name.substring(0, index), prefix;
ModContainer modContainer = ModRegistry.activeMod;
if (modContainer != null) {
prefix = modContainer.modInfo.modid();
} else {
prefix = "discloader";
}
if (!oldPrefix.equals(prefix)) {
name = prefix + ":" + name;
}
return name;
}
Aggregations