[Bleeding] Added local echo toggle to Conversation and ConversationFactory objects. Fixes BUKKIT-1007.
This commit is contained in:
parent
04e4c96049
commit
e1f7e0bbe8
@ -34,6 +34,7 @@ public class Conversation {
|
|||||||
protected Prompt currentPrompt;
|
protected Prompt currentPrompt;
|
||||||
protected ConversationContext context;
|
protected ConversationContext context;
|
||||||
protected boolean modal;
|
protected boolean modal;
|
||||||
|
protected boolean localEchoEnabled;
|
||||||
protected ConversationPrefix prefix;
|
protected ConversationPrefix prefix;
|
||||||
protected List<ConversationCanceller> cancellers;
|
protected List<ConversationCanceller> cancellers;
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ public class Conversation {
|
|||||||
this.firstPrompt = firstPrompt;
|
this.firstPrompt = firstPrompt;
|
||||||
this.context = new ConversationContext(plugin, forWhom, initialSessionData);
|
this.context = new ConversationContext(plugin, forWhom, initialSessionData);
|
||||||
this.modal = true;
|
this.modal = true;
|
||||||
|
this.localEchoEnabled = true;
|
||||||
this.prefix = new NullConversationPrefix();
|
this.prefix = new NullConversationPrefix();
|
||||||
this.cancellers = new ArrayList<ConversationCanceller>();
|
this.cancellers = new ArrayList<ConversationCanceller>();
|
||||||
}
|
}
|
||||||
@ -88,6 +90,24 @@ public class Conversation {
|
|||||||
this.modal = modal;
|
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.
|
* Gets the {@link ConversationPrefix} that prepends all output from this conversation.
|
||||||
* @return The ConversationPrefix in use.
|
* @return The ConversationPrefix in use.
|
||||||
@ -163,7 +183,9 @@ public class Conversation {
|
|||||||
if (currentPrompt != null) {
|
if (currentPrompt != null) {
|
||||||
|
|
||||||
// Echo the user's input
|
// 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
|
// Test for conversation abandonment based on input
|
||||||
for(ConversationCanceller canceller : cancellers) {
|
for(ConversationCanceller canceller : cancellers) {
|
||||||
|
@ -19,6 +19,7 @@ public class ConversationFactory {
|
|||||||
|
|
||||||
protected Plugin plugin;
|
protected Plugin plugin;
|
||||||
protected boolean isModal;
|
protected boolean isModal;
|
||||||
|
protected boolean localEchoEnabled;
|
||||||
protected ConversationPrefix prefix;
|
protected ConversationPrefix prefix;
|
||||||
protected Prompt firstPrompt;
|
protected Prompt firstPrompt;
|
||||||
protected Map<Object, Object> initialSessionData;
|
protected Map<Object, Object> initialSessionData;
|
||||||
@ -32,6 +33,7 @@ public class ConversationFactory {
|
|||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
isModal = true;
|
isModal = true;
|
||||||
|
localEchoEnabled = true;
|
||||||
prefix = new NullConversationPrefix();
|
prefix = new NullConversationPrefix();
|
||||||
firstPrompt = Prompt.END_OF_CONVERSATION;
|
firstPrompt = Prompt.END_OF_CONVERSATION;
|
||||||
initialSessionData = new HashMap<Object, Object>();
|
initialSessionData = new HashMap<Object, Object>();
|
||||||
@ -53,6 +55,17 @@ public class ConversationFactory {
|
|||||||
return this;
|
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.
|
* Sets the {@link ConversationPrefix} that prepends all output from all generated conversations.
|
||||||
*
|
*
|
||||||
@ -146,6 +159,7 @@ public class ConversationFactory {
|
|||||||
//Build and return a conversation
|
//Build and return a conversation
|
||||||
Conversation conversation = new Conversation(plugin, forWhom, firstPrompt, copiedInitialSessionData);
|
Conversation conversation = new Conversation(plugin, forWhom, firstPrompt, copiedInitialSessionData);
|
||||||
conversation.setModal(isModal);
|
conversation.setModal(isModal);
|
||||||
|
conversation.setLocalEchoEnabled(localEchoEnabled);
|
||||||
conversation.setPrefix(prefix);
|
conversation.setPrefix(prefix);
|
||||||
|
|
||||||
//Clone the conversation cancellers
|
//Clone the conversation cancellers
|
||||||
|
Loading…
x
Reference in New Issue
Block a user