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.

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.

listenerThe listener to add.
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.

forWhomThe entity for whom the new conversation is mediating.
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  }
194  //Clone any initial session data
195  Map<Object, Object> copiedInitialSessionData = new HashMap<Object, Object>();
196  copiedInitialSessionData.putAll(initialSessionData);
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);
204  //Clone the conversation cancellers
205  for (ConversationCanceller canceller : cancellers) {
206  conversation.addConversationCanceller(canceller.clone());
207  }
209  //Add the ConversationAbandonedListeners
210  for (ConversationAbandonedListener listener : abandonedListeners) {
211  conversation.addConversationAbandonedListener(listener);
212  }
214  return conversation;
215  }
ConversationFactory org.bukkit.conversations.ConversationFactory.thatExcludesNonPlayersWithMessage ( String  playerOnlyMessage)

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

playerOnlyMessageThe message to return to a non-play in lieu of starting a conversation.
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.

cancellerThe ConversationCanceller to add.
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.

escapeSequenceInput to terminate the conversation.
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.

firstPromptThe first prompt.
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.

initialSessionDataThe conversation context's initial sessionData.
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.

localEchoEnabledThe status of local echo.
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.

modalThe modality of all conversations to be created.
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;

prefixThe ConversationPrefix to use.
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).

timeoutSecondsThe number of seconds to wait.
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: