fixed everything and now everything works

This commit is contained in:
zeroeightsix 2018-10-14 16:33:27 +02:00
parent f08f62fa80
commit 47846db010
9 changed files with 82 additions and 23 deletions

View File

@ -1,12 +1,25 @@
package me.zeroeightsix.kami;
import com.google.common.base.Converter;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import me.zero.alpine.EventBus;
import me.zero.alpine.EventManager;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.command.CommandManager;
import me.zeroeightsix.kami.event.ForgeEventProcessor;
import me.zeroeightsix.kami.gui.kami.KamiGUI;
import me.zeroeightsix.kami.gui.rgui.component.AlignedComponent;
import me.zeroeightsix.kami.gui.rgui.component.Component;
import me.zeroeightsix.kami.gui.rgui.component.container.use.Frame;
import me.zeroeightsix.kami.gui.rgui.util.ContainerHelper;
import me.zeroeightsix.kami.gui.rgui.util.Docking;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.module.ModuleManager;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import me.zeroeightsix.kami.setting.SettingsRegister;
import me.zeroeightsix.kami.setting.config.Configuration;
import me.zeroeightsix.kami.util.Friends;
import me.zeroeightsix.kami.util.LagCompensator;
@ -19,6 +32,9 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.*;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
/**
* Created by 086 on 7/11/2017.
@ -45,6 +61,17 @@ public class KamiMod {
public KamiGUI guiManager;
public CommandManager commandManager;
private Setting<JsonObject> guiStateSetting = Settings.custom("gui", new JsonObject(), new Converter<JsonObject, JsonObject>() {
@Override
protected JsonObject doForward(JsonObject jsonObject) {
return jsonObject;
}
@Override
protected JsonObject doBackward(JsonObject jsonObject) {
return jsonObject;
}
}).buildAndRegister("");
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
@ -68,11 +95,9 @@ public class KamiMod {
commandManager = new CommandManager();
File file = new File("KAMISettings.json");
Friends.initFriends();
if (file.exists()) {
}
SettingsRegister.register("commandPrefix", Command.commandPrefix);
loadConfiguration();
KamiMod.log.info("Settings loaded");
// After settings loaded, we want to let the enabled modules know they've been enabled (since the setting is done through reflection)
@ -112,6 +137,26 @@ public class KamiMod {
File kamiConfig = new File(kamiConfigName);
if (!kamiConfig.exists()) return;
Configuration.loadConfiguration(kamiConfig);
JsonObject gui = KamiMod.INSTANCE.guiStateSetting.getValue();
for (Map.Entry<String, JsonElement> entry : gui.entrySet()) {
Optional<Component> optional = KamiMod.INSTANCE.guiManager.getChildren().stream().filter(component -> component instanceof Frame).filter(component -> ((Frame) component).getTitle().equals(entry.getKey())).findFirst();
if (optional.isPresent()) {
JsonObject object = entry.getValue().getAsJsonObject();
Frame frame = (Frame) optional.get();
frame.setX(object.get("x").getAsInt());
frame.setY(object.get("y").getAsInt());
Docking docking = Docking.values()[object.get("docking").getAsInt()];
if (docking.isLeft()) ContainerHelper.setAlignment(frame, AlignedComponent.Alignment.LEFT);
else if (docking.isRight()) ContainerHelper.setAlignment(frame, AlignedComponent.Alignment.RIGHT);
frame.setDocking(docking);
frame.setMinimized(object.get("minimized").getAsBoolean());
frame.setPinned(object.get("pinned").getAsBoolean());
} else {
System.err.println("Found GUI config entry for " + entry.getKey() + ", but found no frame with that name");
}
}
KamiMod.getInstance().getGuiManager().getChildren().stream().filter(component -> (component instanceof Frame) && (((Frame) component).isPinneable()) && component.isVisible()).forEach(component -> component.setOpacity(0f));
}
public static void saveConfiguration() {
@ -123,6 +168,18 @@ public class KamiMod {
}
public static void saveConfigurationUnsafe() throws IOException {
JsonObject object = new JsonObject();
KamiMod.INSTANCE.guiManager.getChildren().stream().filter(component -> component instanceof Frame).map(component -> (Frame) component).forEach(frame -> {
JsonObject frameObject = new JsonObject();
frameObject.add("x", new JsonPrimitive(frame.getX()));
frameObject.add("y", new JsonPrimitive(frame.getY()));
frameObject.add("docking", new JsonPrimitive(Arrays.asList(Docking.values()).indexOf(frame.getDocking())));
frameObject.add("minimized", new JsonPrimitive(frame.isMinimized()));
frameObject.add("pinned", new JsonPrimitive(frame.isPinned()));
object.add(frame.getTitle(), frameObject);
});
KamiMod.INSTANCE.guiStateSetting.setValue(object);
File outputFile = new File(getConfigName());
if (!outputFile.exists())
outputFile.createNewFile();

View File

@ -2,6 +2,8 @@ package me.zeroeightsix.kami.command;
import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.command.syntax.SyntaxChunk;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import me.zeroeightsix.kami.util.Wrapper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentBase;
@ -17,7 +19,7 @@ public abstract class Command {
protected SyntaxChunk[] syntaxChunks;
public static String COMMAND_PREFIX = ".";
public static Setting<String> commandPrefix = Settings.s("commandPrefix", ".");
public Command(String label, SyntaxChunk[] syntaxChunks) {
this.label = label;
@ -47,7 +49,7 @@ public abstract class Command {
}
public static String getCommandPrefix() {
return COMMAND_PREFIX;
return commandPrefix.getValue();
}
public String getLabel() {

View File

@ -18,7 +18,7 @@ public class CommandsCommand extends Command {
@Override
public void call(String[] args) {
KamiMod.getInstance().getCommandManager().getCommands().stream().sorted(Comparator.comparing(command -> command.getLabel())).forEach(command ->
Command.sendChatMessage("&7" + Command.COMMAND_PREFIX + command.getLabel() + "&r ~ &8" + command.getDescription())
Command.sendChatMessage("&7" + Command.getCommandPrefix() + command.getLabel() + "&r ~ &8" + command.getDescription())
);
}
}

View File

@ -19,8 +19,8 @@ public class PrefixCommand extends Command {
return;
}
Command.COMMAND_PREFIX = args[0];
Command.sendChatMessage("Prefix set to &b" + Command.COMMAND_PREFIX);
Command.commandPrefix.setValue(args[0]);
Command.sendChatMessage("Prefix set to &b" + Command.commandPrefix.getValue());
}
}

View File

@ -111,13 +111,13 @@ public class ForgeEventProcessor {
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onChatSent(ClientChatEvent event) {
if (event.getMessage().startsWith(Command.COMMAND_PREFIX)) {
if (event.getMessage().startsWith(Command.getCommandPrefix())) {
event.setCanceled(true);
try {
Wrapper.getMinecraft().ingameGUI.getChatGUI().addToSentMessages(event.getMessage());
if (event.getMessage().length() > 1)
KamiMod.getInstance().commandManager.callCommand(event.getMessage().substring(Command.COMMAND_PREFIX.length() - 1));
KamiMod.getInstance().commandManager.callCommand(event.getMessage().substring(Command.getCommandPrefix().length() - 1));
else
Command.sendChatMessage("Please enter a command.");
} catch (Exception e) {

View File

@ -7,6 +7,7 @@ import me.zeroeightsix.kami.gui.rgui.component.use.CheckButton;
import me.zeroeightsix.kami.gui.rgui.component.use.Slider;
import me.zeroeightsix.kami.gui.rgui.render.theme.Theme;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.setting.AbstractSetting;
import me.zeroeightsix.kami.setting.Named;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.impl.BooleanSetting;
@ -48,7 +49,7 @@ public class SettingsPanel extends OrganisedContainer {
}
if (!module.settingList.isEmpty()) {
for (Setting setting : module.settingList) {
if (!(setting instanceof Named)) continue;
if (!(setting instanceof Named) || ((setting instanceof AbstractSetting) && !setting.isVisible())) continue;
String name = ((Named) setting).getName();
boolean isNumber = setting instanceof NumberSetting;
boolean isBoolean = setting instanceof BooleanSetting;

View File

@ -21,8 +21,8 @@ public class KamiGuiChat extends GuiChat {
public KamiGuiChat(String startString, String historybuffer, int sentHistoryCursor) {
super(startString);
this.startString = startString;
if (!startString.equals(Command.COMMAND_PREFIX))
calculateCommand(startString.substring(Command.COMMAND_PREFIX.length()));
if (!startString.equals(Command.getCommandPrefix()))
calculateCommand(startString.substring(Command.getCommandPrefix().length()));
this.historyBuffer = historybuffer;
cursor = sentHistoryCursor;
}
@ -34,7 +34,7 @@ public class KamiGuiChat extends GuiChat {
String chatLine = this.inputField.getText();
if (!chatLine.startsWith(Command.COMMAND_PREFIX)){
if (!chatLine.startsWith(Command.getCommandPrefix())){
GuiChat newGUI = new GuiChat(chatLine) {
int cursor = KamiGuiChat.this.cursor;
@Override
@ -51,12 +51,12 @@ public class KamiGuiChat extends GuiChat {
// Startstring is still here! Hooray!
if (chatLine.equals(Command.COMMAND_PREFIX)) {
if (chatLine.equals(Command.getCommandPrefix())) {
currentFillinLine = "";
return;
}
calculateCommand(chatLine.substring(Command.COMMAND_PREFIX.length()));
calculateCommand(chatLine.substring(Command.getCommandPrefix().length()));
}
protected void calculateCommand(String line){

View File

@ -28,7 +28,7 @@ public abstract class MixinGuiChat {
@Inject(method = "Lnet/minecraft/client/gui/GuiChat;keyTyped(CI)V", at = @At("RETURN"))
public void returnKeyTyped(char typedChar, int keyCode, CallbackInfo info) {
if (!(Wrapper.getMinecraft().currentScreen instanceof GuiChat) || Wrapper.getMinecraft().currentScreen instanceof KamiGuiChat) return;
if (inputField.getText().startsWith(Command.COMMAND_PREFIX)) {
if (inputField.getText().startsWith(Command.getCommandPrefix())) {
Wrapper.getMinecraft().displayGuiScreen(new KamiGuiChat(inputField.getText(), historyBuffer, sentHistoryCursor));
}
}

View File

@ -26,8 +26,8 @@ public class Module {
private final String name = getAnnotation().name();
private final String description = getAnnotation().description();
private final Category category = getAnnotation().category();
private Setting<Bind> bind = Settings.custom("Bind", Bind.none(), new BindConverter(), true).build();
private Setting<Boolean> enabled = Settings.b("Enabled", false);
private Setting<Bind> bind = register(Settings.custom("Bind", Bind.none(), new BindConverter()).build());
private Setting<Boolean> enabled = register(Settings.booleanBuilder("Enabled").withVisibility(aBoolean -> false).withValue(false).build());
public boolean alwaysListening;
protected static final Minecraft mc = Minecraft.getMinecraft();
@ -164,8 +164,7 @@ public class Module {
@Override
protected Bind doBackward(JsonElement jsonElement) {
String s = jsonElement.getAsString();
s = s.toLowerCase();
if (s.equals("None")) return Bind.none();
if (s.equalsIgnoreCase("None")) return Bind.none();
boolean ctrl = false, alt = false, shift = false;
if (s.startsWith("Ctrl+")) {
@ -186,7 +185,7 @@ public class Module {
key = Keyboard.getKeyIndex(s);
} catch (Exception ignored) {}
if (key == -1) return Bind.none();
if (key == 0) return Bind.none();
return new Bind(ctrl, alt, shift, key);
}
}