Package org.bukkit.conversations
Class ConversationFactory
- java.lang.Object
-
- org.bukkit.conversations.ConversationFactory
-
public class ConversationFactory extends Object
A ConversationFactory is responsible for creating aConversationfrom 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected List<ConversationAbandonedListener>abandonedListenersprotected List<ConversationCanceller>cancellersprotected PromptfirstPromptprotected Map<Object,Object>initialSessionDataprotected booleanisModalprotected booleanlocalEchoEnabledprotected StringplayerOnlyMessageprotected Pluginpluginprotected ConversationPrefixprefix
-
Constructor Summary
Constructors Constructor Description ConversationFactory(@NotNull Plugin plugin)Constructs a ConversationFactory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull ConversationFactoryaddConversationAbandonedListener(@NotNull ConversationAbandonedListener listener)Adds aConversationAbandonedListenerto all conversations constructed by this factory.@NotNull ConversationbuildConversation(@NotNull Conversable forWhom)Constructs aConversationin accordance with the defaults set for this factory.@NotNull ConversationFactorythatExcludesNonPlayersWithMessage(@Nullable String playerOnlyMessage)Prevents this factory from creating a conversation for non-playerConversableobjects.@NotNull ConversationFactorywithConversationCanceller(@NotNull ConversationCanceller canceller)Adds aConversationCancellerto constructed conversations.@NotNull ConversationFactorywithEscapeSequence(@NotNull String escapeSequence)Sets the player input that, when received, will immediately terminate the conversation.@NotNull ConversationFactorywithFirstPrompt(@Nullable Prompt firstPrompt)Sets the first prompt to use in all generated conversations.@NotNull ConversationFactorywithInitialSessionData(@NotNull Map<Object,Object> initialSessionData)Sets any initial data with which to populate the conversation context sessionData map.@NotNull ConversationFactorywithLocalEcho(boolean localEchoEnabled)Sets the local echo status for allConversations created by this factory.@NotNull ConversationFactorywithModality(boolean modal)Sets the modality of allConversations created by this factory.@NotNull ConversationFactorywithPrefix(@NotNull ConversationPrefix prefix)Sets theConversationPrefixthat prepends all output from all generated conversations.@NotNull ConversationFactorywithTimeout(int timeoutSeconds)Sets the number of inactive seconds to wait before automatically abandoning all generated conversations.
-
-
-
Field Detail
-
plugin
protected Plugin plugin
-
isModal
protected boolean isModal
-
localEchoEnabled
protected boolean localEchoEnabled
-
prefix
protected ConversationPrefix prefix
-
firstPrompt
protected Prompt firstPrompt
-
playerOnlyMessage
protected String playerOnlyMessage
-
cancellers
protected List<ConversationCanceller> cancellers
-
abandonedListeners
protected List<ConversationAbandonedListener> abandonedListeners
-
-
Constructor Detail
-
ConversationFactory
public ConversationFactory(@NotNull @NotNull Plugin plugin)Constructs a ConversationFactory.- Parameters:
plugin- The plugin that owns the factory.
-
-
Method Detail
-
withModality
@NotNull public @NotNull ConversationFactory withModality(boolean modal)
Sets the modality of allConversations 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:
modal- The modality of all conversations to be created.- Returns:
- This object.
-
withLocalEcho
@NotNull public @NotNull ConversationFactory withLocalEcho(boolean localEchoEnabled)
Sets the local echo status for allConversations 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:
localEchoEnabled- The status of local echo.- Returns:
- This object.
-
withPrefix
@NotNull public @NotNull ConversationFactory withPrefix(@NotNull @NotNull ConversationPrefix prefix)
Sets theConversationPrefixthat prepends all output from all generated conversations.The default is a
NullConversationPrefix;- Parameters:
prefix- The ConversationPrefix to use.- Returns:
- This object.
-
withTimeout
@NotNull public @NotNull 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:
timeoutSeconds- The number of seconds to wait.- Returns:
- This object.
-
withFirstPrompt
@NotNull public @NotNull ConversationFactory withFirstPrompt(@Nullable @Nullable Prompt firstPrompt)
Sets the first prompt to use in all generated conversations.The default is Prompt.END_OF_CONVERSATION.
- Parameters:
firstPrompt- The first prompt.- Returns:
- This object.
-
withInitialSessionData
@NotNull public @NotNull ConversationFactory withInitialSessionData(@NotNull @NotNull Map<Object,Object> initialSessionData)
Sets any initial data with which to populate the conversation context sessionData map.- Parameters:
initialSessionData- The conversation context's initial sessionData.- Returns:
- This object.
-
withEscapeSequence
@NotNull public @NotNull ConversationFactory withEscapeSequence(@NotNull @NotNull String escapeSequence)
Sets the player input that, when received, will immediately terminate the conversation.- Parameters:
escapeSequence- Input to terminate the conversation.- Returns:
- This object.
-
withConversationCanceller
@NotNull public @NotNull ConversationFactory withConversationCanceller(@NotNull @NotNull ConversationCanceller canceller)
Adds aConversationCancellerto constructed conversations.- Parameters:
canceller- TheConversationCancellerto add.- Returns:
- This object.
-
thatExcludesNonPlayersWithMessage
@NotNull public @NotNull ConversationFactory thatExcludesNonPlayersWithMessage(@Nullable @Nullable String playerOnlyMessage)
Prevents this factory from creating a conversation for non-playerConversableobjects.- Parameters:
playerOnlyMessage- The message to return to a non-play in lieu of starting a conversation.- Returns:
- This object.
-
addConversationAbandonedListener
@NotNull public @NotNull ConversationFactory addConversationAbandonedListener(@NotNull @NotNull ConversationAbandonedListener listener)
Adds aConversationAbandonedListenerto all conversations constructed by this factory.- Parameters:
listener- The listener to add.- Returns:
- This object.
-
buildConversation
@NotNull public @NotNull Conversation buildConversation(@NotNull @NotNull Conversable forWhom)
Constructs aConversationin accordance with the defaults set for this factory.- Parameters:
forWhom- The entity for whom the new conversation is mediating.- Returns:
- A new conversation.
-
-