[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:
Bukkit/Spigot
2012-03-04 16:29:56 -05:00
parent 819611b351
commit 4b5a0b8ed8
9 changed files with 149 additions and 6 deletions

View File

@@ -0,0 +1,48 @@
package org.bukkit.conversations;
import java.util.EventObject;
/**
* ConversationAbandonedEvent contains information about an abandoned conversation.
*/
public class ConversationAbandonedEvent extends EventObject {
private ConversationContext context;
private ConversationCanceller canceller;
public ConversationAbandonedEvent(Conversation conversation) {
this(conversation, null);
}
public ConversationAbandonedEvent(Conversation conversation, ConversationCanceller canceller) {
super(conversation);
this.context = conversation.getContext();
this.canceller = canceller;
}
/**
* Gets the object that caused the conversation to be abandoned.
* @return The object that abandoned the conversation.
*/
public ConversationCanceller getCanceller() {
return canceller;
}
/**
* Gets the abandoned conversation's conversation context.
* @return The abandoned conversation's conversation context.
*/
public ConversationContext getContext() {
return context;
}
/**
* Indicates how the conversation was abandoned - naturally as part of the prompt chain or prematurely via a
* {@link ConversationCanceller}.
* @return True if the conversation is abandoned gracefully by a {@link Prompt} returning null
* or the next prompt. False of the conversations is abandoned prematurely by a ConversationCanceller.
*/
public boolean gracefulExit() {
return canceller == null;
}
}