Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.conversations.Conversation Class Reference

Classes

enum  ConversationState
 

Public Member Functions

 Conversation (Plugin plugin, Conversable forWhom, Prompt firstPrompt)
 
 Conversation (Plugin plugin, Conversable forWhom, Prompt firstPrompt, Map< Object, Object > initialSessionData)
 
Conversable getForWhom ()
 
boolean isModal ()
 
boolean isLocalEchoEnabled ()
 
void setLocalEchoEnabled (boolean localEchoEnabled)
 
ConversationPrefix getPrefix ()
 
List< ConversationCancellergetCancellers ()
 
ConversationContext getContext ()
 
void begin ()
 
ConversationState getState ()
 
void acceptInput (String input)
 
synchronized void addConversationAbandonedListener (ConversationAbandonedListener listener)
 
synchronized void removeConversationAbandonedListener (ConversationAbandonedListener listener)
 
void abandon ()
 
synchronized void abandon (ConversationAbandonedEvent details)
 
void outputNextPrompt ()
 

Protected Attributes

Prompt currentPrompt
 
ConversationContext context
 
boolean modal
 
boolean localEchoEnabled
 
ConversationPrefix prefix
 
List< ConversationCancellercancellers
 
List< ConversationAbandonedListenerabandonedListeners
 

Detailed Description

The Conversation class is responsible for tracking the current state of a conversation, displaying prompts to the user, and dispatching the user's response to the appropriate place. Conversation objects are not typically instantiated directly. Instead a 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.

Definition at line 35 of file Conversation.java.

Constructor & Destructor Documentation

org.bukkit.conversations.Conversation.Conversation ( Plugin  plugin,
Conversable  forWhom,
Prompt  firstPrompt 
)

Initializes a new Conversation.

Parameters
pluginThe plugin that owns this conversation.
forWhomThe entity for whom this conversation is mediating.
firstPromptThe first prompt in the conversation graph.

Definition at line 54 of file Conversation.java.

54  {
55  this(plugin, forWhom, firstPrompt, new HashMap<Object, Object>());
56  }
org.bukkit.conversations.Conversation.Conversation ( Plugin  plugin,
Conversable  forWhom,
Prompt  firstPrompt,
Map< Object, Object >  initialSessionData 
)

Initializes a new Conversation.

Parameters
pluginThe plugin that owns this conversation.
forWhomThe entity for whom this conversation is mediating.
firstPromptThe first prompt in the conversation graph.
initialSessionDataAny initial values to put in the conversation context sessionData map.

Definition at line 67 of file Conversation.java.

67  {
68  this.firstPrompt = firstPrompt;
69  this.context = new ConversationContext(plugin, forWhom, initialSessionData);
70  this.modal = true;
71  this.localEchoEnabled = true;
72  this.prefix = new NullConversationPrefix();
73  this.cancellers = new ArrayList<ConversationCanceller>();
74  this.abandonedListeners = new ArrayList<ConversationAbandonedListener>();
75  }

Member Function Documentation

void org.bukkit.conversations.Conversation.abandon ( )

Abandons and resets the current conversation. Restores the user's normal chat behavior.

Definition at line 255 of file Conversation.java.

Referenced by org.bukkit.conversations.Conversation.acceptInput(), and org.bukkit.conversations.Conversation.outputNextPrompt().

255  {
256  abandon(new ConversationAbandonedEvent(this, new ManuallyAbandonedConversationCanceller()));
257  }
synchronized void org.bukkit.conversations.Conversation.abandon ( ConversationAbandonedEvent  details)

Abandons and resets the current conversation. Restores the user's normal chat behavior.

Parameters
detailsDetails about why the conversation was abandoned

Definition at line 265 of file Conversation.java.

References org.bukkit.conversations.Conversable.abandonConversation(), and org.bukkit.conversations.ConversationContext.getForWhom().

265  {
266  if (!abandoned) {
267  abandoned = true;
268  currentPrompt = null;
269  context.getForWhom().abandonConversation(this);
270  for (ConversationAbandonedListener listener : abandonedListeners) {
271  listener.conversationAbandoned(details);
272  }
273  }
274  }
void abandonConversation(Conversation conversation)
void org.bukkit.conversations.Conversation.acceptInput ( String  input)

Passes player input into the current prompt. The next prompt (as determined by the current prompt) is then displayed to the user.

Parameters
inputThe user's chat text.

Definition at line 211 of file Conversation.java.

References org.bukkit.conversations.Conversation.abandon(), org.bukkit.conversations.Prompt.acceptInput(), org.bukkit.conversations.ConversationContext.getForWhom(), org.bukkit.conversations.ConversationPrefix.getPrefix(), org.bukkit.conversations.Conversation.outputNextPrompt(), and org.bukkit.conversations.Conversable.sendRawMessage().

211  {
212  if (currentPrompt != null) {
213 
214  // Echo the user's input
215  if (localEchoEnabled) {
216  context.getForWhom().sendRawMessage(prefix.getPrefix(context) + input);
217  }
218 
219  // Test for conversation abandonment based on input
220  for(ConversationCanceller canceller : cancellers) {
221  if (canceller.cancelBasedOnInput(context, input)) {
222  abandon(new ConversationAbandonedEvent(this, canceller));
223  return;
224  }
225  }
226 
227  // Not abandoned, output the next prompt
228  currentPrompt = currentPrompt.acceptInput(context, input);
230  }
231  }
void sendRawMessage(String message)
String getPrefix(ConversationContext context)
Prompt acceptInput(ConversationContext context, String input)
synchronized void org.bukkit.conversations.Conversation.addConversationAbandonedListener ( ConversationAbandonedListener  listener)

