All Downloads are FREE. Search and download functionalities are using the official Maven repository.

walkmc.extensions.Conversations.kt Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
@file:Suppress("NOTHING_TO_INLINE")

package walkmc.extensions

import org.bukkit.conversations.*
import org.bukkit.entity.*
import org.bukkit.plugin.*

/**
 * Casts the conversable for whom of this conversation context in a player.
 */
inline val ConversationContext.player get() = forWhom as Player

/**
 * Locates a possible existent a session data casting by the generic type [T]
 * of this conversation context by the specified string key.
 */
fun  ConversationContext.locate(key: String): T? = getSessionData(key) as? T

/**
 * Gets a existent a session data casting by the generic type [T]
 * of this conversation context by the specified string key.
 */
operator fun  ConversationContext.get(key: String): T = getSessionData(key).cast()

/**
 * Build this conversation to the specified [Conversable].
 */
inline fun ConversationFactory.build(to: Conversable): Conversation = buildConversation(to)

/**
 * Inserts all specified initial session data in this conversation factory.
 */
fun ConversationFactory.withData(vararg data: Pair): ConversationFactory =
   withInitialSessionData(data.toMap())

/**
 * Creates a new empty [ConversationFactory] with the specified plugin.
 */
fun Plugin.newConversation(): ConversationFactory =
   ConversationFactory(this).withLocalEcho(false)

/**
 * Creates a new [ConversationFactory] with the specified plugin and timeout.
 */
fun Plugin.newConversation(timeout: Int): ConversationFactory =
   ConversationFactory(this).withTimeout(timeout).withLocalEcho(false)

/**
 * Creates a new [ConversationFactory] with the specified plugin and first prompt.
 */
fun Plugin.newConversation(first: Prompt): ConversationFactory =
   ConversationFactory(this).withFirstPrompt(first).withLocalEcho(false)

/**
 * Creates a new [ConversationFactory] with the specified plugin, first prompt and timeout.
 */
fun Plugin.newConversation(first: Prompt, timeout: Int): ConversationFactory =
   ConversationFactory(this).withFirstPrompt(first).withTimeout(timeout).withLocalEcho(false)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy