From 99187525894e076b90009e0302980fa7484e7135 Mon Sep 17 00:00:00 2001 From: BONNe Date: Mon, 28 Jan 2019 21:01:26 +0200 Subject: [PATCH] Fix issue when completing challenge was not displayed in ChallengesGUI. (#60) --- .../challenges/panel/ChallengesPanels2.java | 2 +- .../challenges/panel/TryToComplete.java | 22 ++++++++++++++++++- .../challenges/panel/user/ChallengesGUI.java | 8 +++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index 2006f46..3c51fd8 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -152,7 +152,7 @@ public class ChallengesPanels2 { } else { // Player click itemBuilder.clickHandler((panel, player, c, s) -> { - new TryToComplete(addon, player, challenge, world, label, permPrefix); + new TryToComplete(addon, player, challenge, world, label, permPrefix).build(); return true; }); } diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index b25af2e..ceffdba 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -161,8 +161,28 @@ public class TryToComplete this.manager = addon.getChallengesManager(); this.challenge = challenge; this.topLabel = topLabel; + } - this.build(); + + /** + * This static method allows complete challenge and get result about completion. + * @param addon - Challenges Addon. + * @param user - User who performs challenge. + * @param challenge - Challenge that should be completed. + * @param world - World where completion may occur. + * @param topLabel - Label of the top command. + * @param permissionPrefix - Permission prefix for GameMode addon. + * @return true, if challenge is completed, otherwise false. + */ + public static boolean complete(ChallengesAddon addon, + User user, + Challenge challenge, + World world, + String topLabel, + String permissionPrefix) + { + return new TryToComplete(addon, user, challenge, world, topLabel, permissionPrefix). + build().meetsRequirements; } diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index ca88b0f..2cd9aeb 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -325,12 +325,16 @@ public class ChallengesGUI extends CommonGUI name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()). description(GuiUtils.stringSplit(this.createChallengeDescription(challenge))). clickHandler((panel, user1, clickType, slot) -> { - new TryToComplete(this.addon, + if (TryToComplete.complete(this.addon, this.user, challenge, this.world, this.topLabel, - this.permissionPrefix); + this.permissionPrefix)) + { + this.build(); + } + return true; }). glow(this.challengesManager.isChallengeComplete(this.user, challenge)).