forked from RepoMirrors/kami-blue
parent
5029c1ee32
commit
b96f0cb778
|
@ -100,6 +100,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
|
||||
|
||||
// After settings loaded, we want to let the enabled modules know they've been enabled (since the setting is done through reflection)
|
||||
ModuleManager.getModules().stream().filter(Module::isEnabled).forEach(Module::enable);
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package me.zeroeightsix.kami.command.commands;
|
||||
|
||||
import me.zeroeightsix.kami.command.Command;
|
||||
import me.zeroeightsix.kami.command.syntax.ChunkBuilder;
|
||||
import me.zeroeightsix.kami.command.syntax.SyntaxChunk;
|
||||
import me.zeroeightsix.kami.command.syntax.parsers.ModuleParser;
|
||||
import me.zeroeightsix.kami.module.Module;
|
||||
import me.zeroeightsix.kami.module.ModuleManager;
|
||||
|
||||
public class RenameModuleCommand extends Command {
|
||||
|
||||
public RenameModuleCommand() {
|
||||
super("renamemodule", new ChunkBuilder().append("module", true, new ModuleParser()).append("name").build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(String[] args) {
|
||||
if (args.length == 0) {
|
||||
sendChatMessage("Please specify a module!");
|
||||
return;
|
||||
} else if (args.length == 1) {
|
||||
sendChatMessage("Please specify a name!");
|
||||
return;
|
||||
}
|
||||
|
||||
Module module = ModuleManager.getModuleByName(args[0]);
|
||||
if (module == null) {
|
||||
sendChatMessage("Unknown module '" + args[0] + "'!");
|
||||
return;
|
||||
}
|
||||
|
||||
String name = args[1];
|
||||
|
||||
if (!(name.matches("[a-zA-Z]+"))) {
|
||||
sendChatMessage("Name must be alphabetic!");
|
||||
return;
|
||||
}
|
||||
|
||||
sendChatMessage("&b" + module.getName() + "&r renamed to &b" + name);
|
||||
module.setName(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -74,7 +74,11 @@ public class KamiGUI extends GUI {
|
|||
CheckButton checkButton = new CheckButton(module.getName());
|
||||
checkButton.setToggled(module.isEnabled());
|
||||
|
||||
checkButton.addTickListener(() -> checkButton.setToggled(module.isEnabled()));
|
||||
checkButton.addTickListener(() -> { // dear god
|
||||
checkButton.setToggled(module.isEnabled());
|
||||
checkButton.setName(module.getName());
|
||||
});
|
||||
|
||||
checkButton.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void onMouseDown(MouseButtonEvent event) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.google.gson.JsonElement;
|
|||
import com.google.gson.JsonPrimitive;
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
import me.zeroeightsix.kami.event.events.RenderEvent;
|
||||
import me.zeroeightsix.kami.gui.kami.KamiGUI;
|
||||
import me.zeroeightsix.kami.module.modules.movement.Sprint;
|
||||
import me.zeroeightsix.kami.setting.Setting;
|
||||
import me.zeroeightsix.kami.setting.Settings;
|
||||
|
@ -23,7 +24,8 @@ import java.util.List;
|
|||
*/
|
||||
public class Module {
|
||||
|
||||
private final String name = getAnnotation().name();
|
||||
private final String originalName = getAnnotation().name();
|
||||
private final Setting<String> name = register(Settings.s("Name", originalName));
|
||||
private final String description = getAnnotation().description();
|
||||
private final Category category = getAnnotation().category();
|
||||
private Setting<Bind> bind = register(Settings.custom("Bind", Bind.none(), new BindConverter()).build());
|
||||
|
@ -54,6 +56,11 @@ public class Module {
|
|||
return bind.getValue().toString();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name.setValue(name);
|
||||
ModuleManager.updateLookup();
|
||||
}
|
||||
|
||||
public enum Category
|
||||
{
|
||||
COMBAT("Combat", false),
|
||||
|
@ -91,7 +98,7 @@ public class Module {
|
|||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return name.getValue();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
|
@ -164,7 +171,7 @@ public class Module {
|
|||
protected <T> Setting<T> register(Setting<T> setting) {
|
||||
if (settingList == null) settingList = new ArrayList<>();
|
||||
settingList.add(setting);
|
||||
return SettingBuilder.register(setting, "modules." + name);
|
||||
return SettingBuilder.register(setting, "modules." + originalName);
|
||||
}
|
||||
|
||||
protected <T> Setting<T> register(SettingBuilder<T> builder) {
|
||||
|
|
|
@ -31,13 +31,19 @@ public class ModuleManager {
|
|||
*/
|
||||
static HashMap<String, Module> lookup = new HashMap<>();
|
||||
|
||||
public static void updateLookup() {
|
||||
lookup.clear();
|
||||
for (Module m : modules)
|
||||
lookup.put(m.getName().toLowerCase(), m);
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
Set<Class> classList = ClassFinder.findClasses(ClickGUI.class.getPackage().getName(), Module.class);
|
||||
classList.forEach(aClass -> {
|
||||
try {
|
||||
Module module = (Module) aClass.getConstructor().newInstance();
|
||||
modules.add(module);
|
||||
lookup.put(module.getName().toLowerCase(), 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());
|
||||
|
|
Loading…
Reference in New Issue