Adds a ConversationAbandonedListener.

Parameters
listenerThe listener to add.

Definition at line 238 of file Conversation.java.

Referenced by org.bukkit.conversations.ConversationFactory.buildConversation().

238  {
239  abandonedListeners.add(listener);
240  }
void org.bukkit.conversations.Conversation.begin ( )

Displays the first prompt of this conversation and begins redirecting the user's chat responses.

Definition at line 182 of file Conversation.java.

References org.bukkit.conversations.Conversable.beginConversation(), and org.bukkit.conversations.ConversationContext.getForWhom().

182  {
183  if (currentPrompt == null) {
184  abandoned = false;
185  currentPrompt = firstPrompt;
186  context.getForWhom().beginConversation(this);
187  }
188  }
boolean beginConversation(Conversation conversation)
List<ConversationCanceller> org.bukkit.conversations.Conversation.getCancellers ( )

Gets the list of ConversationCancellers

Returns
The list.

Definition at line 165 of file Conversation.java.

165  {
166  return cancellers;
167  }
ConversationContext org.bukkit.conversations.Conversation.getContext ( )

Returns the Conversation's ConversationContext.

Returns
The ConversationContext.

Definition at line 174 of file Conversation.java.

174  {
175  return context;
176  }
Conversable org.bukkit.conversations.Conversation.getForWhom ( )

Gets the entity for whom this conversation is mediating.

Returns
The entity.

Definition at line 82 of file Conversation.java.

References org.bukkit.conversations.ConversationContext.getForWhom().

82  {
83  return context.getForWhom();
84  }
ConversationPrefix org.bukkit.conversations.Conversation.getPrefix ( )

Gets the ConversationPrefix that prepends all output from this conversation.

Returns
The ConversationPrefix in use.

Definition at line 136 of file Conversation.java.

136  {
137  return prefix;
138  }
ConversationState org.bukkit.conversations.Conversation.getState ( )

Returns Returns the current state of the conversation.

Returns
The current state of the conversation.

Definition at line 195 of file Conversation.java.

195  {
196  if (currentPrompt != null) {
197  return ConversationState.STARTED;
198  } else if (abandoned) {
199  return ConversationState.ABANDONED;
200  } else {
201  return ConversationState.UNSTARTED;
202  }
203  }
boolean org.bukkit.conversations.Conversation.isLocalEchoEnabled ( )

Gets the status of local echo for this conversation. If local echo is enabled, any text submitted to a conversation gets echoed back into the submitter's chat window.

Returns
The status of local echo.

Definition at line 115 of file Conversation.java.

115  {
116  return localEchoEnabled;
117  }
boolean org.bukkit.conversations.Conversation.isModal ( )

Gets the modality of this conversation. If a conversation is modal, all messages directed to the player are suppressed for the duration of the conversation.

Returns
The conversation modality.

Definition at line 93 of file Conversation.java.

93  {
94  return modal;
95  }
void org.bukkit.conversations.Conversation.outputNextPrompt ( )

Displays the next user prompt and abandons the conversation if the next prompt is null.

Definition at line 280 of file Conversation.java.

References org.bukkit.conversations.Conversation.abandon(), org.bukkit.conversations.Prompt.acceptInput(), org.bukkit.conversations.Prompt.blocksForInput(), org.bukkit.conversations.ConversationContext.getForWhom(), org.bukkit.conversations.ConversationPrefix.getPrefix(), org.bukkit.conversations.Prompt.getPromptText(), and org.bukkit.conversations.Conversable.sendRawMessage().

Referenced by org.bukkit.conversations.Conversation.acceptInput(), and org.bukkit.conversations.FakeConversable.beginConversation().

280  {
281  if (currentPrompt == null) {
282  abandon(new ConversationAbandonedEvent(this));
283  } else {
284  context.getForWhom().sendRawMessage(prefix.getPrefix(context) + currentPrompt.getPromptText(context));
285  if (!currentPrompt.blocksForInput(context)) {
286  currentPrompt = currentPrompt.acceptInput(context, null);
288  }
289  }
290  }
void sendRawMessage(String message)
boolean blocksForInput(ConversationContext context)
String getPromptText(ConversationContext context)
String getPrefix(ConversationContext context)
Prompt acceptInput(ConversationContext context, String input)
synchronized void org.bukkit.conversations.Conversation.removeConversationAbandonedListener ( ConversationAbandonedListener  listener)

Removes a ConversationAbandonedListener.

Parameters
listenerThe listener to remove.

Definition at line 247 of file Conversation.java.

247  {
248  abandonedListeners.remove(listener);
249  }
void org.bukkit.conversations.Conversation.setLocalEchoEnabled ( boolean  localEchoEnabled)

Sets the status of local echo for this conversation. If local echo is enabled, any text submitted to a conversation gets echoed back into the submitter's chat window.

Parameters
localEchoEnabledThe status of local echo.

Definition at line 126 of file Conversation.java.

Referenced by org.bukkit.conversations.ConversationFactory.buildConversation().

126  {
127  this.localEchoEnabled = localEchoEnabled;
128  }

The documentation for this class was generated from the following file: