Skip to content

Commit

Permalink
Add ability to specify Lore line length via Settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Feb 11, 2019
1 parent 2bbb4e5 commit b2201ec
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ private void makeChallenges(User user, World world, boolean overwrite) {
newChallenge.setDeployed(true);
ConfigurationSection details = chals.getConfigurationSection(challenge);
newChallenge.setFriendlyName(details.getString("friendlyname", challenge));
newChallenge.setDescription(GuiUtils.stringSplit(details.getString("description", "")));
newChallenge.setDescription(GuiUtils.stringSplit(
details.getString("description", ""),
this.addon.getChallengesSettings().getLoreLineLength()));
newChallenge.setIcon(ItemParser.parse(details.getString("icon", "") + ":1"));

if (details.getString("type", "").equalsIgnoreCase("level"))
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/world/bentobox/challenges/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,36 @@ public class Settings implements DataObject
@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")
private boolean removeCompleteOneTimeChallenges = false;

@ConfigComment("")
@ConfigComment("Add enchanted glow to completed challenges")
@ConfigEntry(path = "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("")
@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")
private int loreLineLength = 25;

@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 Down Expand Up @@ -122,6 +133,16 @@ public boolean isFreeChallengesFirst()
}


/**
* This method returns the loreLineLength object.
* @return the loreLineLength object.
*/
public int getLoreLineLength()
{
return loreLineLength;
}


@Override
public void setUniqueId(String uniqueId)
{
Expand Down Expand Up @@ -181,4 +202,14 @@ public void setFreeChallengesFirst(boolean freeChallengesFirst)
{
this.freeChallengesFirst = freeChallengesFirst;
}


/**
* This method sets the loreLineLength object value.
* @param loreLineLength the loreLineLength object new value.
*/
public void setLoreLineLength(int loreLineLength)
{
this.loreLineLength = loreLineLength;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ private void addNavigation(PanelBuilder panelBuilder) {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.ENCHANTED_BOOK))
.name(name)
.description(GuiUtils.stringSplit(user.getTranslation("challenges.navigation","[level]",name)))
.description(GuiUtils.stringSplit(
user.getTranslation("challenges.navigation","[level]",name),
this.addon.getChallengesSettings().getLoreLineLength()))
.clickHandler((p, u, c, s) -> {
u.closeInventory();
u.performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + status.getLevel().getUniqueId());
Expand All @@ -146,7 +148,11 @@ private void addNavigation(PanelBuilder panelBuilder) {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.BOOK))
.name(name)
.description(GuiUtils.stringSplit(user.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName)))
.description(GuiUtils.stringSplit(
user.getTranslation("challenges.to-complete",
"[challengesToDo]", String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""),
"[thisLevel]", previousLevelName),
this.addon.getChallengesSettings().getLoreLineLength()))
.build();
panelBuilder.item(item);
}
Expand Down Expand Up @@ -236,6 +242,7 @@ private List<String> challengeDescription(Challenge challenge) {
}

private Collection<? extends String> splitTrans(User user, String string, String...strings) {
return GuiUtils.stringSplit(user.getTranslation(string, strings));
return GuiUtils.stringSplit(user.getTranslation(string, strings),
this.addon.getChallengesSettings().getLoreLineLength());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ private void addNavigation(PanelBuilder panelBuilder) {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.ENCHANTED_BOOK))
.name(name)
.description(GuiUtils.stringSplit(requester.getTranslation("challenges.navigation","[level]",name)))
.description(GuiUtils.stringSplit(
requester.getTranslation("challenges.navigation","[level]",name),
this.addon.getChallengesSettings().getLoreLineLength()))
.clickHandler((p, u, c, s) -> {
u.closeInventory();
u.performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + status.getLevel().getUniqueId());
Expand All @@ -198,7 +200,10 @@ private void addNavigation(PanelBuilder panelBuilder) {
PanelItem item = new PanelItemBuilder()
.icon(new ItemStack(Material.BOOK))
.name(name)
.description(GuiUtils.stringSplit(requester.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName)))
.description(GuiUtils.stringSplit(requester.getTranslation("challenges.to-complete",
"[challengesToDo]", String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""),
"[thisLevel]", previousLevelName),
this.addon.getChallengesSettings().getLoreLineLength()))
.build();
panelBuilder.item(item);
}
Expand Down Expand Up @@ -309,6 +314,7 @@ private List<String> addRewards(Challenge challenge, boolean complete, boolean a
}

