Implement ability to change text via Chat instead of AnvilGUI (#97).

It was necessary as Anvil has limited char input, while chat is almost unlimited.
This commit is contained in:
BONNe 2019-04-26 21:20:36 +03:00
parent 507c68d683
commit a41859459f
3 changed files with 49 additions and 32 deletions

View File

@ -7,6 +7,7 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.stream.Collectors;
import net.wesjd.anvilgui.AnvilGUI;
import world.bentobox.bentobox.api.panels.PanelItem;
@ -116,6 +117,10 @@ public class EditChallengeGUI extends CommonGUI
panelBuilder.item(44, this.returnButton);
// Every time when this GUI is build, save challenge
// This will ensure that all main things will be always stored
this.addon.getChallengesManager().saveChallenge(this.challenge);
panelBuilder.build();
}
@ -917,13 +922,13 @@ public class EditChallengeGUI extends CommonGUI
icon = new ItemStack(Material.WRITTEN_BOOK);
clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(),
this.user.getPlayer(),
this.challenge.getRewardText(),
(player, reply) -> {
this.challenge.setRewardText(reply);
new StringListGUI(this.user, this.challenge.getRewardText(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining()));
}
this.build();
return reply;
});
return true;
@ -1114,13 +1119,13 @@ public class EditChallengeGUI extends CommonGUI
icon = new ItemStack(Material.WRITTEN_BOOK);
clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(),
this.user.getPlayer(),
this.challenge.getRepeatRewardText(),
(player, reply) -> {
this.challenge.setRepeatRewardText(reply);
new StringListGUI(this.user, this.challenge.getRepeatRewardText(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRepeatRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining()));
}
this.build();
return reply;
});
return true;

View File

@ -103,6 +103,10 @@ public class EditLevelGUI extends CommonGUI
panelBuilder.item(44, this.returnButton);
// Save challenge level every time this gui is build.
// It will ensure that changes are stored in database.
this.addon.getChallengesManager().saveLevel(this.challengeLevel);
panelBuilder.build();
}
@ -422,14 +426,15 @@ public class EditLevelGUI extends CommonGUI
"[value]", "|" + this.challengeLevel.getUnlockMessage()));
icon = new ItemStack(Material.WRITABLE_BOOK);
clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(),
this.user.getPlayer(),
this.challengeLevel.getUnlockMessage(),
(player, reply) -> {
this.challengeLevel.setUnlockMessage(reply);
new StringListGUI(this.user, this.challengeLevel.getUnlockMessage(), lineLength, (status, value) -> {
if (status)
{
this.challengeLevel.setUnlockMessage(value.stream().map(s -> s + "|").collect(Collectors.joining()));
}
this.build();
return reply;
});
return true;
};
glow = false;
@ -492,14 +497,15 @@ public class EditLevelGUI extends CommonGUI
"[value]", "|" + this.challengeLevel.getRewardText()));
icon = new ItemStack(Material.WRITTEN_BOOK);
clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(),
this.user.getPlayer(),
this.challengeLevel.getRewardText(),
(player, reply) -> {
this.challengeLevel.setRewardText(reply);
new StringListGUI(this.user, this.challengeLevel.getRewardText(), lineLength, (status, value) -> {
if (status)
{
this.challengeLevel.setRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining()));
}
this.build();
return reply;
});
return true;
};
glow = false;

View File

@ -30,6 +30,12 @@ import world.bentobox.challenges.utils.GuiUtils;
*/
public class StringListGUI
{
public StringListGUI(User user, String value, int lineLength, BiConsumer<Boolean, List<String>> consumer)
{
this(user, Collections.singleton(value), lineLength, consumer);
}
public StringListGUI(User user, Collection<String> value, int lineLength, BiConsumer<Boolean, List<String>> consumer)
{
this(user, new ArrayList<>(value), lineLength, consumer);