From 336e22c7aad0d1d5c07df2db312438d2dca10152 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 4 May 2019 18:56:24 +0300 Subject: [PATCH] Implement Multiple Challenge Completion command and GUI. (#73) /[gamemode] challenges complete [number] allows to complete challenges [number] amount (or less if not enough items) Via GUI users can right click on challenge and if it is repeatable, then it will open AnvilGUI that accepts only numbers as input. --- .../commands/CompleteChallengeCommand.java | 17 ++++--- .../challenges/panel/user/ChallengesGUI.java | 48 ++++++++++++++++--- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/commands/CompleteChallengeCommand.java b/src/main/java/world/bentobox/challenges/commands/CompleteChallengeCommand.java index b9f7d5a..4837dc9 100644 --- a/src/main/java/world/bentobox/challenges/commands/CompleteChallengeCommand.java +++ b/src/main/java/world/bentobox/challenges/commands/CompleteChallengeCommand.java @@ -112,15 +112,14 @@ public class CompleteChallengeCommand extends CompositeCommand }); break; -// TODO: not implemented YET -// case 4: -// // Suggest a number of completions. -// if (lastString.isEmpty() || lastString.matches("[0-9]*")) -// { -// returnList.addAll(Util.tabLimit(Collections.singletonList(""), lastString)); -// } -// -// break; + case 4: + // Suggest a number of completions. + if (lastString.isEmpty() || lastString.matches("[0-9]*")) + { + returnList.addAll(Util.tabLimit(Collections.singletonList(""), lastString)); + } + + break; default: { returnList.addAll(Util.tabLimit(Collections.singletonList("help"), lastString)); 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 4f1f4e7..776f2df 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -6,6 +6,7 @@ import org.bukkit.World; import org.bukkit.inventory.ItemStack; import java.util.List; +import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -353,14 +354,47 @@ public class ChallengesGUI extends CommonGUI description(GuiUtils.stringSplit(this.generateChallengeDescription(challenge, this.user.getPlayer()), this.addon.getChallengesSettings().getLoreLineLength())). clickHandler((panel, user1, clickType, slot) -> { - if (TryToComplete.complete(this.addon, - this.user, - challenge, - this.world, - this.topLabel, - this.permissionPrefix)) + + // Add ability to input how many repeats player should do. + // Do not open if challenge is not repeatable. + if (clickType.isRightClick() && challenge.isRepeatable()) { - panel.getInventory().setItem(slot, this.getChallengeButton(challenge).getItem()); + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + "1", + (player, reply) -> { + try + { + if (TryToComplete.complete(this.addon, + this.user, + challenge, + this.world, + this.topLabel, + this.permissionPrefix, + Integer.parseInt(reply))) + { + panel.getInventory().setItem(slot, this.getChallengeButton(challenge).getItem()); + } + } + catch (Exception e) + { + this.user.sendMessage("challenges.errors.not-a-integer", "[value]", reply); + } + + return reply; + }); + } + else + { + if (TryToComplete.complete(this.addon, + this.user, + challenge, + this.world, + this.topLabel, + this.permissionPrefix)) + { + panel.getInventory().setItem(slot, this.getChallengeButton(challenge).getItem()); + } } return true;