[Bleeding] Added ConversationAbandonedEvent and supporting infrastructure. Whenever a conversation exits, the ConversationAbandonedEvent is triggered with details about how the conversation ended and what, if anything caused it to end. Fixes BUKKIT-986
By: rmichela <deltahat@gmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package org.bukkit.conversations;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -37,6 +36,7 @@ public class Conversation {
|
||||
protected boolean localEchoEnabled;
|
||||
protected ConversationPrefix prefix;
|
||||
protected List<ConversationCanceller> cancellers;
|
||||
protected List<ConversationAbandonedListener> abandonedListeners;
|
||||
|
||||
/**
|
||||
* Initializes a new Conversation.
|
||||
@@ -62,6 +62,7 @@ public class Conversation {
|
||||
this.localEchoEnabled = true;
|
||||
this.prefix = new NullConversationPrefix();
|
||||
this.cancellers = new ArrayList<ConversationCanceller>();
|
||||
this.abandonedListeners = new ArrayList<ConversationAbandonedListener>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +191,7 @@ public class Conversation {
|
||||
// Test for conversation abandonment based on input
|
||||
for(ConversationCanceller canceller : cancellers) {
|
||||
if (canceller.cancelBasedOnInput(context, input)) {
|
||||
abandon();
|
||||
abandon(new ConversationAbandonedEvent(this, canceller));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -201,14 +202,41 @@ public class Conversation {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a {@link ConversationAbandonedListener}.
|
||||
* @param listener The listener to add.
|
||||
*/
|
||||
public synchronized void addConversationAbandonedListener(ConversationAbandonedListener listener) {
|
||||
abandonedListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link ConversationAbandonedListener}.
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public synchronized void removeConversationAbandonedListener(ConversationAbandonedListener listener) {
|
||||
abandonedListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandons and resets the current conversation. Restores the user's normal chat behavior.
|
||||
*/
|
||||
public void abandon() {
|
||||
abandon(new ConversationAbandonedEvent(this, new ManuallyAbandonedConversationCanceller()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandons and resets the current conversation. Restores the user's normal chat behavior.
|
||||
* @param details Details about why the conversation was abandoned
|
||||
*/
|
||||
public synchronized void abandon(ConversationAbandonedEvent details) {
|
||||
if (!abandoned) {
|
||||
abandoned = true;
|
||||
currentPrompt = null;
|
||||
context.getForWhom().abandonConversation(this);
|
||||
for (ConversationAbandonedListener listener : abandonedListeners) {
|
||||
listener.conversationAbandoned(details);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +245,7 @@ public class Conversation {
|
||||
*/
|
||||
public void outputNextPrompt() {
|
||||
if (currentPrompt == null) {
|
||||
abandon();
|
||||
abandon(new ConversationAbandonedEvent(this));
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(prefix.getPrefix(context) + currentPrompt.getPromptText(context));
|
||||
if (!currentPrompt.blocksForInput(context)) {
|
||||
|
||||
Reference in New Issue
Block a user