Implement configurable locked level icon (#98)

- Implement LockedIcon in ChallengeLevel (can be null)
- Implement defaultLockedIcon in Settings (can be overwritten by ChallengeLevel)
- Reformat Config File. !!!
This commit is contained in:
BONNe1704 2019-02-25 12:09:26 +02:00
parent e019257d38
commit 0f32e0e3d4
8 changed files with 256 additions and 85 deletions

View File

@ -99,6 +99,13 @@ public class ChallengesAddon extends Addon {
return;
}
// Check if addon is not disabled before.
if (this.getState().equals(State.DISABLED))
{
Bukkit.getLogger().severe("Challenges Addon is not available or disabled!");
return;
}
// Challenges Manager
this.challengesManager = new ChallengesManager(this);
// Challenge import setup

View File

@ -1,6 +1,8 @@
package world.bentobox.challenges;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
@ -60,43 +62,32 @@ public class Settings implements DataObject
@ConfigEntry(path = "history.lifespan")
private int lifeSpan = 14;
@ConfigComment("")
@ConfigComment("Reset Challenges - if this is true, player's challenges will reset when they")
@ConfigComment("reset an island or if they are kicked or leave a team. Prevents exploiting the")
@ConfigComment("challenges by doing them repeatedly.")
@ConfigEntry(path = "reset-challenges")
private boolean resetChallenges = true;
@ConfigComment("")
@ConfigComment("Broadcast 1st time challenge completion messages to all players.")
@ConfigComment("Change to false if the spam becomes too much.")
@ConfigEntry(path = "broadcast-messages")
private boolean broadcastMessages = true;
@ConfigComment("")
@ConfigComment("Remove non-repeatable challenges from the challenge GUI when complete.")
@ConfigEntry(path = "remove-complete-one-time-challenges")
@ConfigEntry(path = "gui-settings.remove-complete-one-time-challenges")
private boolean removeCompleteOneTimeChallenges = false;
@ConfigComment("")
@ConfigComment("Add enchanted glow to completed challenges")
@ConfigEntry(path = "add-completed-glow")
@ConfigEntry(path = "gui-settings.add-completed-glow")
private boolean addCompletedGlow = true;
@ConfigComment("")
@ConfigComment("This indicate if free challenges must be at the start (true) or at the end (false) of list.")
@ConfigEntry(path = "free-challenges-first")
private boolean freeChallengesFirst = true;
@ConfigComment("This allows to change default locked level icon. This option may be")
@ConfigComment("overwritten by each challenge level. If challenge level has specified")
@ConfigComment("their locked level icon, then it will be used, instead of this one.")
@ConfigEntry(path = "gui-settings.locked-level-icon")
private ItemStack lockedLevelIcon = new ItemStack(Material.BOOK);
@ConfigComment("")
@ConfigComment("This indicate if challenges data will be stored per island (true) or per player (false).")
@ConfigEntry(path = "store-island-data")
private boolean storeAsIslandData = false;
@ConfigComment("This indicate if free challenges must be at the start (true) or at the end (false) of list.")
@ConfigEntry(path = "gui-settings.free-challenges-first")
private boolean freeChallengesFirst = true;
@ConfigComment("")
@ConfigComment("This allows to change lore description line length. By default it is 25, but some server")
@ConfigComment("owners may like it to be larger.")
@ConfigEntry(path = "lore-length")
@ConfigEntry(path = "gui-settings.lore-length")
private int loreLineLength = 25;
@ConfigComment("")
@ -115,7 +106,7 @@ public class Settings implements DataObject
@ConfigComment(" - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'")
@ConfigComment("By adding 'i' after Q or R (requirements and rewards) will display list of items, blocks")
@ConfigComment("and entities that are defined in challenge and can be customized under 'challenges.gui.description.*'")
@ConfigEntry(path = "challenge-lore-message")
@ConfigEntry(path = "gui-settings.challenge-lore-message")
private String challengeLoreMessage = "LSTDEQiWRi";
@ConfigComment("")
@ -131,9 +122,27 @@ public class Settings implements DataObject
@ConfigComment(" - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'")
@ConfigComment("By adding 'i' after R (rewards) will display list of items that are defined in challenge")
@ConfigComment("and can be customized under 'challenges.gui.description.*'")
@ConfigEntry(path = "level-lore-message")
@ConfigEntry(path = "gui-settings.level-lore-message")
private String levelLoreMessage = "STDARi";
@ConfigComment("")
@ConfigComment("This indicate if challenges data will be stored per island (true) or per player (false).")
@ConfigEntry(path = "store-island-data")
private boolean storeAsIslandData = false;
@ConfigComment("")
@ConfigComment("Reset Challenges - if this is true, player's challenges will reset when users")
@ConfigComment("reset an island or if users are kicked or leave a team. Prevents exploiting the")
@ConfigComment("challenges by doing them repeatedly.")
@ConfigEntry(path = "reset-challenges")
private boolean resetChallenges = true;
@ConfigComment("")
@ConfigComment("Broadcast 1st time challenge completion messages to all players.")
@ConfigComment("Change to false if the spam becomes too much.")
@ConfigEntry(path = "broadcast-messages")
private boolean broadcastMessages = true;
@ConfigComment("")
@ConfigComment("This list stores GameModes in which Challenges addon should not work.")
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
@ -152,7 +161,8 @@ public class Settings implements DataObject
* Configuration version
*/
@ConfigComment("")
private String configVersion = "v1.5";
private String configVersion = "v2";
// ---------------------------------------------------------------------
// Section: Methods
@ -330,6 +340,27 @@ public class Settings implements DataObject
}
/**
* This method returns the lockedLevelIcon value.
* @return the value of lockedLevelIcon.
*/
public ItemStack getLockedLevelIcon()
{
return lockedLevelIcon.clone();
}
/**
* This method sets the lockedLevelIcon value.
* @param lockedLevelIcon the lockedLevelIcon new value.
*
*/
public void setLockedLevelIcon(ItemStack lockedLevelIcon)
{
this.lockedLevelIcon = lockedLevelIcon;
}
/**
* This method sets the userGuiMode value.
* @param userGuiMode the userGuiMode new value.

View File

@ -47,6 +47,12 @@ public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
@Expose
private ItemStack icon = new ItemStack(Material.BOOK);
@ConfigComment("")
@ConfigComment("ItemStack that represents current level when it is locked. Will be used")
@ConfigComment("as icon in GUIs. Will overwrite icon defined in addon settings.")
@Expose
private ItemStack lockedIcon = null;
@ConfigComment("")
@ConfigComment("World that this level applies in. String.")
@Expose
@ -142,6 +148,16 @@ public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
}
/**
* This method returns the closedIcon value.
* @return the value of closedIcon.
*/
public ItemStack getLockedIcon()
{
return lockedIcon;
}
/**
* This method returns the world value.
* @return the value of world.
@ -282,6 +298,17 @@ public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
}
/**
* This method sets the closedIcon value.
* @param closedIcon the closedIcon new value.
*
*/
public void setLockedIcon(ItemStack closedIcon)
{
this.lockedIcon = closedIcon;
}
/**
* This method sets the world value.
* @param world the world new value.

View File

@ -116,6 +116,7 @@ public class EditLevelGUI extends CommonGUI
panelBuilder.item(10, this.createButton(Button.NAME));
panelBuilder.item(19, this.createButton(Button.ICON));
panelBuilder.item(28, this.createButton(Button.CLOSED_ICON));
panelBuilder.item(22, this.createButton(Button.UNLOCK_MESSAGE));
panelBuilder.item(25, this.createButton(Button.ORDER));
@ -330,7 +331,7 @@ public class EditLevelGUI extends CommonGUI
{
name = this.user.getTranslation("challenges.gui.buttons.admin.icon");
description = Collections.singletonList(this.user.getTranslation(
"challenges.gui.descriptions.admin.icon-challenge"));
"challenges.gui.descriptions.admin.icon-level"));
icon = this.challengeLevel.getIcon();
clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(),
@ -357,6 +358,55 @@ public class EditLevelGUI extends CommonGUI
glow = false;
break;
}
case CLOSED_ICON:
{
name = this.user.getTranslation("challenges.gui.buttons.admin.locked-icon");
description = Collections.singletonList(this.user.getTranslation(
"challenges.gui.descriptions.admin.locked-icon"));
boolean isNull = this.challengeLevel.getLockedIcon() == null;
if (isNull)
{
icon = new ItemStack(Material.BARRIER);
}
else
{
icon = this.challengeLevel.getLockedIcon().clone();
}
clickHandler = (panel, user, clickType, slot) -> {
new AnvilGUI(this.addon.getPlugin(),
this.user.getPlayer(),
isNull ? "NULL" : icon.getType().name(),
(player, reply) -> {
if (reply.equals("NULL"))
{
this.challengeLevel.setLockedIcon(null);
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;
};
glow = false;
break;
}
case UNLOCK_MESSAGE:
{
name = this.user.getTranslation("challenges.gui.buttons.admin.description");
@ -663,6 +713,7 @@ public class EditLevelGUI extends CommonGUI
{
NAME,
ICON,
CLOSED_ICON,
UNLOCK_MESSAGE,
ORDER,
WAIVER_AMOUNT,

View File

@ -73,13 +73,14 @@ public class EditSettingsGUI extends CommonGUI
GuiUtils.fillBorder(panelBuilder);
panelBuilder.item(19, this.getSettingsButton(Button.RESET_CHALLENGES));
panelBuilder.item(28, this.getSettingsButton(Button.REMOVE_COMPLETED));
panelBuilder.item(28, this.getSettingsButton(Button.BROADCAST));
panelBuilder.item(20, this.getSettingsButton(Button.BROADCAST));
panelBuilder.item(29, this.getSettingsButton(Button.GLOW_COMPLETED));
panelBuilder.item(20, this.getSettingsButton(Button.GLOW_COMPLETED));
panelBuilder.item(29, this.getSettingsButton(Button.REMOVE_COMPLETED));
panelBuilder.item(22, this.getSettingsButton(Button.FREE_AT_TOP));
panelBuilder.item(31, this.getSettingsButton(Button.GAMEMODE_GUI));
panelBuilder.item(12, this.getSettingsButton(Button.LOCKED_LEVEL_ICON));
panelBuilder.item(21, this.getSettingsButton(Button.FREE_AT_TOP));
panelBuilder.item(30, this.getSettingsButton(Button.GAMEMODE_GUI));
panelBuilder.item(14, this.getSettingsButton(Button.LORE_LENGTH));
panelBuilder.item(23, this.getSettingsButton(Button.CHALLENGE_LORE));
@ -389,6 +390,37 @@ public class EditSettingsGUI extends CommonGUI
glow = this.settings.isStoreAsIslandData();
break;
}
case LOCKED_LEVEL_ICON:
{
description = new ArrayList<>(1);
description.add(this.user.getTranslation("challenges.gui.descriptions.admin.default-locked-icon"));
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)
{
this.settings.setLockedLevelIcon(new ItemStack(material));
this.build();
}
else
{
this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply);
}
return reply;
});
return true;
};
glow = false;
break;
}
default:
return new PanelItemBuilder().build();
}
@ -418,7 +450,8 @@ public class EditSettingsGUI extends CommonGUI
HISTORY,
PURGE_HISTORY,
STORE_MODE,
GLOW_COMPLETED
GLOW_COMPLETED,
LOCKED_LEVEL_ICON
}

View File

@ -417,7 +417,16 @@ public class ChallengesGUI extends CommonGUI
}
else
{
icon = new ItemStack(Material.BOOK);
if (level.getLevel().getLockedIcon() != null)
{
// Clone will prevent issues with description storing.
// It can be done only here as it can be null.
icon = level.getLevel().getLockedIcon().clone();
}
else
{
icon = this.addon.getChallengesSettings().getLockedLevelIcon();
}
description = GuiUtils.stringSplit(
this.user.getTranslation("challenges.gui.descriptions.level-locked",

View File

@ -34,10 +34,66 @@ history:
#
# This allows to specify an amount of time in days when history data will
# be removed. 0 means that data will not be removed.
lifespan: false
lifespan: 14
gui-settings:
#
# Remove non-repeatable challenges from the challenge GUI when complete.
remove-complete-one-time-challenges: false
#
# Add enchanted glow to completed challenges
add-completed-glow: true
#
# This allows to change default locked level icon. This option may be
# overwritten by each challenge level. If challenge level has specified
# their locked level icon, then it will be used, instead of this one.
locked-level-icon:
==: org.bukkit.inventory.ItemStack
v: 1631
type: BOOK
#
# This indicate if free challenges must be at the start (true) or at the end (false) of list.
free-challenges-first: true
#
# This allows to change lore description line length. By default it is 25, but some server
# owners may like it to be larger.
lore-length: 25
#
# This string allows to change element order in Challenge description. Each letter represents
# one object from challenge description. If letter is not used, then its represented part
# will not be in description. If use any letter that is not recognized, then it will be
# ignored. Some strings can be customized via lang file under 'challenges.gui.challenge-description'.
# List of letters and their meaning:
# - L - Level String: '*.level'
# - S - Status String: '*.completed'
# - T - Times String: '*.completed-times', '*.completed-times-of' or '*.maxed-reached'
# - D - Description String: defined in challenge object - challenge.description
# - W - Warning String: '*.warning-items-take', '*.objects-close-by', '*.warning-entities-kill', '*.warning-blocks-remove'
# - E - Environment String: defined in challenge object - challenge.environment
# - Q - Requirement String: '*.required-level', '*.required-money', '*.required-experience'
# - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'
# By adding 'i' after Q or R (requirements and rewards) will display list of items, blocks
# and entities that are defined in challenge and can be customized under 'challenges.gui.description.*'
challenge-lore-message: LSTDEQiWRi
#
# This string allows to change element order in Level description. Each letter represents
# one object from level description. If letter is not used, then its represented part
# will not be in description. If use any letter that is not recognized, then it will be
# ignored. Some strings can be customized via lang file under 'challenges.gui.level-description'.
# List of letters and their meaning:
# - S - Status String: '*.completed'
# - T - Count of completed challenges String: '*.completed-challenges-of'
# - D - Description String: defined in level object - challengeLevel.unlockMessage
# - A - WaiverAmount String: '*.waver-amount'
# - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'
# By adding 'i' after R (rewards) will display list of items that are defined in challenge
# and can be customized under 'challenges.gui.description.*'
level-lore-message: STDARi
#
# Reset Challenges - if this is true, player's challenges will reset when they
# reset an island or if they are kicked or leave a team. Prevents exploiting the
# This indicate if challenges data will be stored per island (true) or per player (false).
store-island-data: false
#
# Reset Challenges - if this is true, player's challenges will reset when users
# reset an island or if users are kicked or leave a team. Prevents exploiting the
# challenges by doing them repeatedly.
reset-challenges: true
#
@ -45,53 +101,6 @@ reset-challenges: true
# Change to false if the spam becomes too much.
broadcast-messages: true
#
# Remove non-repeatable challenges from the challenge GUI when complete.
remove-complete-one-time-challenges: false
#
# Add enchanted glow to completed challenges
add-completed-glow: true
#
# This indicate if free challenges must be at the start (true) or at the end (false) of list.
free-challenges-first: true
#
# This indicate if challenges data will be stored per island (true) or per player (false).
store-island-data: false
#
# This allows to change lore description line length. By default it is 25, but some server
# owners may like it to be larger.
lore-length: 25
#
# This string allows to change element order in Challenge description. Each letter represents
# one object from challenge description. If letter is not used, then its represented part
# will not be in description. If use any letter that is not recognized, then it will be
# ignored. Some strings can be customized via lang file under 'challenges.gui.challenge-description'.
# List of letters and their meaning:
# - L - Level String: '*.level'
# - S - Status String: '*.completed'
# - T - Times String: '*.completed-times', '*.completed-times-of' or '*.maxed-reached'
# - D - Description String: defined in challenge object - challenge.description
# - W - Warning String: '*.warning-items-take', '*.objects-close-by', '*.warning-entities-kill', '*.warning-blocks-remove'
# - E - Environment String: defined in challenge object - challenge.environment
# - Q - Requirement String: '*.required-level', '*.required-money', '*.required-experience'
# - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'
# By adding 'i' after Q or R (requirements and rewards) will display list of items, blocks
# and entities that are defined in challenge and can be customized under 'challenges.gui.description.*'
challenge-lore-message: LSTDEQiWRi
#
# This string allows to change element order in Level description. Each letter represents
# one object from level description. If letter is not used, then its represented part
# will not be in description. If use any letter that is not recognized, then it will be
# ignored. Some strings can be customized via lang file under 'challenges.gui.level-description'.
# List of letters and their meaning:
# - S - Status String: '*.completed'
# - T - Count of completed challenges String: '*.completed-challenges-of'
# - D - Description String: defined in level object - challengeLevel.unlockMessage
# - A - WaiverAmount String: '*.waver-amount'
# - R - Reward String: '*.experience-reward', '*.money-reward', '*.not-repeatable'
# By adding 'i' after R (rewards) will display list of items that are defined in challenge
# and can be customized under 'challenges.gui.description.*'
level-lore-message: STDARi
#
# This list stores GameModes in which Challenges addon should not work.
# To disable addon it is necessary to write its name in new line that starts with -. Example:
# disabled-gamemodes:
@ -100,4 +109,4 @@ disabled-gamemodes: []
#
uniqueId: config
#
configVersion: v1.5
configVersion: v2

View File

@ -78,6 +78,7 @@ challenges:
type: 'Challenge Type'
deployment: 'Deployment'
icon: 'Icon'
locked-icon: 'Locked Icon'
description: 'Description'
order: 'Order'
environment: 'Environment'
@ -140,6 +141,7 @@ challenges:
history-store: 'Challenges History'
history-lifespan: 'History LifeSpan'
island-store: 'Store per Island'
default-locked-icon: 'Locked Level Icon'
next: 'Next'
previous: 'Previous'
return: 'Return'
@ -171,6 +173,7 @@ challenges:
deployment: 'Allows users to complete (view) challenge.'
icon-challenge: 'Icon that will be displayed in GUI panels for this challenge.'
icon-level: 'Icon that will be displayed in GUI panels for this level.'
locked-icon: 'Icon that will be displayed in GUI panels if level is locked.'
description: 'Allows to edit description.'
order: 'Allows to change order number.'
environment: 'Allows to change environment where challenge operates.'
@ -226,6 +229,7 @@ challenges:
history-store: 'Allows to enable/disable challenges history storage.'
history-lifespan: 'Allows to modify how many days history data will be saved.|0 means forever.'
island-store: 'Allows to enable/disable challenges data string per island. This means that challenges will be the same on whole team, if this is enabled.|Will convert data on click.'
default-locked-icon: 'Allows to change default locked level icon.|This option can be overwritten by each level.'
current-value: '|&6Current value: [value].'
enabled: 'Active'
disabled: 'Disabled'
@ -315,4 +319,4 @@ challenges:
import-no-file: '&cCould not find challenges.yml file to import!'
no-load: '&cError: Could not load challenges.yml. [message]'
load-error: '&cError: Cannot load [value].'
version: 7
version: 8