/** * Constructs a {@link Conversation} in accordance with the defaults set * for this factory. * * @param forWhom The entity for whom the new conversation is mediating. * @return A new conversation. */ public Conversation buildConversation(Conversable forWhom) { //Abort conversation construction if we aren't supposed to talk to non-players if (playerOnlyMessage != null && !(forWhom instanceof Player)) { return new Conversation(plugin, forWhom, new NotPlayerMessagePrompt()); } //Clone any initial session data Map<Object, Object> copiedInitialSessionData = new HashMap<Object, Object>(); copiedInitialSessionData.putAll(initialSessionData); //Build and return a conversation Conversation conversation = new Conversation(plugin, forWhom, firstPrompt, copiedInitialSessionData); conversation.setModal(isModal); conversation.setLocalEchoEnabled(localEchoEnabled); conversation.setPrefix(prefix); //Clone the conversation cancellers for (ConversationCanceller canceller : cancellers) { conversation.addConversationCanceller(canceller.clone()); } //Add the ConversationAbandonedListeners for (ConversationAbandonedListener listener : abandonedListeners) { conversation.addConversationAbandonedListener(listener); } return conversation; }
public void run() { if (conversation.getState() == Conversation.ConversationState.UNSTARTED) { startTimer(); } else if (conversation.getState() == Conversation.ConversationState.STARTED) { cancelling(conversation); conversation.abandon(new ConversationAbandonedEvent(conversation, InactivityConversationCanceller.this)); } } }, timeoutSeconds * 20);
@Override public boolean beginConversation(Conversation conversation) { boolean noQueue = conversations.isEmpty(); conversations.add(conversation); if (noQueue) { conversation.begin(); } return noQueue; }
Conversation convo = new Conversation(am.getPlugin(), player, setup); setup.convo = convo; convo.addConversationAbandonedListener(setup); convo.setLocalEchoEnabled(false); convo.begin(); return true;
/** * 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(); } } }
public ConversationAbandonedEvent(Conversation conversation, ConversationCanceller canceller) { super(conversation); this.context = conversation.getContext(); this.canceller = canceller; }
/** * 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(); } }
/** * Abandons and resets the current conversation. Restores the user's * normal chat behavior. */ public void abandon() { abandon(new ConversationAbandonedEvent(this, new ManuallyAbandonedConversationCanceller())); }
public ConversationAbandonedEvent(Conversation conversation, ConversationCanceller canceller) { super(conversation); this.context = conversation.getContext(); this.canceller = canceller; }
/** * Constructs a {@link Conversation} in accordance with the defaults set * for this factory. * * @param forWhom The entity for whom the new conversation is mediating. * @return A new conversation. */ public Conversation buildConversation(Conversable forWhom) { //Abort conversation construction if we aren't supposed to talk to non-players if (playerOnlyMessage != null && !(forWhom instanceof Player)) { return new Conversation(plugin, forWhom, new NotPlayerMessagePrompt()); } //Clone any initial session data Map<Object, Object> copiedInitialSessionData = new HashMap<Object, Object>(); copiedInitialSessionData.putAll(initialSessionData); //Build and return a conversation Conversation conversation = new Conversation(plugin, forWhom, firstPrompt, copiedInitialSessionData); conversation.setModal(isModal); conversation.setLocalEchoEnabled(localEchoEnabled); conversation.setPrefix(prefix); //Clone the conversation cancellers for (ConversationCanceller canceller : cancellers) { conversation.addConversationCanceller(canceller.clone()); } //Add the ConversationAbandonedListeners for (ConversationAbandonedListener listener : abandonedListeners) { conversation.addConversationAbandonedListener(listener); } return conversation; }
/** * 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(); } } }
public void run() { if (conversation.getState() == Conversation.ConversationState.UNSTARTED) { startTimer(); } else if (conversation.getState() == Conversation.ConversationState.STARTED) { cancelling(conversation); conversation.abandon(new ConversationAbandonedEvent(conversation, InactivityConversationCanceller.this)); } } }, timeoutSeconds * 20);
/** * Abandons and resets the current conversation. Restores the user's * normal chat behavior. */ public void abandon() { abandon(new ConversationAbandonedEvent(this, new ManuallyAbandonedConversationCanceller())); }
begin(); } else { sender.sendMessage(ChatColor.RED + "Only console and players are supported!");
abandon(new ConversationAbandonedEvent(this, canceller)); return; outputNextPrompt();