public class ConversationFactory extends Object
Conversation
from a predefined template. A ConversationFactory is typically created when
a plugin is instantiated and builds a Conversation each time a user
initiates a conversation with the plugin. Each Conversation maintains its
own state and calls back as needed into the plugin.
The ConversationFactory implements a fluid API, allowing parameters to be set as an extension to the constructor.
Modifier and Type | Field and Description |
---|---|
protected List<ConversationAbandonedListener> |
abandonedListeners |
protected List<ConversationCanceller> |
cancellers |
protected Prompt |
firstPrompt |
protected Map<Object,Object> |
initialSessionData |
protected boolean |
isModal |
protected boolean |
localEchoEnabled |
protected String |
playerOnlyMessage |
protected Plugin |
plugin |
protected ConversationPrefix |
prefix |
Constructor and Description |
---|
ConversationFactory(@NotNull Plugin plugin)
Constructs a ConversationFactory.
|
Modifier and Type | Method and Description |
---|---|
@NotNull ConversationFactory |
addConversationAbandonedListener(@NotNull ConversationAbandonedListener listener)
Adds a
ConversationAbandonedListener to all conversations
constructed by this factory. |
@NotNull Conversation |
buildConversation(@NotNull Conversable forWhom)
Constructs a
Conversation in accordance with the defaults set
for this factory. |
@NotNull ConversationFactory |
thatExcludesNonPlayersWithMessage(@Nullable String playerOnlyMessage)
Prevents this factory from creating a conversation for non-player
Conversable objects. |
@NotNull ConversationFactory |
withConversationCanceller(@NotNull ConversationCanceller canceller)
Adds a
ConversationCanceller to constructed conversations. |
@NotNull ConversationFactory |
withEscapeSequence(@NotNull String escapeSequence)
Sets the player input that, when received, will immediately terminate
the conversation.
|
@NotNull ConversationFactory |
withFirstPrompt(@Nullable Prompt firstPrompt)
Sets the first prompt to use in all generated conversations.
|
@NotNull ConversationFactory |
withInitialSessionData(@NotNull Map<Object,Object> initialSessionData)
Sets any initial data with which to populate the conversation context
sessionData map.
|
@NotNull ConversationFactory |
withLocalEcho(boolean localEchoEnabled)
Sets the local echo status for all
Conversation s created by
this factory. |
@NotNull ConversationFactory |
withModality(boolean modal)
Sets the modality of all
Conversation s created by this factory. |
@NotNull ConversationFactory |
withPrefix(@NotNull ConversationPrefix prefix)
Sets the
ConversationPrefix that prepends all output from all
generated conversations. |
@NotNull ConversationFactory |
withTimeout(int timeoutSeconds)
Sets the number of inactive seconds to wait before automatically
abandoning all generated conversations.
|
protected Plugin plugin
protected boolean isModal
protected boolean localEchoEnabled
protected ConversationPrefix prefix
protected Prompt firstPrompt
protected String playerOnlyMessage
protected List<ConversationCanceller> cancellers
protected List<ConversationAbandonedListener> abandonedListeners
@NotNull public @NotNull ConversationFactory withModality(boolean modal)
Conversation
s created by this factory.
If a conversation is modal, all messages directed to the player are
suppressed for the duration of the conversation.
The default is True.
modal
- The modality of all conversations to be created.@NotNull public @NotNull ConversationFactory withLocalEcho(boolean localEchoEnabled)
Conversation
s created by
this factory. If local echo is enabled, any text submitted to a
conversation gets echoed back into the submitter's chat window.localEchoEnabled
- The status of local echo.@NotNull public @NotNull ConversationFactory withPrefix(@NotNull @NotNull ConversationPrefix prefix)
ConversationPrefix
that prepends all output from all
generated conversations.
The default is a NullConversationPrefix
;
prefix
- The ConversationPrefix to use.@NotNull public @NotNull ConversationFactory withTimeout(int timeoutSeconds)
The default is 600 seconds (5 minutes).
timeoutSeconds
- The number of seconds to wait.@NotNull public @NotNull ConversationFactory withFirstPrompt(@Nullable @Nullable Prompt firstPrompt)
The default is Prompt.END_OF_CONVERSATION.
firstPrompt
- The first prompt.@NotNull public @NotNull ConversationFactory withInitialSessionData(@NotNull @NotNull Map<Object,Object> initialSessionData)
initialSessionData
- The conversation context's initial
sessionData.@NotNull public @NotNull ConversationFactory withEscapeSequence(@NotNull @NotNull String escapeSequence)
escapeSequence
- Input to terminate the conversation.@NotNull public @NotNull ConversationFactory withConversationCanceller(@NotNull @NotNull ConversationCanceller canceller)
ConversationCanceller
to constructed conversations.canceller
- The ConversationCanceller
to add.@NotNull public @NotNull ConversationFactory thatExcludesNonPlayersWithMessage(@Nullable @Nullable String playerOnlyMessage)
Conversable
objects.playerOnlyMessage
- The message to return to a non-play in lieu of
starting a conversation.@NotNull public @NotNull ConversationFactory addConversationAbandonedListener(@NotNull @NotNull ConversationAbandonedListener listener)
ConversationAbandonedListener
to all conversations
constructed by this factory.listener
- The listener to add.@NotNull public @NotNull Conversation buildConversation(@NotNull @NotNull Conversable forWhom)
Conversation
in accordance with the defaults set
for this factory.forWhom
- The entity for whom the new conversation is mediating.Copyright © 2021. All rights reserved.