public class Conversation extends Object
ConversationFactory
is used to
construct identical conversations on demand.
Conversation flow consists of a directed graph of Prompt
objects.
Each time a prompt gets input from the user, it must return the next prompt
in the graph. Since each Prompt chooses the next Prompt, complex
conversation trees can be implemented where the nature of the player's
response directs the flow of the conversation.
Each conversation has a ConversationPrefix
that prepends all output
from the conversation to the player. The ConversationPrefix can be used to
display the plugin name or conversation status as the conversation evolves.
Each conversation has a timeout measured in the number of inactive seconds to wait before abandoning the conversation. If the inactivity timeout is reached, the conversation is abandoned and the user's incoming and outgoing chat is returned to normal.
You should not construct a conversation manually. Instead, use the ConversationFactory
for access to all available options.
Modifier and Type | Class | Description |
---|---|---|
static class |
Conversation.ConversationState |
Modifier and Type | Field | Description |
---|---|---|
protected List<ConversationAbandonedListener> |
abandonedListeners |
|
protected List<ConversationCanceller> |
cancellers |
|
protected ConversationContext |
context |
|
protected Prompt |
currentPrompt |
|
protected boolean |
localEchoEnabled |
|
protected boolean |
modal |
|
protected ConversationPrefix |
prefix |
Constructor | Description |
---|---|
Conversation(Plugin plugin,
Conversable forWhom,
Prompt firstPrompt) |
Initializes a new Conversation.
|
Conversation(Plugin plugin,
Conversable forWhom,
Prompt firstPrompt,
Map<Object,Object> initialSessionData) |
Initializes a new Conversation.
|
Modifier and Type | Method | Description |
---|---|---|
void |
abandon() |
Abandons and resets the current conversation.
|
void |
abandon(ConversationAbandonedEvent details) |
Abandons and resets the current conversation.
|
void |
acceptInput(String input) |
Passes player input into the current prompt.
|
void |
addConversationAbandonedListener(ConversationAbandonedListener listener) |
Adds a
ConversationAbandonedListener . |
void |
begin() |
Displays the first prompt of this conversation and begins redirecting
the user's chat responses.
|
List<ConversationCanceller> |
getCancellers() |
Gets the list of
ConversationCanceller s |
ConversationContext |
getContext() |
Returns the Conversation's
ConversationContext . |
Conversable |
getForWhom() |
Gets the entity for whom this conversation is mediating.
|
ConversationPrefix |
getPrefix() |
Gets the
ConversationPrefix that prepends all output from this
conversation. |
Conversation.ConversationState |
getState() |
Returns Returns the current state of the conversation.
|
boolean |
isLocalEchoEnabled() |
Gets the status of local echo for this conversation.
|
boolean |
isModal() |
Gets the modality of this conversation.
|
void |
outputNextPrompt() |
Displays the next user prompt and abandons the conversation if the next
prompt is null.
|
void |
removeConversationAbandonedListener(ConversationAbandonedListener listener) |
Removes a
ConversationAbandonedListener . |
void |
setLocalEchoEnabled(boolean localEchoEnabled) |
Sets the status of local echo for this conversation.
|
protected Prompt currentPrompt
protected ConversationContext context
protected boolean modal
protected boolean localEchoEnabled
protected ConversationPrefix prefix
protected List<ConversationCanceller> cancellers
protected List<ConversationAbandonedListener> abandonedListeners
public Conversation(@Nullable Plugin plugin, @NotNull Conversable forWhom, @Nullable Prompt firstPrompt)
plugin
- The plugin that owns this conversation.forWhom
- The entity for whom this conversation is mediating.firstPrompt
- The first prompt in the conversation graph.public Conversation(@Nullable Plugin plugin, @NotNull Conversable forWhom, @Nullable Prompt firstPrompt, @NotNull Map<Object,Object> initialSessionData)
plugin
- The plugin that owns this conversation.forWhom
- The entity for whom this conversation is mediating.firstPrompt
- The first prompt in the conversation graph.initialSessionData
- Any initial values to put in the conversation
context sessionData map.@NotNull public Conversable getForWhom()
public boolean isModal()
public boolean isLocalEchoEnabled()
public void setLocalEchoEnabled(boolean localEchoEnabled)
localEchoEnabled
- The status of local echo.@NotNull public ConversationPrefix getPrefix()
ConversationPrefix
that prepends all output from this
conversation.@NotNull public List<ConversationCanceller> getCancellers()
ConversationCanceller
s@NotNull public ConversationContext getContext()
ConversationContext
.public void begin()
@NotNull public Conversation.ConversationState getState()
public void acceptInput(@NotNull String input)
input
- The user's chat text.public void addConversationAbandonedListener(@NotNull ConversationAbandonedListener listener)
ConversationAbandonedListener
.listener
- The listener to add.public void removeConversationAbandonedListener(@NotNull ConversationAbandonedListener listener)
ConversationAbandonedListener
.listener
- The listener to remove.public void abandon()
public void abandon(@NotNull ConversationAbandonedEvent details)
details
- Details about why the conversation was abandonedpublic void outputNextPrompt()
Copyright © 2020. All rights reserved.