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.
This commit is contained in:
BONNe 2019-05-04 18:56:24 +03:00
parent cded315e16
commit 336e22c7aa
2 changed files with 49 additions and 16 deletions

View File

@ -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("<number>"), lastString));
// }
//
// break;
case 4:
// Suggest a number of completions.
if (lastString.isEmpty() || lastString.matches("[0-9]*"))
{
returnList.addAll(Util.tabLimit(Collections.singletonList("<number>"), lastString));
}
break;
default:
{
returnList.addAll(Util.tabLimit(Collections.singletonList("help"), lastString));

View File

@ -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;