Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Have Macros store keycodes properly, and avoid unnecessary conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT2 committed May 5, 2020
1 parent d1f88c0 commit 68603c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("
}
sendChatMessage("You have the following macros: ")
for ((key1, value) in Macros.macros) {
sendRawChatMessage(Wrapper.getKeyName(key1.toInt()) + ": $value")
sendRawChatMessage(Wrapper.getKeyName(key1) + ": $value")
}
return
}
Expand All @@ -50,7 +50,7 @@ class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("
return
}
args[1] == "clear" -> {
Macro.removeMacro(key.toString())
Macro.removeMacro(key)
MacroManager.saveMacros()
MacroManager.registerMacros()
sendChatMessage("Cleared macros for '&7$rKey&f'")
Expand All @@ -61,7 +61,7 @@ class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("
return
}
else -> {
Macro.addMacroToKey(key.toString(), macro)
Macro.addMacroToKey(key, macro)
MacroManager.saveMacros()
sendChatMessage("Added macro '&7$macro&f' for key '&7$rKey&f'")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/zeroeightsix/kami/module/Macros.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public class Macros {
* Map of all the macros.
* KeyCode, Actions
*/
public static Map<String, List<String>> macros = new LinkedHashMap<>();
public static Map<Integer, List<String>> macros = new LinkedHashMap<>();
}
14 changes: 7 additions & 7 deletions src/main/java/me/zeroeightsix/kami/util/Macro.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,30 @@ object Macro {

fun readFileToMemory() {
try {
Macros.macros = gson.fromJson(FileReader(file), object : TypeToken<HashMap<String?, List<String?>?>?>() {}.type)
Macros.macros = gson.fromJson(FileReader(file), object : TypeToken<HashMap<Int?, 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?>? {
fun getMacrosForKey(keycode: Int): List<String?>? {
for ((key, value) in Macros.macros) {
if (keyCode == key.toInt()) {
if (keycode == key.toInt()) {
return value
}
}
return null
}

fun addMacroToKey(keyCode: String?, macro: String?) {
fun addMacroToKey(keycode: Int?, macro: String?) {
if (macro == null) return // prevent trying to add a null macro
Macros.macros.getOrPut(keyCode, ::mutableListOf).add(macro)
Macros.macros.getOrPut(keycode, ::mutableListOf).add(macro)
}

fun removeMacro(keyCode: String) {
fun removeMacro(keycode: Int) {
for (entry in Macros.macros.entries) {
if (entry.key == keyCode) {
if (entry.key == keycode) {
entry.setValue(null)
}
}
Expand Down

0 comments on commit 68603c2

Please sign in to comment.