Use getMacrosForKey only once, and fix bug when you don't have any macro

This commit is contained in:
Bella 2020-05-05 14:34:21 -04:00
parent 6b6d611585
commit efbafdc05a
No known key found for this signature in database
GPG Key ID: DBD4A6030080C8B3
1 changed files with 8 additions and 2 deletions

View File

@ -22,11 +22,17 @@ class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("
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) {
sendChatMessage(Wrapper.getKeyName(key1.toInt()) + ": $value")
@ -34,12 +40,12 @@ class MacroCommand : Command("macro", ChunkBuilder().append("key|list").append("
return
}
args[1] == null -> { /* message */
if (Macro.getMacrosForKey(key) == null || Macro.getMacrosForKey(key)?.equals("")!! || Macro.getMacrosForKey(key)?.toTypedArray()?.equals("")!!) {
if (keyList == null || keyList.isEmpty() || keyList.toTypedArray().isEmpty()) {
sendChatMessage("'&7$rKey&f' has no macros")
return
}
sendChatMessage("'&7$rKey&f' has the following macros: ")
sendStringChatMessage(Macro.getMacrosForKey(key)?.toTypedArray(), false)
sendStringChatMessage(keyList.toTypedArray(), false)
return
}
args[1] == "clear" -> {