Merge pull request #294 from S-B99/modulemanager

ModuleManager fixes / improvements
This commit is contained in:
Sasha 2019-12-17 07:59:17 -08:00 committed by GitHub
commit 52af5bbead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 16 deletions

View File

@ -130,7 +130,8 @@ public class KamiMod {
loadConfiguration();
KamiMod.log.info("Settings loaded");
ModuleManager.updateLookup(); // generate the lookup table after settings are loaded to make custom module names work
// custom names aren't known at compile-time
//ModuleManager.updateLookup(); // generate the lookup table after settings are loaded to make custom module names work
new Capes();
KamiMod.log.info("Capes init!\n");

View File

@ -9,7 +9,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.launchwrapper.LogWrapper;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

View File

@ -4,7 +4,6 @@ import com.google.common.base.Converter;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.event.events.PacketEvent;
import me.zeroeightsix.kami.event.events.RenderEvent;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;

View File

@ -27,14 +27,15 @@ public class ModuleManager {
public static ArrayList<Module> modules = new ArrayList<>();
/**
* Lookup map for getting by name
* Lookup map for getting by **original** name
*/
static HashMap<String, Module> lookup = new HashMap<>();
static HashMap<String, Integer> lookup = new HashMap<>();
public static void updateLookup() {
lookup.clear();
for (Module m : modules)
lookup.put(m.getName().toLowerCase(), m);
for (int i = 0; i < modules.size(); i++) {
lookup.put(modules.get(i).getOriginalName().toLowerCase(), i);
}
}
public static void initialize() {
@ -43,7 +44,6 @@ public class ModuleManager {
try {
Module module = (Module) aClass.getConstructor().newInstance();
modules.add(module);
// lookup.put(module.getName().toLowerCase(), module);
} catch (InvocationTargetException e) {
e.getCause().printStackTrace();
System.err.println("Couldn't initiate module " + aClass.getSimpleName() + "! Err: " + e.getClass().getSimpleName() + ", message: " + e.getMessage());
@ -53,15 +53,16 @@ public class ModuleManager {
}
});
KamiMod.log.info("Modules initialised");
getModules().sort(Comparator.comparing(Module::getName));
getModules().sort(Comparator.comparing(Module::getOriginalName));
updateLookup();
}
public static void onUpdate() {
modules.stream().filter(module -> module.alwaysListening || module.isEnabled()).forEach(module -> module.onUpdate());
modules.stream().filter(module -> module.alwaysListening || module.isEnabled()).forEach(Module::onUpdate);
}
public static void onRender() {
modules.stream().filter(module -> module.alwaysListening || module.isEnabled()).forEach(module -> module.onRender());
modules.stream().filter(module -> module.alwaysListening || module.isEnabled()).forEach(Module::onRender);
}
public static void onWorldRender(RenderWorldLastEvent event) {
@ -84,7 +85,7 @@ public class ModuleManager {
Minecraft.getMinecraft().profiler.endSection();
modules.stream().filter(module -> module.alwaysListening || module.isEnabled()).forEach(module -> {
Minecraft.getMinecraft().profiler.startSection(module.getName());
Minecraft.getMinecraft().profiler.startSection(module.getOriginalName());
module.onWorldRender(e);
Minecraft.getMinecraft().profiler.endSection();
});
@ -101,8 +102,6 @@ public class ModuleManager {
// GlStateManager.popMatrix();
KamiTessellator.releaseGL();
Minecraft.getMinecraft().profiler.endSection();
Minecraft.getMinecraft().profiler.endSection();
}
public static void onBind(int eventKey) {
@ -118,9 +117,9 @@ public class ModuleManager {
return modules;
}
public static Module getModuleByName(String name) {
return lookup.get(name.toLowerCase());
// return getModules().stream().filter(module -> module.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
return modules.get(lookup.get(name.toLowerCase()));
}
public static boolean isModuleEnabled(String moduleName) {