From 6aff756bbdb17b82028adf21d60b8ae88371a080 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sat, 3 Jul 2021 15:41:19 -0500 Subject: [PATCH] Fixed tab-to-reply Expanded on the ContentAPI to include the ability to use all input dialogue types. --- Server/src/main/kotlin/api/ContentAPI.kt | 21 +++++++++++++++++-- Server/src/main/kotlin/api/InputType.kt | 8 +++++++ .../system/command/sets/MiscCommandSet.kt | 3 ++- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 Server/src/main/kotlin/api/InputType.kt diff --git a/Server/src/main/kotlin/api/ContentAPI.kt b/Server/src/main/kotlin/api/ContentAPI.kt index 28dcd8de0..baadf76e7 100644 --- a/Server/src/main/kotlin/api/ContentAPI.kt +++ b/Server/src/main/kotlin/api/ContentAPI.kt @@ -956,8 +956,25 @@ object ContentAPI { */ @JvmStatic fun sendInputDialogue(player: Player, numeric: Boolean, prompt: String, handler: (value: Any) -> Unit){ - player.dialogueInterpreter.sendInput(!numeric, prompt) - player.setAttribute("runscript",handler) //Handled in RunScriptPacketHandler + if(numeric) sendInputDialogue(player, InputType.NUMERIC, prompt, handler) + else sendInputDialogue(player, InputType.STRING_SHORT, prompt, handler) + } + + /** + * Send input dialogues based on type. Some dialogues are special and can't be covered by the other sendInputDialogue method + * @param player the player to send the input dialogue to + * @param type the input type to send - an enum is available for this called InputType + * @param prompt what to prompt the player + * @param handler the method that handles the value from the input dialogue + */ + @JvmStatic + fun sendInputDialogue(player: Player, type: InputType, prompt: String, handler: (value: Any) -> Unit){ + when(type){ + InputType.NUMERIC, InputType.STRING_SHORT -> player.dialogueInterpreter.sendInput(type != InputType.NUMERIC, prompt) + InputType.STRING_LONG -> player.dialogueInterpreter.sendLongInput(prompt) + InputType.MESSAGE -> player.dialogueInterpreter.sendMessageInput(prompt) + } + player.setAttribute("runscript", handler) } /** diff --git a/Server/src/main/kotlin/api/InputType.kt b/Server/src/main/kotlin/api/InputType.kt new file mode 100644 index 000000000..139060cfc --- /dev/null +++ b/Server/src/main/kotlin/api/InputType.kt @@ -0,0 +1,8 @@ +package api + +enum class InputType { + NUMERIC, + STRING_SHORT, + STRING_LONG, + MESSAGE +} \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt b/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt index 94dc2bf74..f9142922b 100644 --- a/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt +++ b/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt @@ -1,6 +1,7 @@ package rs09.game.system.command.sets import api.ContentAPI +import api.InputType import core.cache.def.impl.ItemDefinition import core.cache.def.impl.NPCDefinition import core.cache.def.impl.SceneryDefinition @@ -201,7 +202,7 @@ class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){ if (player.attributes.containsKey("replyTo")) { player.setAttribute("keepDialogueAlive", true) val replyTo = player.getAttribute("replyTo", "").replace("_".toRegex(), " ") - ContentAPI.sendInputDialogue(player, false ,StringUtils.formatDisplayName(replyTo)){value -> + ContentAPI.sendInputDialogue(player, InputType.MESSAGE ,StringUtils.formatDisplayName(replyTo)){ value -> CommunicationInfo.sendMessage(player, replyTo.toLowerCase(), value as String) player.removeAttribute("keepDialogueAlive") }