程序包 org.bukkit.conversations

# 类 Conversation

java.lang.Object
org.bukkit.conversations.Conversation

public class Conversation extends Object
The Conversation class is responsible for tracking the current state of a conversation, displaying prompts to the user, and dispatching the user's response to the appropriate place. Conversation objects are not typically instantiated directly. Instead a `ConversationFactory` is used to construct identical conversations on demand.

Conversation flow consists of a directed graph of `Prompt` objects. Each time a prompt gets input from the user, it must return the next prompt in the graph. Since each Prompt chooses the next Prompt, complex conversation trees can be implemented where the nature of the player's response directs the flow of the conversation.

Each conversation has a `ConversationPrefix` that prepends all output from the conversation to the player. The ConversationPrefix can be used to display the plugin name or conversation status as the conversation evolves.

Each conversation has a timeout measured in the number of inactive seconds to wait before abandoning the conversation. If the inactivity timeout is reached, the conversation is abandoned and the user's incoming and outgoing chat is returned to normal.

You should not construct a conversation manually. Instead, use the `ConversationFactory` for access to all available options.

- ## 嵌套类概要

  嵌套类
  修饰符和类型
  类
  说明
  `static enum`
  `Conversation.ConversationState`

- ## 字段概要

  字段
  修饰符和类型
  字段
  说明
  `protected List<ConversationAbandonedListener>`
  `abandonedListeners`
  `protected List<ConversationCanceller>`
  `cancellers`
  `protected ConversationContext`
  `context`
  `protected Prompt`
  `currentPrompt`
  `protected boolean`
  `localEchoEnabled`
  `protected boolean`
  `modal`
  `protected ConversationPrefix`
  `prefix`

- ## 构造器概要

  构造器
  构造器
  说明
  `Conversation(@Nullable Plugin plugin, @NotNull Conversable forWhom, @Nullable Prompt firstPrompt)`
  Initializes a new Conversation.
  `Conversation(@Nullable Plugin plugin, @NotNull Conversable forWhom, @Nullable Prompt firstPrompt, @NotNull Map<Object,Object> initialSessionData)`
  Initializes a new Conversation.

- ## 方法概要

  修饰符和类型
  方法
  说明
  `void`
  `abandon()`
  Abandons and resets the current conversation.
  `void`
  `abandon(@NotNull ConversationAbandonedEvent details)`
  Abandons and resets the current conversation.
  `void`
  `acceptInput(@NotNull String input)`
  Passes player input into the current prompt.
  `void`
  `addConversationAbandonedListener(@NotNull ConversationAbandonedListener listener)`
  Adds a `ConversationAbandonedListener`.
  `void`
  `begin()`
  Displays the first prompt of this conversation and begins redirecting the user's chat responses.
  `@NotNull List<ConversationCanceller>`
  `getCancellers()`
  Gets the list of `ConversationCanceller`s
  `@NotNull ConversationContext`
  `getContext()`
  Returns the Conversation's `ConversationContext`.
  `@NotNull Conversable`
  `getForWhom()`
  Gets the entity for whom this conversation is mediating.
  `@NotNull ConversationPrefix`
  `getPrefix()`
  Gets the `ConversationPrefix` that prepends all output from this conversation.
  `@NotNull Conversation.ConversationState`
  `getState()`
  Returns Returns the current state of the conversation.
  `boolean`
  `isLocalEchoEnabled()`
  Gets the status of local echo for this conversation.
  `boolean`
  `isModal()`
  Gets the modality of this conversation.
  `void`
  `outputNextPrompt()`
  Displays the next user prompt and abandons the conversation if the next prompt is null.
  `void`
  `removeConversationAbandonedListener(@NotNull ConversationAbandonedListener listener)`
  Removes a `ConversationAbandonedListener`.
  `void`
  `setLocalEchoEnabled(boolean localEchoEnabled)`
  Sets the status of local echo for this conversation.

  ### 从类继承的方法 java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 字段详细资料

  - ### currentPrompt

    protected Prompt currentPrompt

  - ### context

    protected ConversationContext context

  - ### modal

    protected boolean modal

  - ### localEchoEnabled

    protected boolean localEchoEnabled

  - ### prefix

    protected ConversationPrefix prefix

  - ### cancellers

    protected List<ConversationCanceller> cancellers

  - ### abandonedListeners

    protected List<ConversationAbandonedListener> abandonedListeners

- ## 构造器详细资料

  - ### Conversation

    public Conversation(@Nullable @Nullable Plugin plugin, @NotNull @NotNull Conversable forWhom, @Nullable @Nullable Prompt firstPrompt)
    Initializes a new Conversation.
    参数:
      `plugin` - The plugin that owns this conversation.
      `forWhom` - The entity for whom this conversation is mediating.
      `firstPrompt` - The first prompt in the conversation graph.

  - ### Conversation

    public Conversation(@Nullable @Nullable Plugin plugin, @NotNull @NotNull Conversable forWhom, @Nullable @Nullable Prompt firstPrompt, @NotNull @NotNull Map<Object,Object> initialSessionData)
    Initializes a new Conversation.
    参数:
      `plugin` - The plugin that owns this conversation.
      `forWhom` - The entity for whom this conversation is mediating.
      `firstPrompt` - The first prompt in the conversation graph.
      `initialSessionData` - Any initial values to put in the conversation context sessionData map.

- ## 方法详细资料

  - ### getForWhom

    @NotNull public @NotNull Conversable getForWhom()
    Gets the entity for whom this conversation is mediating.
    返回:
      The entity.

  - ### isModal

    public boolean isModal()
    Gets the modality of this conversation. If a conversation is modal, all messages directed to the player are suppressed for the duration of the conversation.
    返回:
      The conversation modality.

  - ### isLocalEchoEnabled

    public boolean isLocalEchoEnabled()
    Gets the status of local echo for this conversation. If local echo is enabled, any text submitted to a conversation gets echoed back into the submitter's chat window.
    返回:
      The status of local echo.

  - ### setLocalEchoEnabled

    public void setLocalEchoEnabled(boolean localEchoEnabled)
    Sets the status of local echo for this conversation. If local echo is enabled, any text submitted to a conversation gets echoed back into the submitter's chat window.
    参数:
      `localEchoEnabled` - The status of local echo.

  - ### getPrefix

    @NotNull public @NotNull ConversationPrefix getPrefix()
    Gets the `ConversationPrefix` that prepends all output from this conversation.
    返回:
      The ConversationPrefix in use.

  - ### getCancellers

    @NotNull public @NotNull List<ConversationCanceller> getCancellers()
    Gets the list of `ConversationCanceller`s
    返回:
      The list.

  - ### getContext

    @NotNull public @NotNull ConversationContext getContext()
    Returns the Conversation's `ConversationContext`.
    返回:
      The ConversationContext.

  - ### begin

    public void begin()
    Displays the first prompt of this conversation and begins redirecting the user's chat responses.

  - ### getState

    @NotNull public @NotNull Conversation.ConversationState getState()
    Returns Returns the current state of the conversation.
    返回:
      The current state of the conversation.

  - ### acceptInput

    public void acceptInput(@NotNull @NotNull String input)
    Passes player input into the current prompt. The next prompt (as determined by the current prompt) is then displayed to the user.
    参数:
      `input` - The user's chat text.

  - ### addConversationAbandonedListener

    public void addConversationAbandonedListener(@NotNull @NotNull ConversationAbandonedListener listener)
    Adds a `ConversationAbandonedListener`.
    参数:
      `listener` - The listener to add.

  - ### removeConversationAbandonedListener

    public void removeConversationAbandonedListener(@NotNull @NotNull ConversationAbandonedListener listener)
    Removes a `ConversationAbandonedListener`.
    参数:
      `listener` - The listener to remove.

  - ### abandon

    public void abandon()
    Abandons and resets the current conversation. Restores the user's normal chat behavior.

  - ### abandon

    public void abandon(@NotNull @NotNull ConversationAbandonedEvent details)
    Abandons and resets the current conversation. Restores the user's normal chat behavior.
    参数:
      `details` - Details about why the conversation was abandoned

  - ### outputNextPrompt

    public void outputNextPrompt()
    Displays the next user prompt and abandons the conversation if the next prompt is null.