Search in sources :

Example 1 with ConversationContext

use of org.bukkit.conversations.ConversationContext in project CitizensAPI by CitizensDev.

the class ModalMenuInput method captureInput.

public static void captureInput(Player player, InventoryMenu menu, Consumer<String> input) {
    menu.close(player);
    // TODO: this unregisters events incorrectly currently
    player.beginConversation(new ConversationFactory(CitizensAPI.getPlugin()).addConversationAbandonedListener((evt) -> {
        menu.present(player);
    }).withLocalEcho(false).withEscapeSequence("exit").withModality(false).withTimeout(60).withFirstPrompt(new StringPrompt() {

        @Override
        public Prompt acceptInput(ConversationContext ctx, String text) {
            input.accept(text);
            menu.present(player);
            return null;
        }

        @Override
        public String getPromptText(ConversationContext ctx) {
            return "";
        }
    }).buildConversation(player));
}
Also used : Consumer(java.util.function.Consumer) CitizensAPI(net.citizensnpcs.api.CitizensAPI) StringPrompt(org.bukkit.conversations.StringPrompt) ConversationFactory(org.bukkit.conversations.ConversationFactory) ConversationContext(org.bukkit.conversations.ConversationContext) Prompt(org.bukkit.conversations.Prompt) Player(org.bukkit.entity.Player) ConversationFactory(org.bukkit.conversations.ConversationFactory) StringPrompt(org.bukkit.conversations.StringPrompt) StringPrompt(org.bukkit.conversations.StringPrompt) Prompt(org.bukkit.conversations.Prompt) ConversationContext(org.bukkit.conversations.ConversationContext)

Aggregations

Consumer (java.util.function.Consumer)1 CitizensAPI (net.citizensnpcs.api.CitizensAPI)1 ConversationContext (org.bukkit.conversations.ConversationContext)1 ConversationFactory (org.bukkit.conversations.ConversationFactory)1 Prompt (org.bukkit.conversations.Prompt)1 StringPrompt (org.bukkit.conversations.StringPrompt)1 Player (org.bukkit.entity.Player)1