mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-28 13:36:06 +01:00
Cleanup button creation in Settings panel.
This commit is contained in:
parent
7fb5140427
commit
0bb3171c5c
@ -3,15 +3,18 @@ package world.bentobox.challenges.panel.admin;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
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.utils.GuiUtils;
|
||||
@ -52,6 +55,7 @@ public class EditSettingsGUI extends CommonGUI
|
||||
CommonGUI parentGUI)
|
||||
{
|
||||
super(addon, world, user, topLabel, permissionPrefix, parentGUI);
|
||||
this.settings = this.addon.getChallengesSettings();
|
||||
}
|
||||
|
||||
|
||||
@ -66,78 +70,198 @@ public class EditSettingsGUI extends CommonGUI
|
||||
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(
|
||||
this.user.getTranslation("challenges.gui.title.admin.settings-title"));
|
||||
|
||||
final int lineLength = this.addon.getChallengesSettings().getLoreLineLength();
|
||||
GuiUtils.fillBorder(panelBuilder);
|
||||
|
||||
// resetChallenges
|
||||
panelBuilder.item(19, this.getSettingsButton(Button.RESET_CHALLENGES));
|
||||
panelBuilder.item(20, this.getSettingsButton(Button.BROADCAST));
|
||||
panelBuilder.item(21, this.getSettingsButton(Button.REMOVE_COMPLETED));
|
||||
panelBuilder.item(22, this.getSettingsButton(Button.GLOW_COMPLETED));
|
||||
panelBuilder.item(23, this.getSettingsButton(Button.FREE_AT_TOP));
|
||||
panelBuilder.item(24, this.getSettingsButton(Button.CHALLENGE_LORE));
|
||||
panelBuilder.item(33, this.getSettingsButton(Button.LEVEL_LORE));
|
||||
panelBuilder.item(25, this.getSettingsButton(Button.LORE_LENGTH));
|
||||
|
||||
List<String> description = new ArrayList<>(2);
|
||||
// Return Button
|
||||
panelBuilder.item(44, this.returnButton);
|
||||
|
||||
panelBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
private PanelItem getSettingsButton(Button button)
|
||||
{
|
||||
ItemStack icon;
|
||||
String name;
|
||||
List<String> description;
|
||||
boolean glow;
|
||||
PanelItem.ClickHandler clickHandler;
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case RESET_CHALLENGES:
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reset-on-new"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]",
|
||||
this.addon.getChallengesSettings().isResetChallenges() ?
|
||||
this.settings.isResetChallenges() ?
|
||||
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
||||
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.reset-on-new");
|
||||
icon = new ItemStack(Material.LAVA_BUCKET);
|
||||
|
||||
panelBuilder.item(19, new PanelItemBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.buttons.admin.reset-on-new")).
|
||||
description(GuiUtils.stringSplit(description, lineLength)).
|
||||
icon(Material.LAVA_BUCKET).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
this.addon.getChallengesSettings().setResetChallenges(
|
||||
!this.addon.getChallengesSettings().isResetChallenges());
|
||||
this.build();
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
this.settings.setResetChallenges(
|
||||
!this.settings.isResetChallenges());
|
||||
|
||||
panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
return true;
|
||||
}).
|
||||
glow(this.addon.getChallengesSettings().isResetChallenges()).
|
||||
build());
|
||||
};
|
||||
|
||||
// broadcastMessages
|
||||
description.clear();
|
||||
glow = this.settings.isResetChallenges();
|
||||
break;
|
||||
}
|
||||
case BROADCAST:
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.broadcast"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]",
|
||||
this.addon.getChallengesSettings().isBroadcastMessages() ?
|
||||
this.settings.isBroadcastMessages() ?
|
||||
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
||||
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
||||
|
||||
panelBuilder.item(20, new PanelItemBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.buttons.admin.broadcast")).
|
||||
description(GuiUtils.stringSplit(description, lineLength)).
|
||||
icon(Material.JUKEBOX).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
this.addon.getChallengesSettings().setBroadcastMessages(
|
||||
!this.addon.getChallengesSettings().isBroadcastMessages());
|
||||
this.build();
|
||||
return true;
|
||||
}).
|
||||
glow(this.addon.getChallengesSettings().isBroadcastMessages()).
|
||||
build());
|
||||
description = new ArrayList<>(2);
|
||||
|
||||
// removeCompleteOneTimeChallenges
|
||||
description.clear();
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.broadcast");
|
||||
icon = new ItemStack(Material.JUKEBOX);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
this.settings.setBroadcastMessages(
|
||||
!this.settings.isBroadcastMessages());
|
||||
panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
return true;
|
||||
};
|
||||
glow = this.settings.isBroadcastMessages();
|
||||
|
||||
break;
|
||||
}
|
||||
case REMOVE_COMPLETED:
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-completed"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]",
|
||||
this.addon.getChallengesSettings().isRemoveCompleteOneTimeChallenges() ?
|
||||
this.settings.isRemoveCompleteOneTimeChallenges() ?
|
||||
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
||||
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
||||
|
||||
panelBuilder.item(21, new PanelItemBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.buttons.admin.remove-completed")).
|
||||
description(GuiUtils.stringSplit(description, lineLength)).
|
||||
icon(Material.MAGMA_BLOCK).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
this.addon.getChallengesSettings().setRemoveCompleteOneTimeChallenges(
|
||||
!this.addon.getChallengesSettings().isRemoveCompleteOneTimeChallenges());
|
||||
this.build();
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.remove-completed");
|
||||
icon = new ItemStack(Material.MAGMA_BLOCK);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
this.settings.setRemoveCompleteOneTimeChallenges(
|
||||
!this.settings.isRemoveCompleteOneTimeChallenges());
|
||||
panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
return true;
|
||||
}).
|
||||
glow(this.addon.getChallengesSettings().isRemoveCompleteOneTimeChallenges()).
|
||||
build());
|
||||
};
|
||||
glow = this.settings.isRemoveCompleteOneTimeChallenges();
|
||||
|
||||
// addCompletedGlow
|
||||
description.clear();
|
||||
break;
|
||||
}
|
||||
case LORE_LENGTH:
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.line-length"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]", Integer.toString(this.settings.getLoreLineLength())));
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.line-length");
|
||||
icon = new ItemStack(Material.ANVIL);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
new NumberGUI(this.user,
|
||||
this.settings.getLoreLineLength(),
|
||||
0,
|
||||
this.settings.getLoreLineLength(),
|
||||
(status, value) -> {
|
||||
if (status)
|
||||
{
|
||||
this.settings.setLoreLineLength(value);
|
||||
}
|
||||
|
||||
panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
glow = false;
|
||||
break;
|
||||
}
|
||||
case LEVEL_LORE:
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.level-lore"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]", this.settings.getLevelLoreMessage()));
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.level-lore");
|
||||
icon = new ItemStack(Material.PAPER);
|
||||
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;
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
glow = false;
|
||||
break;
|
||||
}
|
||||
case CHALLENGE_LORE:
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.challenge-lore"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]", this.settings.getChallengeLoreMessage()));
|
||||
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;
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
glow = false;
|
||||
break;
|
||||
}
|
||||
case FREE_AT_TOP:
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.free-at-top"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]",
|
||||
this.settings.isAddCompletedGlow() ?
|
||||
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
||||
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.free-at-top");
|
||||
icon = new ItemStack(Material.FILLED_MAP);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
this.settings.setFreeChallengesFirst(!this.settings.isFreeChallengesFirst());
|
||||
panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
return true;
|
||||
};
|
||||
glow = this.settings.isFreeChallengesFirst();
|
||||
break;
|
||||
}
|
||||
case GLOW_COMPLETED:
|
||||
{
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.glow"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]",
|
||||
@ -145,120 +269,48 @@ public class EditSettingsGUI extends CommonGUI
|
||||
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
||||
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
||||
|
||||
panelBuilder.item(22, new PanelItemBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.buttons.admin.glow")).
|
||||
description(GuiUtils.stringSplit(description, lineLength)).
|
||||
icon(Material.GLOWSTONE).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
this.addon.getChallengesSettings().setAddCompletedGlow(
|
||||
!this.addon.getChallengesSettings().isAddCompletedGlow());
|
||||
this.build();
|
||||
|
||||
name = this.user.getTranslation("challenges.gui.buttons.admin.glow");
|
||||
icon = new ItemStack(Material.GLOWSTONE);
|
||||
clickHandler = (panel, user1, clickType, i) -> {
|
||||
this.settings.setAddCompletedGlow(!this.settings.isAddCompletedGlow());
|
||||
panel.getInventory().setItem(i, this.getSettingsButton(button).getItem());
|
||||
return true;
|
||||
}).
|
||||
glow(this.addon.getChallengesSettings().isAddCompletedGlow()).
|
||||
build());
|
||||
};
|
||||
glow = this.settings.isAddCompletedGlow();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return new PanelItemBuilder().build();
|
||||
}
|
||||
|
||||
// freeChallengesAtTheTop
|
||||
description.clear();
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.free-at-top"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]",
|
||||
this.addon.getChallengesSettings().isAddCompletedGlow() ?
|
||||
this.user.getTranslation("challenges.gui.descriptions.enabled") :
|
||||
this.user.getTranslation("challenges.gui.descriptions.disabled")));
|
||||
return new PanelItem(icon, name, GuiUtils.stringSplit(description, this.settings.getLoreLineLength()), glow, clickHandler, false);
|
||||
}
|
||||
|
||||
panelBuilder.item(23, new PanelItemBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.buttons.admin.free-at-top")).
|
||||
description(GuiUtils.stringSplit(description, lineLength)).
|
||||
icon(Material.FILLED_MAP).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
this.addon.getChallengesSettings().setFreeChallengesFirst(
|
||||
!this.addon.getChallengesSettings().isFreeChallengesFirst());
|
||||
this.build();
|
||||
return true;
|
||||
}).
|
||||
glow(this.addon.getChallengesSettings().isFreeChallengesFirst()).
|
||||
build());
|
||||
|
||||
// Challenge Lore Message
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.challenge-lore"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]", this.addon.getChallengesSettings().getChallengeLoreMessage()));
|
||||
panelBuilder.item(24, new PanelItemBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.buttons.admin.challenge-lore")).
|
||||
description(GuiUtils.stringSplit(description, lineLength)).
|
||||
icon(Material.PAPER).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.addon.getChallengesSettings().getChallengeLoreMessage(),
|
||||
(player, reply) -> {
|
||||
this.addon.getChallengesSettings().setChallengeLoreMessage(reply);
|
||||
this.build();
|
||||
return reply;
|
||||
});
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Variables
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
return true;
|
||||
}).
|
||||
glow(false).
|
||||
build());
|
||||
|
||||
// Level Lore Message
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.level-lore"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]", this.addon.getChallengesSettings().getLevelLoreMessage()));
|
||||
panelBuilder.item(33, new PanelItemBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.buttons.admin.level-lore")).
|
||||
description(GuiUtils.stringSplit(description, lineLength)).
|
||||
icon(Material.PAPER).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
new AnvilGUI(this.addon.getPlugin(),
|
||||
this.user.getPlayer(),
|
||||
this.addon.getChallengesSettings().getLevelLoreMessage(),
|
||||
(player, reply) -> {
|
||||
this.addon.getChallengesSettings().setLevelLoreMessage(reply);
|
||||
this.build();
|
||||
return reply;
|
||||
});
|
||||
|
||||
return true;
|
||||
}).
|
||||
glow(false).
|
||||
build());
|
||||
|
||||
// Lore line length
|
||||
description = new ArrayList<>(2);
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.line-length"));
|
||||
description.add(this.user.getTranslation("challenges.gui.descriptions.current-value",
|
||||
"[value]", Integer.toString(this.addon.getChallengesSettings().getLoreLineLength())));
|
||||
panelBuilder.item(25, new PanelItemBuilder().
|
||||
name(this.user.getTranslation("challenges.gui.buttons.admin.line-length")).
|
||||
description(GuiUtils.stringSplit(description, lineLength)).
|
||||
icon(Material.ANVIL).
|
||||
clickHandler((panel, user1, clickType, i) -> {
|
||||
new NumberGUI(this.user,
|
||||
this.addon.getChallengesSettings().getLoreLineLength(),
|
||||
0,
|
||||
lineLength,
|
||||
(status, value) -> {
|
||||
if (status)
|
||||
/**
|
||||
* This enum holds all settings buttons that must have been displayed in this panel.
|
||||
*/
|
||||
private enum Button
|
||||
{
|
||||
this.addon.getChallengesSettings().setLoreLineLength(value);
|
||||
RESET_CHALLENGES,
|
||||
BROADCAST,
|
||||
REMOVE_COMPLETED,
|
||||
LORE_LENGTH,
|
||||
LEVEL_LORE,
|
||||
CHALLENGE_LORE,
|
||||
FREE_AT_TOP,
|
||||
GLOW_COMPLETED
|
||||
}
|
||||
|
||||
this.build();
|
||||
});
|
||||
|
||||
return true;
|
||||
}).
|
||||
glow(this.addon.getChallengesSettings().isFreeChallengesFirst()).
|
||||
build());
|
||||
|
||||
// Return Button
|
||||
panelBuilder.item(44, this.returnButton);
|
||||
|
||||
panelBuilder.build();
|
||||
}
|
||||
/**
|
||||
* This allows faster access to challenges settings object.
|
||||
*/
|
||||
private Settings settings;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user