From b5e92871eb5b2195c187e0082fe22d9e3eb3b7e4 Mon Sep 17 00:00:00 2001 From: rmichela Date: Sun, 4 Mar 2012 16:30:14 -0500 Subject: [PATCH] [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 --- .../craftbukkit/command/CraftConsoleCommandSender.java | 8 +++++++- .../craftbukkit/conversations/ConversationTracker.java | 8 +++++--- .../java/org/bukkit/craftbukkit/entity/CraftPlayer.java | 8 +++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java index 00f18d1d91..b6d1747e1e 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java +++ b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java @@ -3,6 +3,8 @@ package org.bukkit.craftbukkit.command; import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.conversations.Conversation; +import org.bukkit.conversations.ConversationAbandonedEvent; +import org.bukkit.conversations.ManuallyAbandonedConversationCanceller; import org.bukkit.craftbukkit.conversations.ConversationTracker; /** @@ -47,7 +49,11 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co } public void abandonConversation(Conversation conversation) { - conversationTracker.abandonConversation(conversation); + conversationTracker.abandonConversation(conversation, new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller())); + } + + public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) { + conversationTracker.abandonConversation(conversation, details); } public void acceptConversationInput(String input) { diff --git a/src/main/java/org/bukkit/craftbukkit/conversations/ConversationTracker.java b/src/main/java/org/bukkit/craftbukkit/conversations/ConversationTracker.java index c5553ddfdd..1d770a5919 100644 --- a/src/main/java/org/bukkit/craftbukkit/conversations/ConversationTracker.java +++ b/src/main/java/org/bukkit/craftbukkit/conversations/ConversationTracker.java @@ -1,6 +1,8 @@ package org.bukkit.craftbukkit.conversations; import org.bukkit.conversations.Conversation; +import org.bukkit.conversations.ConversationAbandonedEvent; +import org.bukkit.conversations.ManuallyAbandonedConversationCanceller; import java.util.LinkedList; @@ -22,10 +24,10 @@ public class ConversationTracker { return true; } - public synchronized void abandonConversation(Conversation conversation) { + public synchronized void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) { if (!conversationQueue.isEmpty()) { if (conversationQueue.getFirst() == conversation) { - conversation.abandon(); + conversation.abandon(details); } if (conversationQueue.contains(conversation)) { conversationQueue.remove(conversation); @@ -41,7 +43,7 @@ public class ConversationTracker { LinkedList oldQueue = conversationQueue; conversationQueue = new LinkedList(); for(Conversation conversation : oldQueue) { - conversation.abandon(); + conversation.abandon(new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller())); } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 3f8a02d927..e877536e81 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -39,6 +39,8 @@ import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.conversations.Conversation; +import org.bukkit.conversations.ConversationAbandonedEvent; +import org.bukkit.conversations.ManuallyAbandonedConversationCanceller; import org.bukkit.craftbukkit.conversations.ConversationTracker; import org.bukkit.craftbukkit.CraftEffect; import org.bukkit.craftbukkit.CraftOfflinePlayer; @@ -707,7 +709,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } public void abandonConversation(Conversation conversation) { - conversationTracker.abandonConversation(conversation); + conversationTracker.abandonConversation(conversation, new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller())); + } + + public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) { + conversationTracker.abandonConversation(conversation, details); } public void acceptConversationInput(String input) {