summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/conversations/ConversationContext.java
blob: 4ff9858353abc3f2e48b0c47affc33808caa1380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.bukkit.conversations;

import org.bukkit.plugin.Plugin;

import java.util.Map;

/**
 * A ConversationContext provides continuity between nodes in the prompt graph by giving the developer access to the
 * subject of the conversation and a generic map for storing values that are shared between all {@link Prompt}
 * invocations.
 */
public class ConversationContext {
    private Conversable forWhom;
    private Map<Object, Object> sessionData;
    private Plugin plugin;

    /**
     * @param plugin The owning plugin.
     * @param forWhom The subject of the conversation.
     * @param initialSessionData Any initial values to put in the sessionData map.
     */
    public ConversationContext(Plugin plugin, Conversable forWhom, Map<Object, Object> initialSessionData) {
        this.plugin = plugin;
        this.forWhom = forWhom;
        this.sessionData = initialSessionData;
    }

    /**
     * Gets the plugin that owns this conversation.
     * @return The owning plugin.
     */
    public Plugin getPlugin() {
        return plugin;
    }

    /**
     * Gets the subject of the conversation.
     * @return The subject of the conversation.
     */
    public Conversable getForWhom() {
        return forWhom;
    }

    /**
     * Gets session data shared between all {@link Prompt} invocations. Use this as a way
     * to pass data through each Prompt as the conversation develops.
     * @param key The session data key.
     * @return The requested session data.
     */
    public Object getSessionData(Object key) {
        return sessionData.get(key);
    }

    /**
     * Sets session data shared between all {@link Prompt} invocations. Use this as a way to pass
     * data through each prompt as the conversation develops.
     * @param key The session data key.
     * @param value The session data value.
     */
    public void setSessionData(Object key, Object value) {
        sessionData.put(key, value);
    }
}