private Collection<? extends String> splitTrans(User user, String string, String...strings) {
return GuiUtils.stringSplit(user.getTranslation(string, strings));
return GuiUtils.stringSplit(user.getTranslation(string, strings),
this.addon.getChallengesSettings().getLoreLineLength());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private PanelItem createMenuButton(MenuType menuType)
return null;
}

return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength()), glow, clickHandler, false);
}


Expand All @@ -297,6 +297,8 @@ private PanelItem createButton(Button button)
boolean glow;
PanelItem.ClickHandler clickHandler;

final int lineLength = this.addon.getChallengesSettings().getLoreLineLength();

switch (button)
{
case TYPE:
Expand Down Expand Up @@ -408,7 +410,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
description = Collections.emptyList();
icon = new ItemStack(Material.WRITTEN_BOOK);
clickHandler = (panel, user, clickType, slot) -> {
new StringListGUI(this.user, this.challenge.getDescription(), (status, value) -> {
new StringListGUI(this.user, this.challenge.getDescription(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setDescription(value);
Expand Down Expand Up @@ -644,7 +646,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
description = new ArrayList<>(this.challenge.getRequiredPermissions());
icon = new ItemStack(Material.REDSTONE_LAMP);
clickHandler = (panel, user, clickType, slot) -> {
new StringListGUI(this.user, this.challenge.getRequiredPermissions(), (status, value) -> {
new StringListGUI(this.user, this.challenge.getRequiredPermissions(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRequiredPermissions(new HashSet<>(value));
Expand All @@ -671,7 +673,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
description = values;
icon = new ItemStack(Material.CHEST);
clickHandler = (panel, user, clickType, slot) -> {
new ItemSwitchGUI(this.user, this.challenge.getRequiredItems(), (status, value) -> {
new ItemSwitchGUI(this.user, this.challenge.getRequiredItems(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRequiredItems(value);
Expand Down Expand Up @@ -765,7 +767,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
{
icon = new ItemStack(Material.BEACON);
clickHandler = (panel, user, clickType, slot) -> {
new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> {
new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRequiredIslandLevel(value);
Expand Down Expand Up @@ -886,7 +888,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
description = values;
icon = new ItemStack(Material.CHEST);
clickHandler = (panel, user, clickType, slot) -> {
new ItemSwitchGUI(this.user, this.challenge.getRewardItems(), (status, value) -> {
new ItemSwitchGUI(this.user, this.challenge.getRewardItems(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRewardItems(value);
Expand Down Expand Up @@ -962,7 +964,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
description = this.challenge.getRewardCommands();
icon = new ItemStack(Material.COMMAND_BLOCK);
clickHandler = (panel, user, clickType, slot) -> {
new StringListGUI(this.user, this.challenge.getRewardCommands(), (status, value) -> {
new StringListGUI(this.user, this.challenge.getRewardCommands(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRewardCommands(value);
Expand Down Expand Up @@ -1057,7 +1059,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
description = values;
icon = new ItemStack(Material.TRAPPED_CHEST);
clickHandler = (panel, user, clickType, slot) -> {
new ItemSwitchGUI(this.user, this.challenge.getRepeatItemReward(), (status, value) -> {
new ItemSwitchGUI(this.user, this.challenge.getRepeatItemReward(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRepeatItemReward(value);
Expand Down Expand Up @@ -1136,7 +1138,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
description = this.challenge.getRepeatRewardCommands();
icon = new ItemStack(Material.COMMAND_BLOCK);
clickHandler = (panel, user, clickType, slot) -> {
new StringListGUI(this.user, this.challenge.getRepeatRewardCommands(), (status, value) -> {
new StringListGUI(this.user, this.challenge.getRepeatRewardCommands(), lineLength, (status, value) -> {
if (status)
{
this.challenge.setRepeatRewardCommands(value);
Expand All @@ -1154,7 +1156,7 @@ else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)
return null;
}

return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description, lineLength), glow, clickHandler, false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private PanelItem createMenuButton(MenuType menuType)
return null;
}

return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength()), glow, clickHandler, false);
}


Expand All @@ -265,7 +265,9 @@ private PanelItem createChallengeIcon(Challenge challenge)
{
return new PanelItemBuilder().
name(challenge.getFriendlyName()).
description(GuiUtils.stringSplit(challenge.getDescription())).
description(GuiUtils.stringSplit(
challenge.getDescription(),
this.addon.getChallengesSettings().getLoreLineLength())).
icon(challenge.getIcon()).
clickHandler((panel, user1, clickType, slot) -> {
// Open challenges edit screen.
Expand Down Expand Up @@ -297,6 +299,8 @@ private PanelItem createButton(Button button)
boolean glow;
PanelItem.ClickHandler clickHandler;

final int lineLength = this.addon.getChallengesSettings().getLoreLineLength();

switch (button)
{
case NAME:
Expand Down Expand Up @@ -447,7 +451,7 @@ private PanelItem createButton(Button button)
description = values;
icon = new ItemStack(Material.CHEST);
clickHandler = (panel, user, clickType, slot) -> {
new ItemSwitchGUI(this.user, this.challengeLevel.getRewardItems(), (status, value) -> {
new ItemSwitchGUI(this.user, this.challengeLevel.getRewardItems(), lineLength, (status, value) -> {
if (status)
{
this.challengeLevel.setRewardItems(value);
Expand Down Expand Up @@ -523,7 +527,7 @@ private PanelItem createButton(Button button)
description = this.challengeLevel.getRewardCommands();
icon = new ItemStack(Material.COMMAND_BLOCK);
clickHandler = (panel, user, clickType, slot) -> {
new StringListGUI(this.user, this.challengeLevel.getRewardCommands(), (status, value) -> {
new StringListGUI(this.user, this.challengeLevel.getRewardCommands(), lineLength, (status, value) -> {
if (status)
{
this.challengeLevel.setRewardCommands(value);
Expand All @@ -550,7 +554,7 @@ private PanelItem createButton(Button button)
List<Challenge> challengeList = manager.getAllChallenges(this.world);
challengeList.removeAll(manager.getLevelChallenges(this.challengeLevel));

new SelectChallengeGUI(this.user, challengeList, (status, value) -> {
new SelectChallengeGUI(this.user, challengeList, lineLength, (status, value) -> {
if (status)
{
manager.addChallengeToLevel(value, this.challengeLevel);
Expand All @@ -572,7 +576,7 @@ private PanelItem createButton(Button button)
clickHandler = (panel, user, clickType, slot) -> {
ChallengesManager manager = this.addon.getChallengesManager();

new SelectChallengeGUI(this.user, manager.getLevelChallenges(this.challengeLevel), (status, value) -> {
new SelectChallengeGUI(this.user, manager.getLevelChallenges(this.challengeLevel), lineLength, (status, value) -> {
if (status)
{
manager.removeChallengeFromLevel(value, this.challengeLevel);
Expand All @@ -590,7 +594,7 @@ private PanelItem createButton(Button button)
return null;
}

return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false);
return new PanelItem(icon, name, GuiUtils.stringSplit(description, lineLength), glow, clickHandler, false);
}


Expand Down

0 comments on commit b2201ec

Please sign in to comment.