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

Public Member Functions

 ConversationFactory (Plugin plugin)
 
ConversationFactory withModality (boolean modal)
 
ConversationFactory withLocalEcho (boolean localEchoEnabled)
 
ConversationFactory withPrefix (ConversationPrefix prefix)
 
ConversationFactory withTimeout (int timeoutSeconds)
 
ConversationFactory withFirstPrompt (Prompt firstPrompt)
 
ConversationFactory withInitialSessionData (Map< Object, Object > initialSessionData)
 
ConversationFactory withEscapeSequence (String escapeSequence)
 
ConversationFactory withConversationCanceller (ConversationCanceller canceller)
 
ConversationFactory thatExcludesNonPlayersWithMessage (String playerOnlyMessage)
 
ConversationFactory addConversationAbandonedListener (ConversationAbandonedListener listener)
 
Conversation buildConversation (Conversable forWhom)
 

Protected Attributes

Plugin plugin
 
boolean isModal
 
boolean localEchoEnabled
 
ConversationPrefix prefix
 
Prompt firstPrompt
 
Map< Object, Object > initialSessionData
 
String playerOnlyMessage
 
List< ConversationCancellercancellers
 
List< ConversationAbandonedListenerabandonedListeners
 

Detailed Description

A ConversationFactory is responsible for creating a 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.

Definition at line 21 of file ConversationFactory.java.

Constructor & Destructor Documentation

org.bukkit.conversations.ConversationFactory.ConversationFactory ( Plugin  plugin)

Constructs a ConversationFactory.

Parameters
pluginThe plugin that owns the factory.

Definition at line 38 of file ConversationFactory.java.

References org.bukkit.conversations.Prompt.END_OF_CONVERSATION.

39  {
40  this.plugin = plugin;
41  isModal = true;
42  localEchoEnabled = true;
43  prefix = new NullConversationPrefix();
44  firstPrompt = Prompt.END_OF_CONVERSATION;
45  initialSessionData = new HashMap<Object, Object>();
46  playerOnlyMessage = null;
47  cancellers = new ArrayList<ConversationCanceller>();
48  abandonedListeners = new ArrayList<ConversationAbandonedListener>();
49  }
static final Prompt END_OF_CONVERSATION
Definition: Prompt.java:15

Member Function Documentation

ConversationFactory org.bukkit.conversations.ConversationFactory.addConversationAbandonedListener ( ConversationAbandonedListener  listener)

Adds a ConversationAbandonedListener to all conversations constructed by this factory.

Parameters
listenerThe listener to add.
Returns
This object.

Definition at line 176 of file ConversationFactory.java.

176  {
177  abandonedListeners.add(listener);
178  return this;
179  }
Conversation org.bukkit.conversations.ConversationFactory.buildConversation ( Conversable  forWhom)

Constructs a Conversation in accordance with the defaults set for this factory.

Parameters
forWhomThe entity for whom the new conversation is mediating.
Returns
A new conversation.

Definition at line 188 of file ConversationFactory.java.

References org.bukkit.conversations.Conversation.addConversationAbandonedListener(), and org.bukkit.conversations.Conversation.setLocalEchoEnabled().

188  {
189  //Abort conversation construction if we aren't supposed to talk to non-players
190  if (playerOnlyMessage != null && !(forWhom instanceof Player)) {
191  return new Conversation(plugin, forWhom, new NotPlayerMessagePrompt());
192  }
193 
194  //Clone any initial session data
195  Map<Object, Object> copiedInitialSessionData = new HashMap<Object, Object>();
196  copiedInitialSessionData.putAll(initialSessionData);
197 
198  //Build and return a conversation
199  Conversation conversation = new Conversation(plugin, forWhom, firstPrompt, copiedInitialSessionData);
200  conversation.setModal(isModal);
201  conversation.setLocalEchoEnabled(localEchoEnabled);
202  conversation.setPrefix(prefix);
203 
204  //Clone the conversation cancellers
205  for (ConversationCanceller canceller : cancellers) {
206  conversation.addConversationCanceller(canceller.clone());
207  }
208 
209  //Add the ConversationAbandonedListeners
210  for (ConversationAbandonedListener listener : abandonedListeners) {
211  conversation.addConversationAbandonedListener(listener);
212  }
213 
214  return conversation;
215  }
ConversationFactory org.bukkit.conversations.ConversationFactory.thatExcludesNonPlayersWithMessage ( String  playerOnlyMessage)

Prevents this factory from creating a conversation for non-player Conversable objects.

Parameters
playerOnlyMessageThe message to return to a non-play in lieu of starting a conversation.
Returns
This object.

Definition at line 164 of file ConversationFactory.java.

164  {
165  this.playerOnlyMessage = playerOnlyMessage;
166  return this;
167  }
ConversationFactory org.bukkit.conversations.ConversationFactory.withConversationCanceller ( ConversationCanceller  canceller)

Adds a ConversationCanceller to constructed conversations.

Parameters
cancellerThe ConversationCanceller to add.
Returns
This object.

Definition at line 151 of file ConversationFactory.java.

Referenced by org.bukkit.conversations.ConversationFactory.withEscapeSequence(), and org.bukkit.conversations.ConversationFactory.withTimeout().

151  {
152  cancellers.add(canceller);
153  return this;
154  }
ConversationFactory org.bukkit.conversations.ConversationFactory.withEscapeSequence ( String  escapeSequence)

Sets the player input that, when received, will immediately terminate the conversation.

Parameters
escapeSequenceInput to terminate the conversation.
Returns
This object.

Definition at line 140 of file ConversationFactory.java.

References org.bukkit.conversations.ConversationFactory.withConversationCanceller().

140  {
141  return withConversationCanceller(new ExactMatchConversationCanceller(escapeSequence));
142  }
ConversationFactory withConversationCanceller(ConversationCanceller canceller)
ConversationFactory org.bukkit.conversations.ConversationFactory.withFirstPrompt ( Prompt  firstPrompt)

Sets the first prompt to use in all generated conversations.

The default is Prompt.END_OF_CONVERSATION.

Parameters
firstPromptThe first prompt.
Returns
This object.

Definition at line 115 of file ConversationFactory.java.

115  {
116  this.firstPrompt = firstPrompt;
117  return this;
118  }
ConversationFactory org.bukkit.conversations.ConversationFactory.withInitialSessionData ( Map< Object, Object >  initialSessionData)

Sets any initial data with which to populate the conversation context sessionData map.

Parameters
initialSessionDataThe conversation context's initial sessionData.
Returns
This object.

Definition at line 128 of file ConversationFactory.java.

128  {
129  this.initialSessionData = initialSessionData;
130  return this;
131  }
ConversationFactory org.bukkit.conversations.ConversationFactory.withLocalEcho ( boolean  localEchoEnabled)

Sets the local echo status for all Conversations created by this factory. 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.
Returns
This object.

Definition at line 75 of file ConversationFactory.java.

75  {
76  this.localEchoEnabled = localEchoEnabled;
77  return this;
78  }
ConversationFactory org.bukkit.conversations.ConversationFactory.withModality ( boolean  modal)

Sets the modality of all Conversations 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.

Parameters
modalThe modality of all conversations to be created.
Returns
This object.

Definition at line 61 of file ConversationFactory.java.

62  {
63  isModal = modal;
64  return this;
65  }
ConversationFactory org.bukkit.conversations.ConversationFactory.withPrefix ( ConversationPrefix  prefix)

Sets the ConversationPrefix that prepends all output from all generated conversations.

The default is a NullConversationPrefix;

Parameters
prefixThe ConversationPrefix to use.
Returns
This object.

Definition at line 89 of file ConversationFactory.java.

89  {
90  this.prefix = prefix;
91  return this;
92  }
ConversationFactory org.bukkit.conversations.ConversationFactory.withTimeout ( int  timeoutSeconds)

Sets the number of inactive seconds to wait before automatically abandoning all generated conversations.

The default is 600 seconds (5 minutes).

Parameters
timeoutSecondsThe number of seconds to wait.
Returns
This object.

Definition at line 103 of file ConversationFactory.java.

References org.bukkit.conversations.ConversationFactory.withConversationCanceller().

103  {
104  return withConversationCanceller(new InactivityConversationCanceller(plugin, timeoutSeconds));
105  }
ConversationFactory withConversationCanceller(ConversationCanceller canceller)

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