Skip to content

Commit

Permalink
Implement configurable locked level icon (#98)
Browse files Browse the repository at this point in the history
- Implement LockedIcon in ChallengeLevel (can be null)
- Implement defaultLockedIcon in Settings (can be overwritten by ChallengeLevel)
- Reformat Config File. !!!
  • Loading branch information
BONNe committed Feb 25, 2019
1 parent e019257 commit 0f32e0e
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 85 deletions.
7 changes: 7 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public void onEnable() {
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
Expand Down
81 changes: 56 additions & 25 deletions src/main/java/world/bentobox/challenges/Settings.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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("")
Expand All @@ -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("")
Expand All @@ -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:")
Expand All @@ -152,7 +161,8 @@ public class Settings implements DataObject
* Configuration version
*/
@ConfigComment("")
private String configVersion = "v1.5";
private String configVersion = "v2";


// ---------------------------------------------------------------------
// Section: Methods
Expand Down Expand Up @@ -330,6 +340,27 @@ public int getLifeSpan()
}


/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public 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
Expand Down Expand Up @@ -142,6 +148,16 @@ public ItemStack getIcon()
}


/**
* 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.
Expand Down Expand Up @@ -282,6 +298,17 @@ public void setIcon(ItemStack icon)
}


/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ private void buildMainPropertiesPanel(PanelBuilder panelBuilder)
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));

Expand Down Expand Up @@ -330,7 +331,7 @@ private PanelItem createButton(Button button)
{
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(),
Expand All @@ -357,6 +358,55 @@ private PanelItem createButton(Button button)
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");
Expand Down Expand Up @@ -663,6 +713,7 @@ private enum Button
{
NAME,
ICON,
CLOSED_ICON,
UNLOCK_MESSAGE,
ORDER,
WAIVER_AMOUNT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ public void build()
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));
Expand Down Expand Up @@ -389,6 +390,37 @@ private PanelItem getSettingsButton(Button button)
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();
}
Expand Down Expand Up @@ -418,7 +450,8 @@ private enum Button
HISTORY,
PURGE_HISTORY,
STORE_MODE,
GLOW_COMPLETED
GLOW_COMPLETED,
LOCKED_LEVEL_ICON
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,16 @@ else if (level.isUnlocked())
}
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",
Expand Down

0 comments on commit 0f32e0e

Please sign in to comment.