All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.conversations.ConversationContext Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
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 final Conversable forWhom;
  private final Map sessionData;
  private final 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 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 the entire sessionData map.
   *
   * @return The full sessionData map.
   */
  public Map getAllSessionData() {
    return sessionData;
  }

  /**
   * 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);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy