mirror of https://github.com/kami-blue/client
Merge pull request #783 from kami-blue/feature/macros#75
This commit is contained in:
commit
d1f88c08c3
|
@ -16,6 +16,7 @@ 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.MacroManager;
|
||||
import me.zeroeightsix.kami.module.Module;
|
||||
import me.zeroeightsix.kami.module.ModuleManager;
|
||||
import me.zeroeightsix.kami.module.modules.chat.ChatEncryption;
|
||||
|
@ -146,6 +147,8 @@ public class KamiMod {
|
|||
|
||||
Friends.initFriends();
|
||||
|
||||
MacroManager.INSTANCE.registerMacros();
|
||||
|
||||
/* Custom static Settings, which can't register normally if they're static */
|
||||
SettingsRegister.register("commandPrefix", Command.commandPrefix);
|
||||
SettingsRegister.register("delimiterV", ChatEncryption.delimiterValue);
|
||||
|
|
|
@ -6,6 +6,8 @@ import me.zeroeightsix.kami.command.syntax.ChunkBuilder;
|
|||
import me.zeroeightsix.kami.command.syntax.parsers.DependantParser;
|
||||
import me.zeroeightsix.kami.command.syntax.parsers.EnumParser;
|
||||
import me.zeroeightsix.kami.gui.kami.KamiGUI;
|
||||
import me.zeroeightsix.kami.module.MacroManager;
|
||||
import me.zeroeightsix.kami.util.Macro;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
|
@ -37,15 +39,17 @@ public class ConfigCommand extends Command {
|
|||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "reload":
|
||||
Macro.INSTANCE.readFileToMemory();
|
||||
reload();
|
||||
break;
|
||||
case "save":
|
||||
try {
|
||||
KamiMod.saveConfigurationUnsafe();
|
||||
sendChatMessage("Saved configuration!");
|
||||
MacroManager.INSTANCE.saveMacros();
|
||||
sendChatMessage("Saved configuration and macros!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
sendChatMessage("Failed to save! " + e.getMessage());
|
||||
sendChatMessage("Failed to save config! " + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "path":
|
||||
|
@ -79,7 +83,7 @@ public class ConfigCommand extends Command {
|
|||
KamiMod.getInstance().guiManager = new KamiGUI();
|
||||
KamiMod.getInstance().guiManager.initializeGUI();
|
||||
KamiMod.loadConfiguration();
|
||||
sendChatMessage("Configuration reloaded!");
|
||||
sendChatMessage("Configuration and macros reloaded!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package me.zeroeightsix.kami.command.commands
|
||||
|
||||
import me.zeroeightsix.kami.command.Command
|
||||
import me.zeroeightsix.kami.command.syntax.ChunkBuilder
|
||||
import me.zeroeightsix.kami.module.MacroManager
|
||||
import me.zeroeightsix.kami.module.Macros
|
||||
import me.zeroeightsix.kami.util.Macro
|
||||
import me.zeroeightsix.kami.util.MessageSendHelper.*
|
||||
import me.zeroeightsix.kami.util.Wrapper
|
||||
|
||||
/**
|
||||
* @author dominikaaaa
|
||||
* Created by dominikaaaa on 04/05/20
|
||||
*/
|
||||
class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("clear|message/command").build(), "m") {
|
||||
override fun call(args: Array<out String?>) {
|
||||
val rKey = args[0]
|
||||
val macro = args[1]
|
||||
val key = Wrapper.getKey(rKey)
|
||||
|
||||
if (key == 0 && !rKey.equals("list", true)) {
|
||||
sendErrorMessage("Unknown key '&7$rKey&f'! Left alt is &7lmenu&f and left Control is &7lctrl&f. You cannot bind the &7meta&f key.")
|
||||
return
|
||||
}
|
||||
|
||||
val keyList: List<String?>? = Macro.getMacrosForKey(key)
|
||||
|
||||
when {
|
||||
args[0] == null -> { /* key, error message is caught by the command handler but you don't want to continue the rest */
|
||||
return
|
||||
}
|
||||
args[0] == "list" -> {
|
||||
if (Macros.macros.isEmpty()) {
|
||||
sendChatMessage("You have no macros")
|
||||
return
|
||||
}
|
||||
sendChatMessage("You have the following macros: ")
|
||||
for ((key1, value) in Macros.macros) {
|
||||
sendRawChatMessage(Wrapper.getKeyName(key1.toInt()) + ": $value")
|
||||
}
|
||||
return
|
||||
}
|
||||
args[1] == null -> { /* message */
|
||||
if (keyList == null || keyList.isEmpty()) {
|
||||
sendChatMessage("'&7$rKey&f' has no macros")
|
||||
return
|
||||
}
|
||||
sendChatMessage("'&7$rKey&f' has the following macros: ")
|
||||
Macro.sendMacrosToChat(keyList.toTypedArray())
|
||||
return
|
||||
}
|
||||
args[1] == "clear" -> {
|
||||
Macro.removeMacro(key.toString())
|
||||
MacroManager.saveMacros()
|
||||
MacroManager.registerMacros()
|
||||
sendChatMessage("Cleared macros for '&7$rKey&f'")
|
||||
return
|
||||
}
|
||||
args[2] != null -> { /* some random 3rd argument which shouldn't exist */
|
||||
sendWarningMessage("$chatLabel Your macro / command must be inside quotes, as 1 argument in the command. Example: &7" + getCommandPrefix() + label + " R \";set AutoSpawner debug toggle\"")
|
||||
return
|
||||
}
|
||||
else -> {
|
||||
Macro.addMacroToKey(key.toString(), macro)
|
||||
MacroManager.saveMacros()
|
||||
sendChatMessage("Added macro '&7$macro&f' for key '&7$rKey&f'")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import me.zeroeightsix.kami.event.events.DisplaySizeChangedEvent;
|
|||
import me.zeroeightsix.kami.gui.UIRenderer;
|
||||
import me.zeroeightsix.kami.gui.kami.KamiGUI;
|
||||
import me.zeroeightsix.kami.gui.rgui.component.container.use.Frame;
|
||||
import me.zeroeightsix.kami.module.MacroManager;
|
||||
import me.zeroeightsix.kami.module.modules.client.CommandConfig;
|
||||
import me.zeroeightsix.kami.module.modules.render.AntiOverlay;
|
||||
import me.zeroeightsix.kami.module.modules.render.BossStack;
|
||||
|
@ -235,6 +236,7 @@ public class ForgeEventProcessor {
|
|||
Minecraft.getMinecraft().displayGuiScreen(new GuiChat(Command.getCommandPrefix()));
|
||||
} else {
|
||||
MODULE_MANAGER.onBind(Keyboard.getEventKey());
|
||||
MacroManager.INSTANCE.sendMacro(Keyboard.getEventKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,10 +250,10 @@ public class ForgeEventProcessor {
|
|||
if (event.getMessage().length() > 1)
|
||||
KamiMod.getInstance().commandManager.callCommand(event.getMessage().substring(Command.getCommandPrefix().length() - 1));
|
||||
else
|
||||
sendChatMessage("Please enter a command.");
|
||||
sendChatMessage("Please enter a command!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendChatMessage("Error occured while running command! (" + e.getMessage() + ")");
|
||||
sendChatMessage("Error occured while running command! (" + e.getMessage() + "), check the log for info!");
|
||||
}
|
||||
event.setMessage("");
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.zeroeightsix.kami.mixin.client;
|
|||
import me.zeroeightsix.kami.DiscordPresence;
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
import me.zeroeightsix.kami.event.events.GuiScreenEvent;
|
||||
import me.zeroeightsix.kami.module.MacroManager;
|
||||
import me.zeroeightsix.kami.util.Wrapper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.SoundHandler;
|
||||
|
@ -110,6 +111,7 @@ public class MixinMinecraft {
|
|||
private void save() {
|
||||
System.out.println("Shutting down: saving KAMI configuration");
|
||||
KamiMod.saveConfiguration();
|
||||
MacroManager.INSTANCE.saveMacros();
|
||||
System.out.println("Configuration saved.");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package me.zeroeightsix.kami.module
|
||||
|
||||
import me.zeroeightsix.kami.KamiMod
|
||||
import me.zeroeightsix.kami.command.Command
|
||||
import me.zeroeightsix.kami.util.Macro
|
||||
import me.zeroeightsix.kami.util.MessageSendHelper
|
||||
|
||||
/**
|
||||
* @author dominikaaaa
|
||||
* Created by dominikaaaa on 04/05/20
|
||||
*/
|
||||
object MacroManager {
|
||||
|
||||
/**
|
||||
* Reads macros from KAMIBlueMacros.json into the macros Map
|
||||
*/
|
||||
fun registerMacros() {
|
||||
KamiMod.log.info("Registering macros...")
|
||||
Macro.readFileToMemory()
|
||||
KamiMod.log.info("Macros registered")
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves macros from the macros Map into KAMIBlueMacros.json
|
||||
*/
|
||||
fun saveMacros() {
|
||||
KamiMod.log.info("Saving macros...")
|
||||
Macro.writeMemoryToFile()
|
||||
KamiMod.log.info("Macros saved")
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the message or command, depending on which one it is
|
||||
* @param keyCode int keycode of the key the was pressed
|
||||
*/
|
||||
fun sendMacro(keyCode: Int) {
|
||||
val macrosForThisKey = Macro.getMacrosForKey(keyCode) ?: return
|
||||
for (currentMacro in macrosForThisKey) {
|
||||
if (currentMacro!!.startsWith(Command.getCommandPrefix())) { // this is done instead of just sending a chat packet so it doesn't add to the chat history
|
||||
MessageSendHelper.sendKamiCommand(currentMacro, false) // ie, the false here
|
||||
} else {
|
||||
MessageSendHelper.sendServerMessage(currentMacro)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package me.zeroeightsix.kami.module;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author dominikaaaa
|
||||
* Lazy fix used for Java instance of {@link me.zeroeightsix.kami.util.Macro} and {@link MacroManager}
|
||||
*/
|
||||
public class Macros {
|
||||
/*
|
||||
* Map of all the macros.
|
||||
* KeyCode, Actions
|
||||
*/
|
||||
public static Map<String, List<String>> macros = new LinkedHashMap<>();
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package me.zeroeightsix.kami.util
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import me.zeroeightsix.kami.KamiMod
|
||||
import me.zeroeightsix.kami.module.Macros
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author dominikaaaa
|
||||
* Created by dominikaaaa on 04/05/20
|
||||
*/
|
||||
object Macro {
|
||||
private val gson = GsonBuilder().create()
|
||||
private const val configName = "KAMIBlueMacros.json"
|
||||
private val file = File(configName)
|
||||
|
||||
fun writeMemoryToFile() {
|
||||
try {
|
||||
val fw = FileWriter(file, false)
|
||||
gson.toJson(Macros.macros, fw)
|
||||
fw.flush()
|
||||
fw.close()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun readFileToMemory() {
|
||||
try {
|
||||
Macros.macros = gson.fromJson(FileReader(file), object : TypeToken<HashMap<String?, List<String?>?>?>() {}.type)
|
||||
} catch (e: FileNotFoundException) {
|
||||
KamiMod.log.warn("Could not find file $configName, clearing the macros list")
|
||||
Macros.macros.clear()
|
||||
}
|
||||
}
|
||||
|
||||
fun getMacrosForKey(keyCode: Int): List<String?>? {
|
||||
for ((key, value) in Macros.macros) {
|
||||
if (keyCode == key.toInt()) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun addMacroToKey(keyCode: String?, macro: String?) {
|
||||
if (macro == null) return // prevent trying to add a null macro
|
||||
Macros.macros.getOrPut(keyCode, ::mutableListOf).add(macro)
|
||||
}
|
||||
|
||||
fun removeMacro(keyCode: String) {
|
||||
for (entry in Macros.macros.entries) {
|
||||
if (entry.key == keyCode) {
|
||||
entry.setValue(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun sendMacrosToChat(messages: Array<String?>) {
|
||||
for (s in messages) MessageSendHelper.sendRawChatMessage("[$s]")
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package me.zeroeightsix.kami.util;
|
||||
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
import me.zeroeightsix.kami.command.Command;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.launchwrapper.LogWrapper;
|
||||
import net.minecraft.network.play.client.CPacketChatMessage;
|
||||
|
@ -25,10 +26,22 @@ public class MessageSendHelper {
|
|||
sendRawChatMessage("&7[&4" + KamiMod.KAMI_KANJI + "&7] &r" + message);
|
||||
}
|
||||
|
||||
public static void sendCustomMessage(String message, String colour) {
|
||||
sendRawChatMessage("&7[" + colour + KamiMod.KAMI_KANJI + "&7] &r" + message);
|
||||
public static void sendKamiCommand(String command, boolean addToHistory) {
|
||||
try {
|
||||
if (addToHistory) {
|
||||
Wrapper.getMinecraft().ingameGUI.getChatGUI().addToSentMessages(command);
|
||||
}
|
||||
if (command.length() > 1)
|
||||
KamiMod.getInstance().commandManager.callCommand(command.substring(Command.getCommandPrefix().length() - 1));
|
||||
else
|
||||
sendChatMessage("Please enter a command!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendChatMessage("Error occurred while running command! (" + e.getMessage() + "), check the log for info!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void sendStringChatMessage(String[] messages) {
|
||||
sendChatMessage("");
|
||||
for (String s : messages) sendRawChatMessage(s);
|
||||
|
|
|
@ -35,6 +35,10 @@ public class Wrapper {
|
|||
return Keyboard.getKeyIndex(keyname.toUpperCase());
|
||||
}
|
||||
|
||||
public static String getKeyName(int keycode) {
|
||||
return Keyboard.getKeyName(keycode);
|
||||
}
|
||||
|
||||
public static FontRenderer getFontRenderer() {
|
||||
return fontRenderer;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue