/** * Gets the entity for whom this conversation is mediating. * * @return The entity. */ public Conversable getForWhom() { return context.getForWhom(); }
/** * Displays the first prompt of this conversation and begins redirecting * the user's chat responses. */ public void begin() { if (currentPrompt == null) { abandoned = false; currentPrompt = firstPrompt; context.getForWhom().beginConversation(this); } }
/** * Abandons and resets the current conversation. Restores the user's * normal chat behavior. * * @param details Details about why the conversation was abandoned */ public synchronized void abandon(ConversationAbandonedEvent details) { if (!abandoned) { abandoned = true; currentPrompt = null; context.getForWhom().abandonConversation(this); for (ConversationAbandonedListener listener : abandonedListeners) { listener.conversationAbandoned(details); } } }
/** * Accepts and processes input from the user and validates it. If * validation fails, this prompt is returned for re-execution, otherwise * the next Prompt in the prompt graph is returned. * * @param context Context information about the conversation. * @param input The input text from the user. * @return This prompt or the next Prompt in the prompt graph. */ public Prompt acceptInput(ConversationContext context, String input) { if (isInputValid(context, input)) { return acceptValidatedInput(context, input); } else { String failPrompt = getFailedValidationText(context, input); if (failPrompt != null) { context.getForWhom().sendRawMessage(ChatColor.RED + failPrompt); } // Redisplay this prompt to the user to re-collect input return this; } }
/** * Displays the next user prompt and abandons the conversation if the next * prompt is null. */ public void outputNextPrompt() { if (currentPrompt == null) { abandon(new ConversationAbandonedEvent(this)); } else { context.getForWhom().sendRawMessage(prefix.getPrefix(context) + currentPrompt.getPromptText(context)); if (!currentPrompt.blocksForInput(context)) { currentPrompt = currentPrompt.acceptInput(context, null); outputNextPrompt(); } } }
/** * Passes player input into the current prompt. The next prompt (as * determined by the current prompt) is then displayed to the user. * * @param input The user's chat text. */ public void acceptInput(String input) { if (currentPrompt != null) { // Echo the user's input if (localEchoEnabled) { context.getForWhom().sendRawMessage(prefix.getPrefix(context) + input); } // Test for conversation abandonment based on input for(ConversationCanceller canceller : cancellers) { if (canceller.cancelBasedOnInput(context, input)) { abandon(new ConversationAbandonedEvent(this, canceller)); return; } } // Not abandoned, output the next prompt currentPrompt = currentPrompt.acceptInput(context, input); outputNextPrompt(); } }
/** * Gets the entity for whom this conversation is mediating. * * @return The entity. */ public Conversable getForWhom() { return context.getForWhom(); }
/** * Displays the first prompt of this conversation and begins redirecting * the user's chat responses. */ public void begin() { if (currentPrompt == null) { abandoned = false; currentPrompt = firstPrompt; context.getForWhom().beginConversation(this); } }
/** * Abandons and resets the current conversation. Restores the user's * normal chat behavior. * * @param details Details about why the conversation was abandoned */ public synchronized void abandon(ConversationAbandonedEvent details) { if (!abandoned) { abandoned = true; currentPrompt = null; context.getForWhom().abandonConversation(this); for (ConversationAbandonedListener listener : abandonedListeners) { listener.conversationAbandoned(details); } } }
/** * Accepts and processes input from the user and validates it. If * validation fails, this prompt is returned for re-execution, otherwise * the next Prompt in the prompt graph is returned. * * @param context Context information about the conversation. * @param input The input text from the user. * @return This prompt or the next Prompt in the prompt graph. */ public Prompt acceptInput(ConversationContext context, String input) { if (isInputValid(context, input)) { return acceptValidatedInput(context, input); } else { String failPrompt = getFailedValidationText(context, input); if (failPrompt != null) { context.getForWhom().sendRawMessage(ChatColor.RED + failPrompt); } // Redisplay this prompt to the user to re-collect input return this; } }
context.getForWhom().sendRawMessage(prefix.getPrefix(context) + input);
/** * Displays the next user prompt and abandons the conversation if the next * prompt is null. */ public void outputNextPrompt() { if (currentPrompt == null) { abandon(new ConversationAbandonedEvent(this)); } else { context.getForWhom().sendRawMessage(prefix.getPrefix(context) + currentPrompt.getPromptText(context)); if (!currentPrompt.blocksForInput(context)) { currentPrompt = currentPrompt.acceptInput(context, null); outputNextPrompt(); } } }
@Override public void conversationAbandoned(ConversationAbandonedEvent event) { try { final Conversable whom = event.getContext().getForWhom();