Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
ConversationContext.java
1 package org.bukkit.conversations;
2 
3 import org.bukkit.plugin.Plugin;
4 
5 import java.util.Map;
6 
7 /**
8  * A ConversationContext provides continuity between nodes in the prompt graph
9  * by giving the developer access to the subject of the conversation and a
10  * generic map for storing values that are shared between all {@link Prompt}
11  * invocations.
12  */
13 public class ConversationContext {
14  private Conversable forWhom;
15  private Map<Object, Object> sessionData;
16  private Plugin plugin;
17 
18  /**
19  * @param plugin The owning plugin.
20  * @param forWhom The subject of the conversation.
21  * @param initialSessionData Any initial values to put in the sessionData
22  * map.
23  */
24  public ConversationContext(Plugin plugin, Conversable forWhom, Map<Object, Object> initialSessionData) {
25  this.plugin = plugin;
26  this.forWhom = forWhom;
27  this.sessionData = initialSessionData;
28  }
29 
30  /**
31  * Gets the plugin that owns this conversation.
32  *
33  * @return The owning plugin.
34  */
35  public Plugin getPlugin() {
36  return plugin;
37  }
38 
39  /**
40  * Gets the subject of the conversation.
41  *
42  * @return The subject of the conversation.
43  */
45  return forWhom;
46  }
47 
48  /**
49  * Gets session data shared between all {@link Prompt} invocations. Use
50  * this as a way to pass data through each Prompt as the conversation
51  * develops.
52  *
53  * @param key The session data key.
54  * @return The requested session data.
55  */
56  public Object getSessionData(Object key) {
57  return sessionData.get(key);
58  }
59 
60  /**
61  * Sets session data shared between all {@link Prompt} invocations. Use
62  * this as a way to pass data through each prompt as the conversation
63  * develops.
64  *
65  * @param key The session data key.
66  * @param value The session data value.
67  */
68  public void setSessionData(Object key, Object value) {
69  sessionData.put(key, value);
70  }
71 }
ConversationContext(Plugin plugin, Conversable forWhom, Map< Object, Object > initialSessionData)