mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-22 00:04:59 +01:00
[Bleeding] Added local echo toggle to Conversation and ConversationFactory objects. Fixes BUKKIT-1007.
By: rmichela <deltahat@gmail.com>
This commit is contained in:
parent
4644c277b4
commit
819611b351
2 changed files with 37 additions and 1 deletions
|
@ -34,6 +34,7 @@ public class Conversation {
|
|||
protected Prompt currentPrompt;
|
||||
protected ConversationContext context;
|
||||
protected boolean modal;
|
||||
protected boolean localEchoEnabled;
|
||||
protected ConversationPrefix prefix;
|
||||
protected List<ConversationCanceller> 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<ConversationCanceller>();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
|
|
@ -19,6 +19,7 @@ public class ConversationFactory {
|
|||
|
||||
protected Plugin plugin;
|
||||
protected boolean isModal;
|
||||
protected boolean localEchoEnabled;
|
||||
protected ConversationPrefix prefix;
|
||||
protected Prompt firstPrompt;
|
||||
protected Map<Object, Object> 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<Object, Object>();
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue