mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-26 12:35:24 +01:00
Update to v1.6.0 version.
Remove AnvilGUI, as it is broken. Replaced with Spigot Conversation API. Remove lore-config from GUI (broken). Remove RIGHT_CLICK to complete multiple times (broken).
This commit is contained in:
parent
b6e2133782
commit
c516d53907
12
pom.xml
12
pom.xml
@ -36,10 +36,9 @@
|
||||
<powermock.version>1.7.4</powermock.version>
|
||||
<!-- More visible way how to change dependency versions -->
|
||||
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
|
||||
<bentobox.version>1.6.0-SNAPSHOT</bentobox.version>
|
||||
<bentobox.version>1.6.0</bentobox.version>
|
||||
<level.version>1.5.0</level.version>
|
||||
<vault.version>1.7</vault.version>
|
||||
<anvilgui.version>1.2.2-SNAPSHOT</anvilgui.version>
|
||||
<!-- Revision variable removes warning about dynamic version -->
|
||||
<revision>${build.version}-SNAPSHOT</revision>
|
||||
<!-- This allows to change between versions and snapshots. -->
|
||||
@ -115,10 +114,6 @@
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>wesjd-repo</id>
|
||||
<url>https://nexus.wesjd.net/repository/thirdparty/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -170,11 +165,6 @@
|
||||
<version>${vault.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.wesjd</groupId>
|
||||
<artifactId>anvilgui</artifactId>
|
||||
<version>${anvilgui.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -5,9 +5,11 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.conversations.*;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -21,7 +23,12 @@ import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.inventory.meta.SpawnEggMeta;
|
||||
import org.bukkit.inventory.meta.TropicalFishBucketMeta;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -917,5 +924,68 @@ public abstract class CommonGUI
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Chat Input Methods
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This method will close opened gui and writes inputText in chat. After players answers on inputText in
|
||||
* chat, message will trigger consumer and gui will reopen.
|
||||
* @param consumer Consumer that accepts player output text.
|
||||
* @param question Message that will be displayed in chat when player triggers conversion.
|
||||
* @param message Message that will be set in player text field when clicked on question.
|
||||
*/
|
||||
protected void getFriendlyName(Consumer<String> consumer, @NonNull String question, @Nullable String message)
|
||||
{
|
||||
final User user = this.user;
|
||||
|
||||
Conversation conversation =
|
||||
new ConversationFactory(BentoBox.getInstance()).withFirstPrompt(
|
||||
new StringPrompt()
|
||||
{
|
||||
/**
|
||||
* @see Prompt#getPromptText(ConversationContext)
|
||||
*/
|
||||
@Override
|
||||
public String getPromptText(ConversationContext conversationContext)
|
||||
{
|
||||
// Close input GUI.
|
||||
user.closeInventory();
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
// Create Edit Text message.
|
||||
TextComponent component = new TextComponent(user.getTranslation("challenges.gui.descriptions.admin.click-to-edit"));
|
||||
component.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message));
|
||||
// Send question and message to player.
|
||||
user.getPlayer().spigot().sendMessage(component);
|
||||
}
|
||||
|
||||
// There are no editable message. Just return question.
|
||||
return question;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Prompt#acceptInput(ConversationContext, String)
|
||||
*/
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext conversationContext, String answer)
|
||||
{
|
||||
// Add answer to consumer.
|
||||
consumer.accept(answer);
|
||||
// End conversation
|
||||
return Prompt.END_OF_CONVERSATION;
|
||||
}
|
||||
}).
|
||||
withLocalEcho(false).
|
||||
withPrefix(context -> user.getTranslation("challenges.gui.questions.prefix")).
|
||||
buildConversation(user.getPlayer());
|
||||
|
||||
conversation.begin();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,19 @@ package world.bentobox.challenges.panel.admin;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.conversations.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import net.wesjd.anvilgui.AnvilGUI;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.panel.CommonGUI;
|
||||
import world.bentobox.challenges.panel.util.ConfirmationGUI;
|
||||
@ -208,14 +214,10 @@ public class AdminGUI extends CommonGUI
|
||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.create-challenge");
|
||||
icon = new ItemStack(Material.BOOK);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
"unique_id",
|
||||
(player, reply) -> {
|
||||
String newName = Utils.getGameMode(this.world) + "_" + reply;
|
||||
|
||||
if (!this.addon.getChallengesManager().containsChallenge(newName))
|
||||
{
|
||||
this.getNewUniqueID(challenge -> {
|
||||
String newName = Utils.getGameMode(this.world) + "_" + challenge;
|
||||
|
||||
new EditChallengeGUI(this.addon,
|
||||
this.world,
|
||||
this.user,
|
||||
@ -223,14 +225,13 @@ public class AdminGUI extends CommonGUI
|
||||
this.topLabel,
|
||||
this.permissionPrefix,
|
||||
this).build();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
|
||||
}
|
||||
|
||||
return reply;
|
||||
});
|
||||
},
|
||||
input -> {
|
||||
String newName = Utils.getGameMode(this.world) + "_" + input;
|
||||
return !this.addon.getChallengesManager().containsChallenge(newName);
|
||||
},
|
||||
this.user.getTranslation("challenges.question.admin.unique-id")
|
||||
);
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -244,14 +245,10 @@ public class AdminGUI extends CommonGUI
|
||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.create-level");
|
||||
icon = new ItemStack(Material.BOOK);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
"unique_id",
|
||||
(player, reply) -> {
|
||||
String newName = Utils.getGameMode(this.world) + "_" + reply;
|
||||
|
||||
if (!this.addon.getChallengesManager().containsLevel(newName))
|
||||
{
|
||||
this.getNewUniqueID(level -> {
|
||||
String newName = Utils.getGameMode(this.world) + "_" + level;
|
||||
|
||||
new EditLevelGUI(this.addon,
|
||||
this.world,
|
||||
this.user,
|
||||
@ -259,14 +256,13 @@ public class AdminGUI extends CommonGUI
|
||||
this.topLabel,
|
||||
this.permissionPrefix,
|
||||
this).build();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.user.sendMessage("challenges.errors.unique-id", "[id]", reply);
|
||||
}
|
||||
|
||||
return reply;
|
||||
});
|
||||
},
|
||||
input -> {
|
||||
String newName = Utils.getGameMode(this.world) + "_" + input;
|
||||
return !this.addon.getChallengesManager().containsLevel(newName);
|
||||
},
|
||||
this.user.getTranslation("challenges.question.admin.unique-id")
|
||||
);
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -496,4 +492,111 @@ public class AdminGUI extends CommonGUI
|
||||
clickHandler(clickHandler).
|
||||
build();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Conversation
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This method will close opened gui and writes inputText in chat. After players answers on
|
||||
* inputText in chat, message will trigger consumer and gui will reopen.
|
||||
* @param consumer Consumer that accepts player output text.
|
||||
* @param question Message that will be displayed in chat when player triggers conversion.
|
||||
*/
|
||||
private void getNewUniqueID(Consumer<String> consumer,
|
||||
Function<String, Boolean> stringValidation,
|
||||
@NonNull String question)
|
||||
{
|
||||
final User user = this.user;
|
||||
|
||||
Conversation conversation =
|
||||
new ConversationFactory(BentoBox.getInstance()).withFirstPrompt(
|
||||
new ValidatingPrompt()
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the text to display to the user when
|
||||
* this prompt is first presented.
|
||||
*
|
||||
* @param context Context information about the
|
||||
* conversation.
|
||||
* @return The text to display.
|
||||
*/
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context)
|
||||
{
|
||||
// Close input GUI.
|
||||
user.closeInventory();
|
||||
|
||||
// There are no editable message. Just return question.
|
||||
return question;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override this method to check the validity of
|
||||
* the player's input.
|
||||
*
|
||||
* @param context Context information about the
|
||||
* conversation.
|
||||
* @param input The player's raw console input.
|
||||
* @return True or false depending on the
|
||||
* validity of the input.
|
||||
*/
|
||||
@Override
|
||||
protected boolean isInputValid(ConversationContext context, String input)
|
||||
{
|
||||
return stringValidation.apply(input);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Optionally override this method to
|
||||
* display an additional message if the
|
||||
* user enters an invalid input.
|
||||
*
|
||||
* @param context Context information
|
||||
* about the conversation.
|
||||
* @param invalidInput The invalid input
|
||||
* provided by the user.
|
||||
* @return A message explaining how to
|
||||
* correct the input.
|
||||
*/
|
||||
@Override
|
||||
protected String getFailedValidationText(ConversationContext context,
|
||||
String invalidInput)
|
||||
{
|
||||
return user.getTranslation("challenges.errors.unique-id", "[id]", invalidInput);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override this method to accept and processes
|
||||
* the validated input from the user. Using the
|
||||
* input, the next Prompt in the prompt graph
|
||||
* should be returned.
|
||||
*
|
||||
* @param context Context information about the
|
||||
* conversation.
|
||||
* @param input The validated input text from
|
||||
* the user.
|
||||
* @return The next Prompt in the prompt graph.
|
||||
*/
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(ConversationContext context, String input)
|
||||
{
|
||||
// Add answer to consumer.
|
||||
consumer.accept(input);
|
||||
// End conversation
|
||||
return Prompt.END_OF_CONVERSATION;
|
||||
}
|
||||
}).
|
||||
withLocalEcho(false).
|
||||
withPrefix(context -> user.getTranslation("challenges.gui.questions.prefix")).
|
||||
buildConversation(user.getPlayer());
|
||||
|
||||
conversation.begin();
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ 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;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
@ -16,10 +15,7 @@ import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.database.object.Challenge;
|
||||
import world.bentobox.challenges.panel.CommonGUI;
|
||||
import world.bentobox.challenges.panel.util.ItemSwitchGUI;
|
||||
import world.bentobox.challenges.panel.util.NumberGUI;
|
||||
import world.bentobox.challenges.panel.util.SelectEnvironmentGUI;
|
||||
import world.bentobox.challenges.panel.util.StringListGUI;
|
||||
import world.bentobox.challenges.panel.util.*;
|
||||
import world.bentobox.challenges.utils.GuiUtils;
|
||||
import world.bentobox.challenges.utils.Utils;
|
||||
|
||||
@ -406,23 +402,15 @@ public class EditChallengeGUI extends CommonGUI
|
||||
"challenges.gui.descriptions.admin.icon-challenge"));
|
||||
icon = this.challenge.getIcon();
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.challenge.getIcon().getType().name(),
|
||||
(player, reply) -> {
|
||||
Material material = Material.getMaterial(reply);
|
||||
|
||||
if (material != null)
|
||||
new SelectBlocksGUI(this.user, true, (status, materials) -> {
|
||||
if (status)
|
||||
{
|
||||
this.challenge.setIcon(new ItemStack(material));
|
||||
materials.forEach(material ->
|
||||
this.challenge.setIcon(new ItemStack(material)));
|
||||
}
|
||||
|
||||
this.build();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply);
|
||||
}
|
||||
|
||||
return reply;
|
||||
});
|
||||
|
||||
return true;
|
||||
@ -543,14 +531,14 @@ public class EditChallengeGUI extends CommonGUI
|
||||
|
||||
icon = new ItemStack(Material.DROPPER);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.challenge.getFriendlyName(),
|
||||
(player, reply) -> {
|
||||
|
||||
this.getFriendlyName(reply -> {
|
||||
this.challenge.setFriendlyName(reply);
|
||||
this.build();
|
||||
return reply;
|
||||
});
|
||||
},
|
||||
this.user.getTranslation("challenges.gui.questions.admin.challenge-name"),
|
||||
this.challenge.getFriendlyName()
|
||||
);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
@ -13,7 +13,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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;
|
||||
@ -23,10 +22,7 @@ import world.bentobox.challenges.ChallengesManager;
|
||||
import world.bentobox.challenges.database.object.Challenge;
|
||||
import world.bentobox.challenges.database.object.ChallengeLevel;
|
||||
import world.bentobox.challenges.panel.CommonGUI;
|
||||
import world.bentobox.challenges.panel.util.ItemSwitchGUI;
|
||||
import world.bentobox.challenges.panel.util.NumberGUI;
|
||||
import world.bentobox.challenges.panel.util.SelectChallengeGUI;
|
||||
import world.bentobox.challenges.panel.util.StringListGUI;
|
||||
import world.bentobox.challenges.panel.util.*;
|
||||
import world.bentobox.challenges.utils.GuiUtils;
|
||||
import world.bentobox.challenges.utils.Utils;
|
||||
|
||||
@ -337,14 +333,14 @@ public class EditLevelGUI extends CommonGUI
|
||||
"[value]", this.challengeLevel.getFriendlyName()));
|
||||
icon = new ItemStack(Material.DROPPER);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.challengeLevel.getFriendlyName(),
|
||||
(player, reply) -> {
|
||||
|
||||
this.getFriendlyName(reply -> {
|
||||
this.challengeLevel.setFriendlyName(reply);
|
||||
this.build();
|
||||
return reply;
|
||||
});
|
||||
},
|
||||
this.user.getTranslation("challenges.gui.questions.admin.level-name"),
|
||||
this.challengeLevel.getFriendlyName()
|
||||
);
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -358,23 +354,15 @@ public class EditLevelGUI extends CommonGUI
|
||||
"challenges.gui.descriptions.admin.icon-level"));
|
||||
icon = this.challengeLevel.getIcon();
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.challengeLevel.getIcon().getType().name(),
|
||||
(player, reply) -> {
|
||||
Material material = Material.getMaterial(reply);
|
||||
|
||||
if (material != null)
|
||||
new SelectBlocksGUI(this.user, true, (status, materials) -> {
|
||||
if (status)
|
||||
{
|
||||
this.challengeLevel.setIcon(new ItemStack(material));
|
||||
materials.forEach(material ->
|
||||
this.challengeLevel.setIcon(new ItemStack(material)));
|
||||
}
|
||||
|
||||
this.build();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply);
|
||||
}
|
||||
|
||||
return reply;
|
||||
});
|
||||
|
||||
return true;
|
||||
@ -400,30 +388,14 @@ public class EditLevelGUI extends CommonGUI
|
||||
}
|
||||
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
isNull ? "NULL" : icon.getType().name(),
|
||||
(player, reply) -> {
|
||||
if (reply.equals("NULL"))
|
||||
new SelectBlocksGUI(this.user, true, (status, materials) -> {
|
||||
if (status)
|
||||
{
|
||||
this.challengeLevel.setLockedIcon(null);
|
||||
materials.forEach(material ->
|
||||
this.challengeLevel.setLockedIcon(new ItemStack(material)));
|
||||
}
|
||||
|
||||
this.build();
|
||||
return reply;
|
||||
}
|
||||
|
||||
Material material = Material.getMaterial(reply);
|
||||
|
||||
if (material != null)
|
||||
{
|
||||
this.challengeLevel.setLockedIcon(new ItemStack(material));
|
||||
this.build();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply);
|
||||
}
|
||||
|
||||
return reply;
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -8,7 +8,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
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;
|
||||
@ -17,6 +16,7 @@ import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.Settings;
|
||||
import world.bentobox.challenges.panel.CommonGUI;
|
||||
import world.bentobox.challenges.panel.util.NumberGUI;
|
||||
import world.bentobox.challenges.panel.util.SelectBlocksGUI;
|
||||
import world.bentobox.challenges.utils.GuiUtils;
|
||||
|
||||
|
||||
@ -240,14 +240,16 @@ public class EditSettingsGUI extends CommonGUI
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.level-lore");
|
||||
icon = new ItemStack(Material.MAP);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.settings.getLevelLoreMessage(),
|
||||
(player, reply) -> {
|
||||
this.settings.setLevelLoreMessage(reply);
|
||||
panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
return reply;
|
||||
});
|
||||
|
||||
// TODO: AnvilGUI is out. Need to implement better GUI for editing this.
|
||||
// new AnvilGUI(this.addon.getPlugin(),
|
||||
// this.user.getPlayer(),
|
||||
// this.settings.getLevelLoreMessage(),
|
||||
// (player, reply) -> {
|
||||
// this.settings.setLevelLoreMessage(reply);
|
||||
// panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
// return reply;
|
||||
// });
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -263,14 +265,16 @@ public class EditSettingsGUI extends CommonGUI
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.challenge-lore");
|
||||
icon = new ItemStack(Material.PAPER);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.settings.getChallengeLoreMessage(),
|
||||
(player, reply) -> {
|
||||
this.settings.setChallengeLoreMessage(reply);
|
||||
panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
return reply;
|
||||
});
|
||||
// TODO: AnvilGUI is out. Need to implement better GUI for editing this.
|
||||
|
||||
// new AnvilGUI(this.addon.getPlugin(),
|
||||
// this.user.getPlayer(),
|
||||
// this.settings.getChallengeLoreMessage(),
|
||||
// (player, reply) -> {
|
||||
// this.settings.setChallengeLoreMessage(reply);
|
||||
// panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
// return reply;
|
||||
// });
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -441,23 +445,15 @@ public class EditSettingsGUI extends CommonGUI
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.default-locked-icon");
|
||||
icon = this.settings.getLockedLevelIcon();
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.settings.getLockedLevelIcon().getType().name(),
|
||||
(player, reply) -> {
|
||||
Material material = Material.getMaterial(reply);
|
||||
|
||||
if (material != null)
|
||||
new SelectBlocksGUI(this.user, true, (status, materials) -> {
|
||||
if (status)
|
||||
{
|
||||
this.settings.setLockedLevelIcon(new ItemStack(material));
|
||||
materials.forEach(material ->
|
||||
this.settings.setLockedLevelIcon(new ItemStack(material)));
|
||||
}
|
||||
|
||||
this.build();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply);
|
||||
}
|
||||
|
||||
return reply;
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -2,12 +2,10 @@ package world.bentobox.challenges.panel.user;
|
||||
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
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;
|
||||
@ -360,34 +358,35 @@ public class ChallengesGUI extends CommonGUI
|
||||
|
||||
// Add ability to input how many repeats player should do.
|
||||
// Do not open if challenge is not repeatable.
|
||||
if (clickType.isRightClick() && challenge.isRepeatable())
|
||||
{
|
||||
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
|
||||
// TODO: AnvilGUI is removed. Need to use different input mode.
|
||||
// if (clickType.isRightClick() && challenge.isRepeatable())
|
||||
// {
|
||||
// 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,
|
||||
|
@ -2,11 +2,12 @@ package world.bentobox.challenges.panel.util;
|
||||
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.conversations.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.Collections;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.wesjd.anvilgui.AnvilGUI;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
@ -140,34 +141,12 @@ public class NumberGUI
|
||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.input");
|
||||
icon = new ItemStack(Material.ANVIL);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
new AnvilGUI(BentoBox.getInstance(),
|
||||
this.user.getPlayer(),
|
||||
Integer.toString(this.value),
|
||||
(player, reply) -> {
|
||||
try
|
||||
{
|
||||
this.value = Integer.parseInt(reply);
|
||||
|
||||
if (this.value > this.maxValue || this.value < this.minValue)
|
||||
{
|
||||
this.user.sendMessage("challenges.errors.not-valid-integer",
|
||||
"[value]", reply,
|
||||
"[min]", Integer.toString(this.minValue),
|
||||
"[max]", Integer.toString(this.maxValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getNumberInput(number -> {
|
||||
this.value = number.intValue();
|
||||
this.build();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
reply = Integer.toString(this.value);
|
||||
this.user.sendMessage("challenges.errors.not-a-integer", "[value]", reply);
|
||||
}
|
||||
|
||||
return reply;
|
||||
});
|
||||
},
|
||||
this.user.getTranslation("challenges.gui.questions.admin.number"));
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -368,6 +347,120 @@ public class NumberGUI
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Conversation
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* This method will close opened gui and writes inputText in chat. After players answers on
|
||||
* inputText in chat, message will trigger consumer and gui will reopen.
|
||||
* @param consumer Consumer that accepts player output text.
|
||||
* @param question Message that will be displayed in chat when player triggers conversion.
|
||||
*/
|
||||
private void getNumberInput(Consumer<Number> consumer, @NonNull String question)
|
||||
{
|
||||
final User user = this.user;
|
||||
|
||||
Conversation conversation =
|
||||
new ConversationFactory(BentoBox.getInstance()).withFirstPrompt(
|
||||
new NumericPrompt()
|
||||
{
|
||||
/**
|
||||
* Override this method to perform some action
|
||||
* with the user's integer response.
|
||||
*
|
||||
* @param context Context information about the
|
||||
* conversation.
|
||||
* @param input The user's response as a {@link
|
||||
* Number}.
|
||||
* @return The next {@link Prompt} in the prompt
|
||||
* graph.
|
||||
*/
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(ConversationContext context, Number input)
|
||||
{
|
||||
// Add answer to consumer.
|
||||
consumer.accept(input);
|
||||
// Reopen GUI
|
||||
NumberGUI.this.build();
|
||||
// End conversation
|
||||
return Prompt.END_OF_CONVERSATION;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override this method to do further validation on the numeric player
|
||||
* input after the input has been determined to actually be a number.
|
||||
*
|
||||
* @param context Context information about the conversation.
|
||||
* @param input The number the player provided.
|
||||
* @return The validity of the player's input.
|
||||
*/
|
||||
protected boolean isNumberValid(ConversationContext context, Number input)
|
||||
{
|
||||
return input.intValue() >= NumberGUI.this.minValue &&
|
||||
input.intValue() <= NumberGUI.this.maxValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Optionally override this method to display an additional message if the
|
||||
* user enters an invalid number.
|
||||
*
|
||||
* @param context Context information about the conversation.
|
||||
* @param invalidInput The invalid input provided by the user.
|
||||
* @return A message explaining how to correct the input.
|
||||
*/
|
||||
@Override
|
||||
protected String getInputNotNumericText(ConversationContext context,
|
||||
String invalidInput)
|
||||
{
|
||||
return NumberGUI.this.user.getTranslation("challenges.errors.not-a-integer", "[value]", invalidInput);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Optionally override this method to display an additional message if the
|
||||
* user enters an invalid numeric input.
|
||||
*
|
||||
* @param context Context information about the conversation.
|
||||
* @param invalidInput The invalid input provided by the user.
|
||||
* @return A message explaining how to correct the input.
|
||||
*/
|
||||
@Override
|
||||
protected String getFailedValidationText(ConversationContext context,
|
||||
Number invalidInput)
|
||||
{
|
||||
return NumberGUI.this.user.getTranslation("challenges.errors.not-valid-integer",
|
||||
"[value]", invalidInput.toString(),
|
||||
"[min]", Integer.toString(NumberGUI.this.minValue),
|
||||
"[max]", Integer.toString(NumberGUI.this.maxValue));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Prompt#getPromptText(ConversationContext)
|
||||
*/
|
||||
@Override
|
||||
public String getPromptText(ConversationContext conversationContext)
|
||||
{
|
||||
// Close input GUI.
|
||||
user.closeInventory();
|
||||
|
||||
// There are no editable message. Just return question.
|
||||
return question;
|
||||
}
|
||||
}).
|
||||
withLocalEcho(false).
|
||||
withPrefix(context ->
|
||||
NumberGUI.this.user.getTranslation("challenges.gui.questions.prefix")).
|
||||
buildConversation(user.getPlayer());
|
||||
|
||||
conversation.begin();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Enums
|
||||
// ---------------------------------------------------------------------
|
||||
|
@ -23,14 +23,20 @@ public class SelectBlocksGUI
|
||||
{
|
||||
public SelectBlocksGUI(User user, BiConsumer<Boolean, Set<Material>> consumer)
|
||||
{
|
||||
this(user, Collections.emptySet(), consumer);
|
||||
this(user, false, new HashSet<>(), consumer);
|
||||
}
|
||||
|
||||
public SelectBlocksGUI(User user, boolean singleSelect, BiConsumer<Boolean, Set<Material>> consumer)
|
||||
{
|
||||
this(user, singleSelect, new HashSet<>(), consumer);
|
||||
}
|
||||
|
||||
|
||||
public SelectBlocksGUI(User user, Set<Material> excludedMaterial, BiConsumer<Boolean, Set<Material>> consumer)
|
||||
public SelectBlocksGUI(User user, boolean singleSelect, Set<Material> excludedMaterial, BiConsumer<Boolean, Set<Material>> consumer)
|
||||
{
|
||||
this.consumer = consumer;
|
||||
this.user = user;
|
||||
this.singleSelect = singleSelect;
|
||||
|
||||
// Current GUI cannot display air blocks. It crashes with null-pointer
|
||||
excludedMaterial.add(Material.AIR);
|
||||
@ -185,7 +191,7 @@ public class SelectBlocksGUI
|
||||
this.user.getTranslation("challenges.gui.descriptions.admin.selected") : "").
|
||||
icon(itemStack).
|
||||
clickHandler((panel, user1, clickType, slot) -> {
|
||||
if (clickType.isRightClick())
|
||||
if (!this.singleSelect && clickType.isRightClick())
|
||||
{
|
||||
if (!this.selectedMaterials.add(material))
|
||||
{
|
||||
@ -230,4 +236,9 @@ public class SelectBlocksGUI
|
||||
* User who runs GUI.
|
||||
*/
|
||||
private User user;
|
||||
|
||||
/**
|
||||
* This indicate that return set must contain only single item.
|
||||
*/
|
||||
private boolean singleSelect;
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import java.util.function.Consumer;
|
||||
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.wesjd.anvilgui.AnvilGUI;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
@ -78,8 +77,6 @@ public class StringListGUI
|
||||
panelBuilder.item(5, this.getButton(Button.REMOVE));
|
||||
panelBuilder.item(6, this.getButton(Button.CLEAR));
|
||||
|
||||
panelBuilder.item(8, this.getButton(Button.MODE));
|
||||
|
||||
panelBuilder.item(44, this.getButton(Button.CANCEL));
|
||||
|
||||
int slot = 10;
|
||||
@ -154,23 +151,8 @@ public class StringListGUI
|
||||
icon = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
|
||||
if (this.useAnvil)
|
||||
{
|
||||
new AnvilGUI(BentoBox.getInstance(),
|
||||
this.user.getPlayer(),
|
||||
" ",
|
||||
(player, reply) -> {
|
||||
this.value.add(reply);
|
||||
this.build();
|
||||
return reply;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.startConversion(value ->
|
||||
this.value.add(value),
|
||||
this.getStringInput(value -> this.value.add(value),
|
||||
this.user.getTranslation("challenges.gui.descriptions.admin.add-text-line"));
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -201,18 +183,6 @@ public class StringListGUI
|
||||
};
|
||||
break;
|
||||
}
|
||||
case MODE:
|
||||
{
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.input-mode");
|
||||
description = Collections.singletonList(this.user.getTranslation("challenges.gui.descriptions.admin.input-mode"));
|
||||
icon = this.useAnvil ? new ItemStack(Material.ANVIL) : new ItemStack(Material.MAP);
|
||||
clickHandler = (panel, user, clickType, slot) -> {
|
||||
this.useAnvil = !this.useAnvil;
|
||||
panel.getInventory().setItem(slot, this.getButton(button).getItem());
|
||||
return true;
|
||||
};
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@ -239,24 +209,10 @@ public class StringListGUI
|
||||
icon(Material.PAPER).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
|
||||
if (this.useAnvil)
|
||||
{
|
||||
new AnvilGUI(BentoBox.getInstance(),
|
||||
this.user.getPlayer(),
|
||||
element,
|
||||
(player, reply) -> {
|
||||
this.value.set(stringIndex, reply);
|
||||
this.build();
|
||||
return reply;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.startConversion(
|
||||
this.getStringInput(
|
||||
value -> this.value.set(stringIndex, value),
|
||||
this.user.getTranslation("challenges.gui.descriptions.admin.edit-text-line"),
|
||||
element);
|
||||
}
|
||||
|
||||
return true;
|
||||
}).build();
|
||||
@ -269,9 +225,9 @@ public class StringListGUI
|
||||
* @param consumer Consumer that accepts player output text.
|
||||
* @param question Message that will be displayed in chat when player triggers conversion.
|
||||
*/
|
||||
private void startConversion(Consumer<String> consumer, @NonNull String question)
|
||||
private void getStringInput(Consumer<String> consumer, @NonNull String question)
|
||||
{
|
||||
this.startConversion(consumer, question, null);
|
||||
this.getStringInput(consumer, question, null);
|
||||
}
|
||||
|
||||
|
||||
@ -282,7 +238,7 @@ public class StringListGUI
|
||||
* @param question Message that will be displayed in chat when player triggers conversion.
|
||||
* @param message Message that will be set in player text field when clicked on question.
|
||||
*/
|
||||
private void startConversion(Consumer<String> consumer, @NonNull String question, @Nullable String message)
|
||||
private void getStringInput(Consumer<String> consumer, @NonNull String question, @Nullable String message)
|
||||
{
|
||||
final User user = this.user;
|
||||
|
||||
@ -328,6 +284,7 @@ public class StringListGUI
|
||||
}
|
||||
}).
|
||||
withLocalEcho(false).
|
||||
withPrefix(context -> user.getTranslation("challenges.gui.questions.prefix")).
|
||||
buildConversation(user.getPlayer());
|
||||
|
||||
conversation.begin();
|
||||
@ -349,8 +306,7 @@ public class StringListGUI
|
||||
REMOVE,
|
||||
CANCEL,
|
||||
CLEAR,
|
||||
SAVE,
|
||||
MODE
|
||||
SAVE
|
||||
}
|
||||
|
||||
|
||||
@ -369,11 +325,6 @@ public class StringListGUI
|
||||
*/
|
||||
private User user;
|
||||
|
||||
/**
|
||||
* Boolean that indicate if editing should happen in anvil.
|
||||
*/
|
||||
private boolean useAnvil;
|
||||
|
||||
/**
|
||||
* Current value.
|
||||
*/
|
||||
|
@ -321,6 +321,16 @@ challenges:
|
||||
skull-owner: ' [owner]'
|
||||
egg-meta: ' [mob]'
|
||||
fish-meta: ' [body-color] with [pattern-color] [pattern]'
|
||||
|
||||
questions:
|
||||
prefix: "&2[SERVER]: "
|
||||
|
||||
admin:
|
||||
number: "Write a number in chat and press enter to accept it and press enter."
|
||||
unique-id: "Write object unique name and press enter."
|
||||
challenge-name: "Write in chat display name for current challenge."
|
||||
level-name: "Write in chat display name for current level."
|
||||
|
||||
titles:
|
||||
# Title and subtitle my contain variable in [] that will be replaced with proper message from challenge object.
|
||||
# [friendlyName] will be replaced with challenge friendly name.
|
||||
|
@ -283,6 +283,15 @@ challenges:
|
||||
money-reward: '&6Recompensa de dinero: $[value]'
|
||||
reward-items: '&6Artículos de recompensa:'
|
||||
reward-commands: '&6Comandos de recompensa:'
|
||||
|
||||
questions:
|
||||
prefix: "&2[SERVER]: "
|
||||
|
||||
admin:
|
||||
number: "Write a number in chat and press enter to accept it and press enter."
|
||||
unique-id: "Write object unique name and press enter."
|
||||
challenge-name: "Write in chat display name for current challenge."
|
||||
level-name: "Write in chat display name for current level."
|
||||
messages:
|
||||
admin:
|
||||
hit-things: 'Golpea cosas para agregarlas a la lista de cosas requeridas. Haga click derecho cuando haya terminado.'
|
||||
|
@ -295,6 +295,15 @@ challenges:
|
||||
money-reward: '&6Récompense: [value]$'
|
||||
reward-items: '&6Récompenses:'
|
||||
reward-commands: '&6Récompenses (commandes):'
|
||||
|
||||
questions:
|
||||
prefix: "&2[SERVER]: "
|
||||
|
||||
admin:
|
||||
number: "Write a number in chat and press enter to accept it and press enter."
|
||||
unique-id: "Write object unique name and press enter."
|
||||
challenge-name: "Write in chat display name for current challenge."
|
||||
level-name: "Write in chat display name for current level."
|
||||
titles:
|
||||
# Title and subtitle my contain variable in [] that will be replaced with proper message from challenge object.
|
||||
# [friendlyName] will be replaced with challenge friendly name.
|
||||
|
@ -318,6 +318,15 @@ challenges:
|
||||
skull-owner: ' [owner]'
|
||||
egg-meta: ' [mob]'
|
||||
fish-meta: ' [body-color] ar [pattern-color] [pattern]'
|
||||
|
||||
questions:
|
||||
prefix: "&2[SERVERIS]: "
|
||||
|
||||
admin:
|
||||
number: "Ieraksti nummuru sarakstē."
|
||||
unique-id: "Ieraksti objekta unikālo nosaukumu sarakstē."
|
||||
challenge-name: "Ieraksti uzdevuma nosaukumu sarakstē."
|
||||
level-name: "Ieraksti uzdevuma līmeņa nosaukumu sarakstē."
|
||||
titles:
|
||||
# Title and subtitle my contain variable in [] that will be replaced with proper message from challenge object.
|
||||
# [friendlyName] will be replaced with challenge friendly name.
|
||||
|
@ -315,6 +315,16 @@ challenges:
|
||||
skull-owner: ' [owner]'
|
||||
egg-meta: ' [mob]'
|
||||
fish-meta: ' [body-color] with [pattern-color] [pattern]'
|
||||
|
||||
questions:
|
||||
prefix: "&2[SERVER]: "
|
||||
|
||||
admin:
|
||||
number: "Write a number in chat and press enter to accept it and press enter."
|
||||
unique-id: "Write object unique name and press enter."
|
||||
challenge-name: "Write in chat display name for current challenge."
|
||||
level-name: "Write in chat display name for current level."
|
||||
|
||||
titles:
|
||||
# Title and subtitle my contain variable in [] that will be replaced with proper message from challenge object.
|
||||
# [friendlyName] will be replaced with challenge friendly name.
|
||||
|
@ -315,6 +315,15 @@ challenges:
|
||||
skull-owner: ' [owner]'
|
||||
egg-meta: ' [mob]'
|
||||
fish-meta: ' [body-color] with [pattern-color] [pattern]'
|
||||
|
||||
questions:
|
||||
prefix: "&2[SERVER]: "
|
||||
|
||||
admin:
|
||||
number: "Write a number in chat and press enter to accept it and press enter."
|
||||
unique-id: "Write object unique name and press enter."
|
||||
challenge-name: "Write in chat display name for current challenge."
|
||||
level-name: "Write in chat display name for current level."
|
||||
titles:
|
||||
# Title and subtitle my contain variable in [] that will be replaced with proper message from challenge object.
|
||||
# [friendlyName] will be replaced with challenge friendly name.
|
||||
|
Loading…
Reference in New Issue
Block a user