Skip to content

Commit

Permalink
Fix issue when AbandonedListener targeted correct input values.
Browse files Browse the repository at this point in the history
I did not understand correctly how that listener worked.
  • Loading branch information
BONNe committed Apr 29, 2020
1 parent 4ab706b commit 8d55143
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/main/java/world/bentobox/challenges/panel/CommonGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,13 @@ public Prompt acceptInput(ConversationContext conversationContext, String answer
// On cancel conversation will be closed.
withEscapeSequence("cancel").
// Use null value in consumer to detect if user has abandoned conversation.
addConversationAbandonedListener(abandonedEvent -> consumer.accept(null)).
addConversationAbandonedListener(abandonedEvent ->
{
if (!abandonedEvent.gracefulExit())
{
consumer.accept(null);
}
}).
withPrefix(context -> user.getTranslation("challenges.gui.questions.prefix")).
buildConversation(user.getPlayer());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,13 @@ protected Prompt acceptValidatedInput(ConversationContext context, String input)
// On cancel conversation will be closed.
withEscapeSequence("cancel").
// Use null value in consumer to detect if user has abandoned conversation.
addConversationAbandonedListener(abandonedEvent -> consumer.accept(null)).
addConversationAbandonedListener(abandonedEvent ->
{
if (!abandonedEvent.gracefulExit())
{
consumer.accept(null);
}
}).
withLocalEcho(false).
withPrefix(context -> user.getTranslation("challenges.gui.questions.prefix")).
buildConversation(user.getPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,13 @@ public String getPromptText(ConversationContext conversationContext)
// On cancel conversation will be closed.
withEscapeSequence("cancel").
// Use null value in consumer to detect if user has abandoned conversation.
addConversationAbandonedListener(abandonedEvent -> consumer.accept(null)).
addConversationAbandonedListener(abandonedEvent ->
{
if (!abandonedEvent.gracefulExit())
{
consumer.accept(null);
}
}).
withPrefix(context ->
NumberGUI.this.user.getTranslation("challenges.gui.questions.prefix")).
buildConversation(user.getPlayer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,13 @@ public Prompt acceptInput(ConversationContext conversationContext, String answer
// On cancel conversation will be closed.
withEscapeSequence("cancel").
// Use null value in consumer to detect if user has abandoned conversation.
addConversationAbandonedListener(abandonedEvent -> consumer.accept(null)).
addConversationAbandonedListener(abandonedEvent ->
{
if (!abandonedEvent.gracefulExit())
{
consumer.accept(null);
}
}).
withLocalEcho(false).
withPrefix(context -> user.getTranslation("challenges.gui.questions.prefix")).
buildConversation(user.getPlayer());
Expand Down

0 comments on commit 8d55143

Please sign in to comment.