2019-01-16 18:25:01 +01:00
|
|
|
package world.bentobox.challenges.panel.admin;
|
|
|
|
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2019-04-26 20:20:36 +02:00
|
|
|
import java.util.stream.Collectors;
|
2019-01-16 18:25:01 +01:00
|
|
|
|
2019-10-10 07:35:25 +02:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2019-01-16 18:25:01 +01:00
|
|
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
|
|
|
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
2019-03-28 23:42:51 +01:00
|
|
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
2019-01-16 18:25:01 +01:00
|
|
|
import world.bentobox.bentobox.api.user.User;
|
2020-07-12 13:43:15 +02:00
|
|
|
import world.bentobox.bentobox.util.Util;
|
2019-01-16 18:25:01 +01:00
|
|
|
import world.bentobox.challenges.ChallengesAddon;
|
2019-01-23 15:09:38 +01:00
|
|
|
import world.bentobox.challenges.database.object.Challenge;
|
2019-09-08 19:03:46 +02:00
|
|
|
import world.bentobox.challenges.database.object.requirements.InventoryRequirements;
|
|
|
|
import world.bentobox.challenges.database.object.requirements.IslandRequirements;
|
|
|
|
import world.bentobox.challenges.database.object.requirements.OtherRequirements;
|
2019-01-16 18:25:01 +01:00
|
|
|
import world.bentobox.challenges.panel.CommonGUI;
|
2019-09-08 19:03:46 +02:00
|
|
|
import world.bentobox.challenges.panel.util.ItemSwitchGUI;
|
|
|
|
import world.bentobox.challenges.panel.util.NumberGUI;
|
|
|
|
import world.bentobox.challenges.panel.util.SelectBlocksGUI;
|
|
|
|
import world.bentobox.challenges.panel.util.SelectEnvironmentGUI;
|
|
|
|
import world.bentobox.challenges.panel.util.StringListGUI;
|
2019-01-21 14:23:16 +01:00
|
|
|
import world.bentobox.challenges.utils.GuiUtils;
|
2019-06-16 19:22:42 +02:00
|
|
|
import world.bentobox.challenges.utils.Utils;
|
2019-01-16 18:25:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class contains all necessary methods that creates GUI and allow to edit challenges
|
|
|
|
* properties.
|
|
|
|
*/
|
2019-01-17 10:36:39 +01:00
|
|
|
public class EditChallengeGUI extends CommonGUI
|
2019-01-16 18:25:01 +01:00
|
|
|
{
|
2019-08-05 12:00:03 +02:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Constructors
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param addon Addon where panel operates.
|
|
|
|
* @param world World from which panel was created.
|
|
|
|
* @param user User who created panel.
|
|
|
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
|
|
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
|
|
|
* @param challenge - challenge that needs editing
|
|
|
|
*/
|
|
|
|
public EditChallengeGUI(ChallengesAddon addon,
|
|
|
|
World world,
|
|
|
|
User user,
|
|
|
|
Challenge challenge,
|
|
|
|
String topLabel,
|
|
|
|
String permissionPrefix)
|
|
|
|
{
|
|
|
|
this(addon, world, user, challenge, topLabel, permissionPrefix, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param addon Addon where panel operates.
|
|
|
|
* @param world World from which panel was created.
|
|
|
|
* @param user User who created panel.
|
|
|
|
* @param topLabel Command top label which creates panel (f.e. island or ai)
|
|
|
|
* @param permissionPrefix Command permission prefix (f.e. bskyblock.)
|
|
|
|
* @param challenge challenge that needs editing.
|
|
|
|
*/
|
|
|
|
public EditChallengeGUI(ChallengesAddon addon,
|
|
|
|
World world,
|
|
|
|
User user,
|
|
|
|
Challenge challenge,
|
|
|
|
String topLabel,
|
|
|
|
String permissionPrefix,
|
|
|
|
CommonGUI parentGUI)
|
|
|
|
{
|
|
|
|
super(addon, world, user, topLabel, permissionPrefix, parentGUI);
|
|
|
|
this.challenge = challenge;
|
|
|
|
|
|
|
|
// Default panel should be Properties.
|
|
|
|
this.currentMenuType = MenuType.PROPERTIES;
|
2019-09-08 19:03:46 +02:00
|
|
|
|
|
|
|
// Set line length.
|
|
|
|
this.lineLength = this.addon.getChallengesSettings().getLoreLineLength();
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Panel Creation related methods
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void build()
|
|
|
|
{
|
|
|
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
|
|
|
this.user.getTranslation("challenges.gui.title.admin.edit-challenge-title"));
|
|
|
|
|
|
|
|
GuiUtils.fillBorder(panelBuilder);
|
|
|
|
|
|
|
|
panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES));
|
|
|
|
panelBuilder.item(4, this.createMenuButton(MenuType.REQUIREMENTS));
|
|
|
|
panelBuilder.item(6, this.createMenuButton(MenuType.REWARDS));
|
|
|
|
|
|
|
|
if (this.currentMenuType.equals(MenuType.PROPERTIES))
|
|
|
|
{
|
|
|
|
this.buildMainPropertiesPanel(panelBuilder);
|
|
|
|
}
|
|
|
|
else if (this.currentMenuType.equals(MenuType.REQUIREMENTS))
|
|
|
|
{
|
|
|
|
switch (this.challenge.getChallengeType())
|
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
case INVENTORY:
|
|
|
|
this.buildInventoryRequirementsPanel(panelBuilder);
|
|
|
|
break;
|
|
|
|
case ISLAND:
|
|
|
|
this.buildIslandRequirementsPanel(panelBuilder);
|
|
|
|
break;
|
|
|
|
case OTHER:
|
|
|
|
this.buildOtherRequirementsPanel(panelBuilder);
|
|
|
|
break;
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this.currentMenuType.equals(MenuType.REWARDS))
|
|
|
|
{
|
|
|
|
this.buildRewardsPanel(panelBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class populate ChallengesEditGUI with main challenge settings.
|
|
|
|
* @param panelBuilder PanelBuilder where icons must be added.
|
|
|
|
*/
|
|
|
|
private void buildMainPropertiesPanel(PanelBuilder panelBuilder)
|
|
|
|
{
|
|
|
|
panelBuilder.item(10, this.createButton(Button.NAME));
|
|
|
|
panelBuilder.item(16, this.createButton(Button.DEPLOYED));
|
|
|
|
|
|
|
|
panelBuilder.item(19, this.createButton(Button.ICON));
|
|
|
|
panelBuilder.item(22, this.createButton(Button.DESCRIPTION));
|
|
|
|
panelBuilder.item(25, this.createButton(Button.ORDER));
|
|
|
|
|
|
|
|
panelBuilder.item(28, this.createButton(Button.ENVIRONMENT));
|
|
|
|
panelBuilder.item(31, this.createButton(Button.REMOVE_ON_COMPLETE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class populates ChallengesEditGUI with island challenges requirement elements.
|
|
|
|
* @param panelBuilder PanelBuilder where icons must be added.
|
|
|
|
*/
|
|
|
|
private void buildIslandRequirementsPanel(PanelBuilder panelBuilder)
|
|
|
|
{
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(19, this.createRequirementButton(RequirementButton.REQUIRED_ENTITIES));
|
|
|
|
panelBuilder.item(28, this.createRequirementButton(RequirementButton.REMOVE_ENTITIES));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(21, this.createRequirementButton(RequirementButton.REQUIRED_BLOCKS));
|
|
|
|
panelBuilder.item(30, this.createRequirementButton(RequirementButton.REMOVE_BLOCKS));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(23, this.createRequirementButton(RequirementButton.SEARCH_RADIUS));
|
|
|
|
panelBuilder.item(25, this.createRequirementButton(RequirementButton.REQUIRED_PERMISSIONS));
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class populates ChallengesEditGUI with inventory challenges requirement elements.
|
|
|
|
* @param panelBuilder PanelBuilder where icons must be added.
|
|
|
|
*/
|
|
|
|
private void buildInventoryRequirementsPanel(PanelBuilder panelBuilder)
|
|
|
|
{
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(10, this.createRequirementButton(RequirementButton.REQUIRED_ITEMS));
|
|
|
|
panelBuilder.item(19, this.createRequirementButton(RequirementButton.REMOVE_ITEMS));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(25, this.createRequirementButton(RequirementButton.REQUIRED_PERMISSIONS));
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class populates ChallengesEditGUI with other challenges requirement elements.
|
|
|
|
* @param panelBuilder PanelBuilder where icons must be added.
|
|
|
|
*/
|
|
|
|
private void buildOtherRequirementsPanel(PanelBuilder panelBuilder)
|
|
|
|
{
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(10, this.createRequirementButton(RequirementButton.REQUIRED_EXPERIENCE));
|
|
|
|
panelBuilder.item(19, this.createRequirementButton(RequirementButton.REMOVE_EXPERIENCE));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(12, this.createRequirementButton(RequirementButton.REQUIRED_MONEY));
|
|
|
|
panelBuilder.item(21, this.createRequirementButton(RequirementButton.REMOVE_MONEY));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(23, this.createRequirementButton(RequirementButton.REQUIRED_LEVEL));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(25, this.createRequirementButton(RequirementButton.REQUIRED_PERMISSIONS));
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class populates ChallengesEditGUI with challenges reward elements.
|
|
|
|
* @param panelBuilder PanelBuilder where icons must be added.
|
|
|
|
*/
|
|
|
|
private void buildRewardsPanel(PanelBuilder panelBuilder)
|
|
|
|
{
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(10, this.createRewardButton(RewardButton.REWARD_TEXT));
|
|
|
|
panelBuilder.item(19, this.createRewardButton(RewardButton.REWARD_COMMANDS));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(11, this.createRewardButton(RewardButton.REWARD_ITEM));
|
|
|
|
panelBuilder.item(20, this.createRewardButton(RewardButton.REWARD_EXPERIENCE));
|
|
|
|
panelBuilder.item(29, this.createRewardButton(RewardButton.REWARD_MONEY));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(22, this.createRewardButton(RewardButton.REPEATABLE));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
|
|
|
if (this.challenge.isRepeatable())
|
|
|
|
{
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(31, this.createRewardButton(RewardButton.REPEAT_COUNT));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(15, this.createRewardButton(RewardButton.REPEAT_REWARD_TEXT));
|
|
|
|
panelBuilder.item(24, this.createRewardButton(RewardButton.REPEAT_REWARD_COMMANDS));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
panelBuilder.item(16, this.createRewardButton(RewardButton.REPEAT_REWARD_ITEM));
|
|
|
|
panelBuilder.item(25, this.createRewardButton(RewardButton.REPEAT_REWARD_EXPERIENCE));
|
|
|
|
panelBuilder.item(34, this.createRewardButton(RewardButton.REPEAT_REWARD_MONEY));
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Other methods
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method creates top menu buttons, that allows to switch "tabs".
|
|
|
|
* @param menuType Menu Type which button must be constructed.
|
|
|
|
* @return PanelItem that represents given menu type.
|
|
|
|
*/
|
|
|
|
private PanelItem createMenuButton(MenuType menuType)
|
|
|
|
{
|
|
|
|
ItemStack icon;
|
|
|
|
String name;
|
|
|
|
String description;
|
|
|
|
boolean glow;
|
|
|
|
PanelItem.ClickHandler clickHandler;
|
|
|
|
|
|
|
|
switch (menuType)
|
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
case PROPERTIES:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.properties");
|
|
|
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.properties");
|
|
|
|
icon = new ItemStack(Material.CRAFTING_TABLE);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
this.currentMenuType = MenuType.PROPERTIES;
|
|
|
|
this.build();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = this.currentMenuType.equals(MenuType.PROPERTIES);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REQUIREMENTS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.requirements");
|
|
|
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.requirements");
|
|
|
|
icon = new ItemStack(Material.HOPPER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
this.currentMenuType = MenuType.REQUIREMENTS;
|
|
|
|
this.build();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = this.currentMenuType.equals(MenuType.REQUIREMENTS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REWARDS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.rewards");
|
|
|
|
description = this.user.getTranslation("challenges.gui.descriptions.admin.rewards");
|
|
|
|
icon = new ItemStack(Material.DROPPER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
this.currentMenuType = MenuType.REWARDS;
|
|
|
|
this.build();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = this.currentMenuType.equals(MenuType.REWARDS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return null;
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return new PanelItemBuilder().
|
|
|
|
icon(icon).
|
|
|
|
name(name).
|
2019-09-08 19:03:46 +02:00
|
|
|
description(GuiUtils.stringSplit(description, this.lineLength)).
|
2019-08-05 12:00:03 +02:00
|
|
|
glow(glow).
|
|
|
|
clickHandler(clickHandler).
|
|
|
|
build();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method creates buttons for default main menu.
|
|
|
|
* @param button Button which panel item must be created.
|
2019-09-08 19:03:46 +02:00
|
|
|
* @return PanelItem that represents given button.
|
2019-08-05 12:00:03 +02:00
|
|
|
*/
|
|
|
|
private PanelItem createButton(Button button)
|
|
|
|
{
|
|
|
|
ItemStack icon;
|
|
|
|
String name;
|
|
|
|
List<String> description;
|
|
|
|
boolean glow;
|
|
|
|
PanelItem.ClickHandler clickHandler;
|
|
|
|
|
|
|
|
switch (button)
|
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
case DEPLOYED:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.deployment");
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.deployment"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[value]",
|
|
|
|
this.challenge.isDeployed() ?
|
2020-07-12 13:43:15 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
|
|
|
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.LEVER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
this.challenge.setDeployed(!this.challenge.isDeployed());
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.build();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = this.challenge.isDeployed();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ICON:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.icon");
|
|
|
|
description = Collections.singletonList(this.user.getTranslation(
|
2019-09-08 19:03:46 +02:00
|
|
|
"challenges.gui.descriptions.admin.icon-challenge"));
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = this.challenge.getIcon();
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
|
|
|
|
new SelectBlocksGUI(this.user, true, (status, materials) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
materials.forEach(material ->
|
|
|
|
this.challenge.setIcon(new ItemStack(material)));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.build();
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DESCRIPTION:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.description");
|
|
|
|
description = Collections.singletonList(
|
2019-09-08 19:03:46 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.admin.description"));
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.WRITTEN_BOOK);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new StringListGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getDescription(),
|
|
|
|
this.lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setDescription(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.build();
|
|
|
|
});
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ORDER:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.order");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.order"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[value]", Integer.toString(this.challenge.getOrder())));
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.DROPPER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getOrder(),
|
|
|
|
-1,
|
|
|
|
9999,
|
|
|
|
this.lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setOrder(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.build();
|
|
|
|
});
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ENVIRONMENT:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.environment");
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(4);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.environment"));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
description.add((this.challenge.getEnvironment().contains(World.Environment.NORMAL) ? "&2" : "&c") +
|
2019-09-08 19:03:46 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.normal"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description.add((this.challenge.getEnvironment().contains(World.Environment.NETHER) ? "&2" : "&c") +
|
2019-09-08 19:03:46 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.nether"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description.add((this.challenge.getEnvironment().contains(World.Environment.THE_END) ? "&2" : "&c") +
|
2019-09-08 19:03:46 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.the-end"));
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.DROPPER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new SelectEnvironmentGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getEnvironment(),
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setEnvironment(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.build();
|
|
|
|
});
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOVE_ON_COMPLETE:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.remove-on-complete");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-on-complete"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[value]",
|
|
|
|
this.challenge.isRemoveWhenCompleted() ?
|
2020-07-12 13:43:15 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
|
|
|
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
if (this.challenge.isRemoveWhenCompleted())
|
|
|
|
{
|
|
|
|
icon = new ItemStack(Material.LAVA_BUCKET);
|
2019-09-08 19:03:46 +02:00
|
|
|
}
|
2020-07-12 13:43:15 +02:00
|
|
|
else
|
2019-09-08 19:03:46 +02:00
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.BUCKET);
|
|
|
|
}
|
|
|
|
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
this.challenge.setRemoveWhenCompleted(!this.challenge.isRemoveWhenCompleted());
|
|
|
|
this.build();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = this.challenge.isRemoveWhenCompleted();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NAME:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.name");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.name-challenge"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[value]", this.challenge.getFriendlyName()));
|
2019-08-25 21:43:15 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.DROPPER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
2019-08-25 21:43:15 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.getFriendlyName(reply -> {
|
|
|
|
if (reply != null)
|
|
|
|
{
|
|
|
|
this.challenge.setFriendlyName(reply);
|
|
|
|
}
|
2020-04-22 00:12:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.build();
|
|
|
|
},
|
2019-09-08 19:03:46 +02:00
|
|
|
this.user.getTranslation("challenges.gui.questions.admin.challenge-name"),
|
|
|
|
this.challenge.getFriendlyName()
|
2020-07-12 13:43:15 +02:00
|
|
|
);
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
default:
|
|
|
|
return null;
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
return new PanelItemBuilder().
|
|
|
|
icon(icon).
|
|
|
|
name(name).
|
|
|
|
description(GuiUtils.stringSplit(description, this.lineLength)).
|
|
|
|
glow(glow).
|
|
|
|
clickHandler(clickHandler).
|
|
|
|
build();
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
/**
|
|
|
|
* This method creates buttons for requirements menu.
|
|
|
|
* @param button Button which panel item must be created.
|
|
|
|
* @return PanelItem that represents given button.
|
|
|
|
*/
|
|
|
|
private PanelItem createRequirementButton(RequirementButton button)
|
|
|
|
{
|
|
|
|
ItemStack icon;
|
|
|
|
String name;
|
|
|
|
List<String> description;
|
|
|
|
boolean glow;
|
|
|
|
PanelItem.ClickHandler clickHandler;
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
switch (button)
|
2019-08-05 12:00:03 +02:00
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
case REQUIRED_PERMISSIONS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.required-permissions");
|
|
|
|
description = new ArrayList<>(this.challenge.getRequirements().getRequiredPermissions().size() + 1);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-permissions"));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
for (String permission : this.challenge.getRequirements().getRequiredPermissions())
|
|
|
|
{
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.permission",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[permission]", permission));
|
2020-07-12 13:43:15 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.REDSTONE_LAMP);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new StringListGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRequirements().getRequiredPermissions(),
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.getRequirements().setRequiredPermissions(new HashSet<>(value));
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
case REQUIRED_ENTITIES:
|
|
|
|
case REMOVE_ENTITIES:
|
|
|
|
case REQUIRED_BLOCKS:
|
|
|
|
case REMOVE_BLOCKS:
|
|
|
|
case SEARCH_RADIUS:
|
|
|
|
{
|
|
|
|
return this.createIslandRequirementButton(button);
|
|
|
|
}
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
case REQUIRED_ITEMS:
|
|
|
|
case REMOVE_ITEMS:
|
|
|
|
{
|
|
|
|
return this.createInventoryRequirementButton(button);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
case REQUIRED_EXPERIENCE:
|
|
|
|
case REMOVE_EXPERIENCE:
|
|
|
|
case REQUIRED_LEVEL:
|
|
|
|
case REQUIRED_MONEY:
|
|
|
|
case REMOVE_MONEY:
|
|
|
|
{
|
|
|
|
return this.createOtherRequirementButton(button);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
default:
|
|
|
|
return null;
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
return new PanelItemBuilder().
|
2020-07-12 13:43:15 +02:00
|
|
|
icon(icon).
|
|
|
|
name(name).
|
|
|
|
description(GuiUtils.stringSplit(description, this.lineLength)).
|
|
|
|
glow(glow).
|
|
|
|
clickHandler(clickHandler).
|
|
|
|
build();
|
2019-09-08 19:03:46 +02:00
|
|
|
}
|
2019-08-25 21:43:15 +02:00
|
|
|
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
/**
|
|
|
|
* This method creates buttons for island requirements menu.
|
|
|
|
* @param button Button which panel item must be created.
|
|
|
|
* @return PanelItem that represents given button.
|
|
|
|
*/
|
|
|
|
private PanelItem createIslandRequirementButton(RequirementButton button)
|
|
|
|
{
|
|
|
|
ItemStack icon;
|
|
|
|
String name;
|
|
|
|
List<String> description;
|
|
|
|
boolean glow;
|
|
|
|
PanelItem.ClickHandler clickHandler;
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
final IslandRequirements requirements = this.challenge.getRequirements();
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
switch (button)
|
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
case REQUIRED_ENTITIES:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.required-entities");
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(requirements.getRequiredEntities().size() + 1);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-entities"));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
for (Map.Entry<EntityType, Integer> entry : requirements.getRequiredEntities().entrySet())
|
|
|
|
{
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.entity",
|
|
|
|
"[entity]", Util.prettifyText(entry.getKey().name()),
|
2019-08-05 12:00:03 +02:00
|
|
|
"[count]", Integer.toString(entry.getValue())));
|
2020-07-12 13:43:15 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.CREEPER_HEAD);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new ManageEntitiesGUI(this.addon,
|
2019-08-05 12:00:03 +02:00
|
|
|
this.world,
|
|
|
|
this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.getRequiredEntities(),
|
2019-08-05 12:00:03 +02:00
|
|
|
this.topLabel,
|
|
|
|
this.permissionPrefix,
|
|
|
|
this).build();
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOVE_ENTITIES:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.remove-entities");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-entities"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-08-05 12:00:03 +02:00
|
|
|
"[value]",
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.isRemoveEntities() ?
|
2020-07-12 13:43:15 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
|
|
|
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.LEVER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
requirements.setRemoveEntities(!requirements.isRemoveEntities());
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.build();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = requirements.isRemoveEntities();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REQUIRED_BLOCKS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.required-blocks");
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(requirements.getRequiredBlocks().size() + 1);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-blocks"));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
for (Map.Entry<Material, Integer> entry : requirements.getRequiredBlocks().entrySet())
|
|
|
|
{
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.block",
|
2019-08-05 12:00:03 +02:00
|
|
|
"[block]", entry.getKey().name(),
|
|
|
|
"[count]", Integer.toString(entry.getValue())));
|
2020-07-12 13:43:15 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.STONE);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new ManageBlocksGUI(this.addon,
|
2019-08-05 12:00:03 +02:00
|
|
|
this.world,
|
|
|
|
this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.getRequiredBlocks(),
|
2019-08-05 12:00:03 +02:00
|
|
|
this.topLabel,
|
|
|
|
this.permissionPrefix,
|
|
|
|
this).build();
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOVE_BLOCKS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.remove-blocks");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-blocks"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-08-05 12:00:03 +02:00
|
|
|
"[value]",
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.isRemoveBlocks() ?
|
2020-07-12 13:43:15 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
|
|
|
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.LEVER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
requirements.setRemoveBlocks(!requirements.isRemoveBlocks());
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.build();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = requirements.isRemoveBlocks();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SEARCH_RADIUS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.search-radius");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.search-radius"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]", Integer.toString(requirements.getSearchRadius())));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.COBBLESTONE_WALL);
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
// Search radius should not be larger then island radius.
|
|
|
|
int maxSearchDistance =
|
2019-08-05 12:00:03 +02:00
|
|
|
this.addon.getPlugin().getIWM().getAddon(this.world).map(gameModeAddon ->
|
2020-07-12 13:43:15 +02:00
|
|
|
gameModeAddon.getWorldSettings().getIslandDistance()).orElse(100);
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.getSearchRadius(),
|
|
|
|
0,
|
|
|
|
maxSearchDistance,
|
|
|
|
this.lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
requirements.setSearchRadius(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return null;
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
return new PanelItemBuilder().
|
2020-07-12 13:43:15 +02:00
|
|
|
icon(icon).
|
|
|
|
name(name).
|
|
|
|
description(GuiUtils.stringSplit(description, this.lineLength)).
|
|
|
|
glow(glow).
|
|
|
|
clickHandler(clickHandler).
|
|
|
|
build();
|
2019-09-08 19:03:46 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
/**
|
|
|
|
* This method creates buttons for inventory requirements menu.
|
|
|
|
* @param button Button which panel item must be created.
|
|
|
|
* @return PanelItem that represents given button.
|
|
|
|
*/
|
|
|
|
private PanelItem createInventoryRequirementButton(RequirementButton button)
|
|
|
|
{
|
|
|
|
ItemStack icon;
|
|
|
|
String name;
|
|
|
|
List<String> description;
|
|
|
|
boolean glow;
|
|
|
|
PanelItem.ClickHandler clickHandler;
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
final InventoryRequirements requirements = this.challenge.getRequirements();
|
|
|
|
|
|
|
|
switch (button)
|
2019-08-05 12:00:03 +02:00
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
case REQUIRED_ITEMS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.required-items");
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(requirements.getRequiredItems().size() + 1);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-items"));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
Utils.groupEqualItems(requirements.getRequiredItems()).forEach(itemStack ->
|
|
|
|
description.addAll(this.generateItemStackDescription(itemStack)));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.CHEST);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new ItemSwitchGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.getRequiredItems(),
|
|
|
|
this.lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
requirements.setRequiredItems(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOVE_ITEMS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.remove-items");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-items"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-08-05 12:00:03 +02:00
|
|
|
"[value]",
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.isTakeItems() ?
|
2020-07-12 13:43:15 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
|
|
|
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.LEVER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
requirements.setTakeItems(!requirements.isTakeItems());
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.build();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = requirements.isTakeItems();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return null;
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
return new PanelItemBuilder().
|
2020-07-12 13:43:15 +02:00
|
|
|
icon(icon).
|
|
|
|
name(name).
|
|
|
|
description(GuiUtils.stringSplit(description, this.lineLength)).
|
|
|
|
glow(glow).
|
|
|
|
clickHandler(clickHandler).
|
|
|
|
build();
|
2019-09-08 19:03:46 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
/**
|
|
|
|
* This method creates buttons for other requirements menu.
|
|
|
|
* @param button Button which panel item must be created.
|
|
|
|
* @return PanelItem that represents given button.
|
|
|
|
*/
|
|
|
|
private PanelItem createOtherRequirementButton(RequirementButton button)
|
|
|
|
{
|
|
|
|
ItemStack icon;
|
|
|
|
String name;
|
|
|
|
List<String> description;
|
|
|
|
boolean glow;
|
|
|
|
PanelItem.ClickHandler clickHandler;
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
final OtherRequirements requirements = this.challenge.getRequirements();
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
switch (button)
|
2019-08-05 12:00:03 +02:00
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
case REQUIRED_EXPERIENCE:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.required-experience");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-experience"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[value]", Integer.toString(requirements.getRequiredExperience())));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.getRequiredExperience(),
|
|
|
|
0,
|
|
|
|
this.lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
requirements.setRequiredExperience(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOVE_EXPERIENCE:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.remove-experience");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-experience"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-08-05 12:00:03 +02:00
|
|
|
"[value]",
|
2019-09-08 19:03:46 +02:00
|
|
|
requirements.isTakeExperience() ?
|
2020-07-12 13:43:15 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
|
|
|
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.LEVER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
requirements.setTakeExperience(!requirements.isTakeExperience());
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.build();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = requirements.isTakeExperience();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REQUIRED_LEVEL:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.required-level");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-level"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[value]", Long.toString(requirements.getRequiredIslandLevel())));
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(this.addon.isLevelProvided() ? Material.BEACON : Material.BARRIER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
(int) requirements.getRequiredIslandLevel(),
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
requirements.setRequiredIslandLevel(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REQUIRED_MONEY:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.required-money");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-money"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[value]", Double.toString(requirements.getRequiredMoney())));
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
(int) requirements.getRequiredMoney(),
|
|
|
|
0,
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
requirements.setRequiredMoney(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.build();
|
|
|
|
});
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
2019-09-02 12:20:59 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REMOVE_MONEY:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.remove-money");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-money"));
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
2019-09-08 19:03:46 +02:00
|
|
|
"[value]",
|
|
|
|
requirements.isTakeMoney() ?
|
2020-07-12 13:43:15 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
|
|
|
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(this.addon.isEconomyProvided() ? Material.LEVER : Material.BARRIER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
requirements.setTakeMoney(!requirements.isTakeMoney());
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.build();
|
|
|
|
return true;
|
|
|
|
};
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
glow = requirements.isTakeMoney();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return null;
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
2019-09-08 19:03:46 +02:00
|
|
|
|
|
|
|
return new PanelItemBuilder().
|
2020-07-12 13:43:15 +02:00
|
|
|
icon(icon).
|
|
|
|
name(name).
|
|
|
|
description(GuiUtils.stringSplit(description, this.lineLength)).
|
|
|
|
glow(glow).
|
|
|
|
clickHandler(clickHandler).
|
|
|
|
build();
|
2019-09-08 19:03:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method creates buttons for rewards menu.
|
|
|
|
* @param button Button which panel item must be created.
|
|
|
|
* @return PanelItem that represents given button.
|
|
|
|
*/
|
|
|
|
private PanelItem createRewardButton(RewardButton button)
|
|
|
|
{
|
|
|
|
ItemStack icon;
|
|
|
|
String name;
|
|
|
|
List<String> description;
|
|
|
|
boolean glow;
|
|
|
|
PanelItem.ClickHandler clickHandler;
|
|
|
|
|
|
|
|
switch (button)
|
2019-08-05 12:00:03 +02:00
|
|
|
{
|
2020-07-12 13:43:15 +02:00
|
|
|
case REWARD_TEXT:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.reward-text");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-text"));
|
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]", "|" + this.challenge.getRewardText()));
|
|
|
|
|
|
|
|
icon = new ItemStack(Material.WRITTEN_BOOK);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new StringListGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRewardText(),
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
String singleLineMessage = value.stream().
|
2020-07-12 13:43:15 +02:00
|
|
|
map(s -> s + "|").
|
|
|
|
collect(Collectors.joining());
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
if (singleLineMessage.endsWith("|"))
|
|
|
|
{
|
|
|
|
singleLineMessage = singleLineMessage
|
2020-07-12 13:43:15 +02:00
|
|
|
.substring(0, singleLineMessage.length() - 1);
|
2019-09-08 19:03:46 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.setRewardText(singleLineMessage);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REWARD_ITEM:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.reward-items");
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(this.challenge.getRewardItems().size() + 1);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.reward-items"));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
Utils.groupEqualItems(this.challenge.getRewardItems()).forEach(itemStack ->
|
|
|
|
description.addAll(this.generateItemStackDescription(itemStack)));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.CHEST);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new ItemSwitchGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRewardItems(),
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setRewardItems(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REWARD_EXPERIENCE:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.reward-experience");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.reward-experience"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]", Integer.toString(this.challenge.getRewardExperience())));
|
|
|
|
icon = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRewardExperience(),
|
|
|
|
0,
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setRewardExperience(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REWARD_MONEY:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.reward-money");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.reward-money"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]", Integer.toString(this.challenge.getRewardMoney())));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(
|
2019-09-08 19:03:46 +02:00
|
|
|
this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER);
|
2020-07-12 13:43:15 +02:00
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRewardMoney(),
|
|
|
|
0,
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setRewardMoney(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
2019-09-08 19:03:46 +02:00
|
|
|
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REWARD_COMMANDS:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.reward-commands");
|
|
|
|
description = new ArrayList<>(this.challenge.getRewardCommands().size() + 1);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.reward-commands"));
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
for (String command : this.challenge.getRewardCommands())
|
|
|
|
{
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.command",
|
2019-08-05 12:00:03 +02:00
|
|
|
"[command]", command));
|
2020-07-12 13:43:15 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.COMMAND_BLOCK);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new StringListGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRewardCommands(),
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setRewardCommands(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
case REPEATABLE:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.repeatable");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeatable"));
|
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]",
|
|
|
|
this.challenge.isRepeatable() ?
|
2019-08-05 12:00:03 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
2020-07-12 13:43:15 +02:00
|
|
|
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.LEVER);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
this.challenge.setRepeatable(!this.challenge.isRepeatable());
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
this.build();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = this.challenge.isRepeatable();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REPEAT_COUNT:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-count");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.repeat-count"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]", Integer.toString(this.challenge.getMaxTimes())));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.COBBLESTONE_WALL);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getMaxTimes(),
|
|
|
|
0,
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setMaxTimes(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
2019-09-02 12:20:59 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
case REPEAT_REWARD_TEXT:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-text");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.repeat-reward-text"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]", "|" + this.challenge.getRepeatRewardText()));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.WRITTEN_BOOK);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new StringListGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRepeatRewardText(),
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
String singleLineMessage = value.stream().
|
2020-07-12 13:43:15 +02:00
|
|
|
map(s -> s + "|").
|
|
|
|
collect(Collectors.joining());
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
if (singleLineMessage.endsWith("|"))
|
|
|
|
{
|
|
|
|
singleLineMessage = singleLineMessage
|
2020-07-12 13:43:15 +02:00
|
|
|
.substring(0, singleLineMessage.length() - 1);
|
2019-09-08 19:03:46 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.setRepeatRewardText(singleLineMessage);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REPEAT_REWARD_ITEM:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-items");
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(this.challenge.getRepeatItemReward().size() + 1);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.repeat-reward-items"));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
Utils.groupEqualItems(this.challenge.getRepeatItemReward()).forEach(itemStack ->
|
|
|
|
description.addAll(this.generateItemStackDescription(itemStack)));
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.TRAPPED_CHEST);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new ItemSwitchGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRepeatItemReward(),
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setRepeatItemReward(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REPEAT_REWARD_EXPERIENCE:
|
|
|
|
{
|
|
|
|
name = this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.buttons.admin.repeat-reward-experience");
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.repeat-reward-experience"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]", Integer.toString(this.challenge.getRepeatExperienceReward())));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.GLASS_BOTTLE);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRepeatExperienceReward(),
|
|
|
|
0,
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setRepeatExperienceReward(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.build();
|
|
|
|
});
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REPEAT_REWARD_MONEY:
|
|
|
|
{
|
|
|
|
name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-money");
|
|
|
|
description = new ArrayList<>(2);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.repeat-reward-money"));
|
2020-07-12 13:43:15 +02:00
|
|
|
description
|
|
|
|
.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
|
|
|
"[value]", Integer.toString(this.challenge.getRepeatMoneyReward())));
|
2019-09-08 19:03:46 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(
|
2019-09-08 19:03:46 +02:00
|
|
|
this.addon.isEconomyProvided() ? Material.GOLD_NUGGET : Material.BARRIER);
|
2020-07-12 13:43:15 +02:00
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new NumberGUI(this.user,
|
2019-08-05 12:00:03 +02:00
|
|
|
this.challenge.getRepeatMoneyReward(),
|
|
|
|
0,
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setRepeatMoneyReward(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.build();
|
|
|
|
});
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case REPEAT_REWARD_COMMANDS:
|
|
|
|
{
|
|
|
|
name =
|
2019-09-08 19:03:46 +02:00
|
|
|
this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-commands");
|
2020-07-12 13:43:15 +02:00
|
|
|
description = new ArrayList<>(this.challenge.getRepeatRewardCommands().size() + 1);
|
|
|
|
description.add(this.user
|
2019-09-08 19:03:46 +02:00
|
|
|
.getTranslation("challenges.gui.descriptions.admin.repeat-reward-commands"));
|
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
for (String command : this.challenge.getRepeatRewardCommands())
|
|
|
|
{
|
|
|
|
description.add(this.user.getTranslation("challenges.gui.descriptions.command",
|
2019-08-05 12:00:03 +02:00
|
|
|
"[command]", command));
|
2020-07-12 13:43:15 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
icon = new ItemStack(Material.COMMAND_BLOCK);
|
|
|
|
clickHandler = (panel, user, clickType, slot) -> {
|
|
|
|
new StringListGUI(this.user,
|
2019-09-08 19:03:46 +02:00
|
|
|
this.challenge.getRepeatRewardCommands(),
|
|
|
|
lineLength,
|
|
|
|
(status, value) -> {
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
this.challenge.setRepeatRewardCommands(value);
|
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
this.build();
|
|
|
|
});
|
2019-08-05 12:00:03 +02:00
|
|
|
|
2020-07-12 13:43:15 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
glow = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return null;
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return new PanelItemBuilder().
|
2020-07-12 13:43:15 +02:00
|
|
|
icon(icon).
|
|
|
|
name(name).
|
|
|
|
description(GuiUtils.stringSplit(description, this.lineLength)).
|
|
|
|
glow(glow).
|
|
|
|
clickHandler(clickHandler).
|
|
|
|
build();
|
2019-08-05 12:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Enums
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents different types of menus
|
|
|
|
*/
|
|
|
|
private enum MenuType
|
|
|
|
{
|
|
|
|
PROPERTIES,
|
|
|
|
REQUIREMENTS,
|
|
|
|
REWARDS
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents different buttons that could be in menus.
|
|
|
|
*/
|
|
|
|
private enum Button
|
|
|
|
{
|
|
|
|
NAME,
|
|
|
|
DEPLOYED,
|
|
|
|
ICON,
|
|
|
|
DESCRIPTION,
|
|
|
|
ORDER,
|
|
|
|
ENVIRONMENT,
|
|
|
|
REMOVE_ON_COMPLETE,
|
2019-09-08 19:03:46 +02:00
|
|
|
}
|
2019-08-05 12:00:03 +02:00
|
|
|
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
/**
|
|
|
|
* Represents different rewards buttons that are used in menus.
|
|
|
|
*/
|
|
|
|
private enum RewardButton
|
|
|
|
{
|
2019-08-05 12:00:03 +02:00
|
|
|
REWARD_TEXT,
|
|
|
|
REWARD_ITEM,
|
|
|
|
REWARD_EXPERIENCE,
|
|
|
|
REWARD_MONEY,
|
|
|
|
REWARD_COMMANDS,
|
|
|
|
|
|
|
|
REPEATABLE,
|
|
|
|
REPEAT_COUNT,
|
|
|
|
|
|
|
|
REPEAT_REWARD_TEXT,
|
|
|
|
REPEAT_REWARD_ITEM,
|
|
|
|
REPEAT_REWARD_EXPERIENCE,
|
|
|
|
REPEAT_REWARD_MONEY,
|
|
|
|
REPEAT_REWARD_COMMANDS,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-08 19:03:46 +02:00
|
|
|
/**
|
|
|
|
* Represents different requirement buttons that are used in menus.
|
|
|
|
*/
|
|
|
|
private enum RequirementButton
|
|
|
|
{
|
|
|
|
REQUIRED_ENTITIES,
|
|
|
|
REMOVE_ENTITIES,
|
|
|
|
REQUIRED_BLOCKS,
|
|
|
|
REMOVE_BLOCKS,
|
|
|
|
SEARCH_RADIUS,
|
|
|
|
REQUIRED_PERMISSIONS,
|
|
|
|
REQUIRED_ITEMS,
|
|
|
|
REMOVE_ITEMS,
|
|
|
|
REQUIRED_EXPERIENCE,
|
|
|
|
REMOVE_EXPERIENCE,
|
|
|
|
REQUIRED_LEVEL,
|
|
|
|
REQUIRED_MONEY,
|
|
|
|
REMOVE_MONEY,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-05 12:00:03 +02:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Variables
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Variable holds challenge thats needs editing.
|
|
|
|
*/
|
|
|
|
private Challenge challenge;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Variable holds current active menu.
|
|
|
|
*/
|
|
|
|
private MenuType currentMenuType;
|
2019-09-08 19:03:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* LineLength variable.
|
|
|
|
*/
|
|
|
|
private final int lineLength;
|
2019-07-08 19:30:34 +02:00
|
|
|
}
|