Fixed tab-to-reply

Expanded on the ContentAPI to include the ability to use all input dialogue types.
This commit is contained in:
ceikry
2021-07-03 15:41:19 -05:00
parent a9ed9de7c5
commit 6aff756bbd
3 changed files with 29 additions and 3 deletions
+19 -2
View File
@@ -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)
}
/**
+8
View File
@@ -0,0 +1,8 @@
package api
enum class InputType {
NUMERIC,
STRING_SHORT,
STRING_LONG,
MESSAGE
}
@@ -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")
}