From e1f7e0bbe8addf46553c4a5d532a449e15d53996 Mon Sep 17 00:00:00 2001 From: rmichela Date: Sun, 4 Mar 2012 13:59:45 -0500 Subject: [Bleeding] Added local echo toggle to Conversation and ConversationFactory objects. Fixes BUKKIT-1007. --- .../org/bukkit/conversations/Conversation.java | 24 +++++++++++++++++++++- .../bukkit/conversations/ConversationFactory.java | 14 +++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/bukkit/conversations/Conversation.java b/src/main/java/org/bukkit/conversations/Conversation.java index 6a202418..55592552 100644 --- a/src/main/java/org/bukkit/conversations/Conversation.java +++ b/src/main/java/org/bukkit/conversations/Conversation.java @@ -34,6 +34,7 @@ public class Conversation { protected Prompt currentPrompt; protected ConversationContext context; protected boolean modal; + protected boolean localEchoEnabled; protected ConversationPrefix prefix; protected List cancellers; @@ -58,6 +59,7 @@ public class Conversation { this.firstPrompt = firstPrompt; this.context = new ConversationContext(plugin, forWhom, initialSessionData); this.modal = true; + this.localEchoEnabled = true; this.prefix = new NullConversationPrefix(); this.cancellers = new ArrayList(); } @@ -88,6 +90,24 @@ public class Conversation { this.modal = modal; } + /** + * 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. + * @return The status of local echo. + */ + public boolean isLocalEchoEnabled() { + return 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. + * @param localEchoEnabled The status of local echo. + */ + public void setLocalEchoEnabled(boolean localEchoEnabled) { + this.localEchoEnabled = localEchoEnabled; + } + /** * Gets the {@link ConversationPrefix} that prepends all output from this conversation. * @return The ConversationPrefix in use. @@ -163,7 +183,9 @@ public class Conversation { if (currentPrompt != null) { // Echo the user's input - context.getForWhom().sendRawMessage(prefix.getPrefix(context) + input); + if (localEchoEnabled) { + context.getForWhom().sendRawMessage(prefix.getPrefix(context) + input); + } // Test for conversation abandonment based on input for(ConversationCanceller canceller : cancellers) { diff --git a/src/main/java/org/bukkit/conversations/ConversationFactory.java b/src/main/java/org/bukkit/conversations/ConversationFactory.java index 308a302a..6eb28692 100644 --- a/src/main/java/org/bukkit/conversations/ConversationFactory.java +++ b/src/main/java/org/bukkit/conversations/ConversationFactory.java @@ -19,6 +19,7 @@ public class ConversationFactory { protected Plugin plugin; protected boolean isModal; + protected boolean localEchoEnabled; protected ConversationPrefix prefix; protected Prompt firstPrompt; protected Map initialSessionData; @@ -32,6 +33,7 @@ public class ConversationFactory { { this.plugin = plugin; isModal = true; + localEchoEnabled = true; prefix = new NullConversationPrefix(); firstPrompt = Prompt.END_OF_CONVERSATION; initialSessionData = new HashMap(); @@ -53,6 +55,17 @@ public class ConversationFactory { return this; } + /** + * Sets the local echo status for all {@link Conversation}s created by this factory. If local echo is enabled, + * any text submitted to a conversation gets echoed back into the submitter's chat window. + * @param localEchoEnabled The status of local echo. + * @return This object. + */ + public ConversationFactory withLocalEcho(boolean localEchoEnabled) { + this.localEchoEnabled = localEchoEnabled; + return this; + } + /** * Sets the {@link ConversationPrefix} that prepends all output from all generated conversations. * @@ -146,6 +159,7 @@ public class ConversationFactory { //Build and return a conversation Conversation conversation = new Conversation(plugin, forWhom, firstPrompt, copiedInitialSessionData); conversation.setModal(isModal); + conversation.setLocalEchoEnabled(localEchoEnabled); conversation.setPrefix(prefix); //Clone the conversation cancellers -- cgit v1.2.3