001 package org.bukkit.conversations;
002
003 import org.bukkit.plugin.Plugin;
004
005 import java.util.Map;
006
007 /**
008 * A ConversationContext provides continuity between nodes in the prompt graph
009 * by giving the developer access to the subject of the conversation and a
010 * generic map for storing values that are shared between all {@link Prompt}
011 * invocations.
012 */
013 public class ConversationContext {
014 private Conversable forWhom;
015 private Map<Object, Object> sessionData;
016 private Plugin plugin;
017
018 /**
019 * @param plugin The owning plugin.
020 * @param forWhom The subject of the conversation.
021 * @param initialSessionData Any initial values to put in the sessionData
022 * map.
023 */
024 public ConversationContext(Plugin plugin, Conversable forWhom, Map<Object, Object> initialSessionData) {
025 this.plugin = plugin;
026 this.forWhom = forWhom;
027 this.sessionData = initialSessionData;
028 }
029
030 /**
031 * Gets the plugin that owns this conversation.
032 *
033 * @return The owning plugin.
034 */
035 public Plugin getPlugin() {
036 return plugin;
037 }
038
039 /**
040 * Gets the subject of the conversation.
041 *
042 * @return The subject of the conversation.
043 */
044 public Conversable getForWhom() {
045 return forWhom;
046 }
047
048 /**
049 * Gets session data shared between all {@link Prompt} invocations. Use
050 * this as a way to pass data through each Prompt as the conversation
051 * develops.
052 *
053 * @param key The session data key.
054 * @return The requested session data.
055 */
056 public Object getSessionData(Object key) {
057 return sessionData.get(key);
058 }
059
060 /**
061 * Sets session data shared between all {@link Prompt} invocations. Use
062 * this as a way to pass data through each prompt as the conversation
063 * develops.
064 *
065 * @param key The session data key.
066 * @param value The session data value.
067 */
068 public void setSessionData(Object key, Object value) {
069 sessionData.put(key, value);
070 }
071 }