diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index 080b479..ab73edf 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -117,7 +117,9 @@ public class ChallengesImportManager 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")) diff --git a/src/main/java/world/bentobox/challenges/Settings.java b/src/main/java/world/bentobox/challenges/Settings.java index 39c8248..143f246 100644 --- a/src/main/java/world/bentobox/challenges/Settings.java +++ b/src/main/java/world/bentobox/challenges/Settings.java @@ -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:") @@ -122,6 +133,16 @@ public class Settings implements DataObject } + /** + * This method returns the loreLineLength object. + * @return the loreLineLength object. + */ + public int getLoreLineLength() + { + return loreLineLength; + } + + @Override public void setUniqueId(String uniqueId) { @@ -181,4 +202,14 @@ public class Settings implements DataObject { 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; + } } diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java index c3d8f35..604bc32 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java @@ -132,7 +132,9 @@ public class ChallengesPanels { 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()); @@ -146,7 +148,11 @@ public class ChallengesPanels { 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); } @@ -236,6 +242,7 @@ public class ChallengesPanels { } private Collection 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()); } } diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index 3c51fd8..335b172 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -184,7 +184,9 @@ public class ChallengesPanels2 { 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()); @@ -198,7 +200,10 @@ public class ChallengesPanels2 { 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); } @@ -309,6 +314,7 @@ public class ChallengesPanels2 { } private Collection 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()); } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 812b58f..28cec3e 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -280,7 +280,7 @@ public class EditChallengeGUI extends CommonGUI 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); } @@ -297,6 +297,8 @@ public class EditChallengeGUI extends CommonGUI boolean glow; PanelItem.ClickHandler clickHandler; + final int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); + switch (button) { case TYPE: @@ -408,7 +410,7 @@ public class EditChallengeGUI extends CommonGUI 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); @@ -644,7 +646,7 @@ public class EditChallengeGUI extends CommonGUI 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)); @@ -671,7 +673,7 @@ public class EditChallengeGUI extends CommonGUI 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); @@ -765,7 +767,7 @@ public class EditChallengeGUI extends CommonGUI { 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); @@ -886,7 +888,7 @@ public class EditChallengeGUI extends CommonGUI 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); @@ -962,7 +964,7 @@ public class EditChallengeGUI extends CommonGUI 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); @@ -1057,7 +1059,7 @@ public class EditChallengeGUI extends CommonGUI 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); @@ -1136,7 +1138,7 @@ public class EditChallengeGUI extends CommonGUI 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); @@ -1154,7 +1156,7 @@ public class EditChallengeGUI extends CommonGUI 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); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 75c7159..a2300cc 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -252,7 +252,7 @@ public class EditLevelGUI extends CommonGUI 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); } @@ -265,7 +265,9 @@ public class EditLevelGUI extends CommonGUI { 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. @@ -297,6 +299,8 @@ public class EditLevelGUI extends CommonGUI boolean glow; PanelItem.ClickHandler clickHandler; + final int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); + switch (button) { case NAME: @@ -447,7 +451,7 @@ public class EditLevelGUI extends CommonGUI 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); @@ -523,7 +527,7 @@ public class EditLevelGUI extends CommonGUI 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); @@ -550,7 +554,7 @@ public class EditLevelGUI extends CommonGUI List 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); @@ -572,7 +576,7 @@ public class EditLevelGUI extends CommonGUI 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); @@ -590,7 +594,7 @@ public class EditLevelGUI extends CommonGUI 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); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java index 984e9ce..a3d548c 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java @@ -9,6 +9,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.NumberGUI; import world.bentobox.challenges.utils.GuiUtils; @@ -61,12 +62,13 @@ public class EditSettingsGUI extends CommonGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.settings-title")); + final int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); GuiUtils.fillBorder(panelBuilder); // resetChallenges panelBuilder.item(19, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.reset")). - description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.reset"))). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.reset"), lineLength)). icon(Material.LAVA_BUCKET). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setResetChallenges( @@ -80,7 +82,7 @@ public class EditSettingsGUI extends CommonGUI // broadcastMessages panelBuilder.item(20, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.broadcast")). - description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.broadcast"))). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.broadcast"), lineLength)). icon(Material.JUKEBOX). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setBroadcastMessages( @@ -94,7 +96,7 @@ public class EditSettingsGUI extends CommonGUI // removeCompleteOneTimeChallenges panelBuilder.item(21, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.remove-on-complete")). - description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.remove-on-complete"))). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.remove-on-complete"), lineLength)). icon(Material.MAGMA_BLOCK). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setRemoveCompleteOneTimeChallenges( @@ -108,7 +110,7 @@ public class EditSettingsGUI extends CommonGUI // addCompletedGlow panelBuilder.item(22, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.glow")). - description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.glow"))). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.glow"), lineLength)). icon(Material.GLOWSTONE). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setAddCompletedGlow( @@ -122,7 +124,7 @@ public class EditSettingsGUI extends CommonGUI // freeChallengesAtTheTop panelBuilder.item(23, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.free-challenges")). - description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.free-challenges"))). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.free-challenges"), lineLength)). icon(Material.FILLED_MAP). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setFreeChallengesFirst( @@ -133,6 +135,29 @@ public class EditSettingsGUI extends CommonGUI glow(this.addon.getChallengesSettings().isFreeChallengesFirst()). build()); + // Lore line length + panelBuilder.item(23, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.lore-length")). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.lore-length"), lineLength)). + icon(Material.ANVIL). + clickHandler((panel, user1, clickType, i) -> { + new NumberGUI(this.user, + this.addon.getChallengesSettings().getLoreLineLength(), + 0, + (status, value) -> { + if (status) + { + this.addon.getChallengesSettings().setLoreLineLength(value); + } + + this.build(); + }); + + return true; + }). + glow(this.addon.getChallengesSettings().isFreeChallengesFirst()). + build()); + // Return Button panelBuilder.item(44, this.returnButton); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index 8e0bd0d..c669302 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -134,7 +134,8 @@ public class ListChallengesGUI extends CommonGUI { PanelItemBuilder itemBuilder = new PanelItemBuilder(). name(challenge.getFriendlyName()). - description(GuiUtils.stringSplit(challenge.getDescription())). + description(GuiUtils.stringSplit(challenge.getDescription(), + this.addon.getChallengesSettings().getLoreLineLength())). icon(challenge.getIcon()). glow(challenge.isDeployed()); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index b340dc5..8ef9430 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -134,7 +134,8 @@ public class ListLevelsGUI extends CommonGUI { PanelItemBuilder itemBuilder = new PanelItemBuilder(). name(challengeLevel.getFriendlyName()). - description(GuiUtils.stringSplit(challengeLevel.getUnlockMessage())). + description(GuiUtils.stringSplit(challengeLevel.getUnlockMessage(), + this.addon.getChallengesSettings().getLoreLineLength())). icon(challengeLevel.getIcon()). glow(false); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index 153958f..bbd5a3d 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -170,6 +170,8 @@ public class ListUsersGUI extends CommonGUI */ private PanelItem createPlayerIcon(Player player) { + int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); + if (this.addon.getIslands().hasIsland(this.world, player.getUniqueId())) { return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler( @@ -179,7 +181,7 @@ public class ListUsersGUI extends CommonGUI switch (this.operationMode) { case COMPLETE: - new SelectChallengeGUI(this.user, manager.getAllChallenges(this.world), (status, value) -> { + new SelectChallengeGUI(this.user, manager.getAllChallenges(this.world), lineLength, (status, value) -> { if (status) { manager.setChallengeComplete(User.getInstance(player), value); @@ -191,7 +193,7 @@ public class ListUsersGUI extends CommonGUI }); break; case RESET: - new SelectChallengeGUI(this.user, manager.getAllChallenges(this.world), (status, value) -> { + new SelectChallengeGUI(this.user, manager.getAllChallenges(this.world), lineLength, (status, value) -> { if (status) { manager.resetChallenge(User.getInstance(player), value); @@ -222,7 +224,7 @@ public class ListUsersGUI extends CommonGUI return new PanelItemBuilder(). name(player.getName()). icon(Material.BARRIER). - description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"))). + description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"), lineLength)). clickHandler((panel, user1, clickType, slot) -> false). build(); } @@ -273,7 +275,7 @@ public class ListUsersGUI extends CommonGUI name(this.user.getTranslation("challenges.gui.admin.buttons.toggle-users", "[value]", this.user.getTranslation("challenges.gui.admin.descriptions." + ViewMode.values()[this.modeIndex].name().toLowerCase()))). - description(GuiUtils.stringSplit(values)). + description(GuiUtils.stringSplit(values, this.addon.getChallengesSettings().getLoreLineLength())). icon(Material.STONE_BUTTON). clickHandler( (panel, user1, clickType, slot) -> { diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index bca04af..2e4474e 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -343,7 +343,8 @@ public class ChallengesGUI extends CommonGUI return new PanelItemBuilder(). icon(challenge.getIcon()). name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()). - description(GuiUtils.stringSplit(this.createChallengeDescription(challenge))). + description(GuiUtils.stringSplit(this.createChallengeDescription(challenge), + this.addon.getChallengesSettings().getLoreLineLength())). clickHandler((panel, user1, clickType, slot) -> { if (TryToComplete.complete(this.addon, this.user, @@ -523,7 +524,9 @@ public class ChallengesGUI extends CommonGUI if (level.isUnlocked()) { icon = level.getLevel().getIcon(); - description = GuiUtils.stringSplit(this.user.getTranslation("challenges.navigation", "[level]", name)); + description = GuiUtils.stringSplit( + this.user.getTranslation("challenges.navigation", "[level]", name), + this.addon.getChallengesSettings().getLoreLineLength()); clickHandler = (panel, user1, clickType, slot) -> { this.lastSelectedLevel = level; @@ -543,7 +546,8 @@ public class ChallengesGUI extends CommonGUI description = GuiUtils.stringSplit( this.user.getTranslation("challenges.to-complete", "[challengesToDo]", Integer.toString(level.getNumberOfChallengesStillToDo()), - "[thisLevel]", level.getPreviousLevel().getFriendlyName())); + "[thisLevel]", level.getPreviousLevel().getFriendlyName()), + this.addon.getChallengesSettings().getLoreLineLength()); clickHandler = null; glow = false; diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java index 2d44739..7fc7c9e 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java @@ -22,11 +22,12 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class ItemSwitchGUI { - public ItemSwitchGUI(User user, List itemStacks, BiConsumer> consumer) + public ItemSwitchGUI(User user, List itemStacks, int lineLength, BiConsumer> consumer) { this.consumer = consumer; this.user = user; this.itemStacks = itemStacks; + this.lineLength = lineLength; this.build(); } @@ -124,7 +125,7 @@ public class ItemSwitchGUI return null; } - return new PanelItem(icon, name, GuiUtils.stringSplit(description), false, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description, this.lineLength), false, clickHandler, false); } @@ -233,4 +234,9 @@ public class ItemSwitchGUI * Consumer that returns item stacks on save action. */ private BiConsumer> consumer; + + /** + * This variable stores how large line can be, before warp it. + */ + private int lineLength; } diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java index 6eb0376..1ef760a 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -21,19 +21,19 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class NumberGUI { - public NumberGUI(User user, int value, BiConsumer consumer) + public NumberGUI(User user, int value, int lineLength, BiConsumer consumer) { - this(user, value, Integer.MIN_VALUE, Integer.MAX_VALUE, consumer); + this(user, value, Integer.MIN_VALUE, Integer.MAX_VALUE, lineLength, consumer); } - public NumberGUI(User user, int value, int minValue, BiConsumer consumer) + public NumberGUI(User user, int value, int minValue, int lineLength, BiConsumer consumer) { - this(user, value, minValue, Integer.MAX_VALUE, consumer); + this(user, value, minValue, Integer.MAX_VALUE, lineLength, consumer); } - public NumberGUI(User user, int value, int minValue, int maxValue, BiConsumer consumer) + public NumberGUI(User user, int value, int minValue, int maxValue, int lineLength, BiConsumer consumer) { this.user = user; this.value = value; @@ -44,6 +44,8 @@ public class NumberGUI this.currentOperation = Button.SET; + this.lineLength = lineLength; + this.build(); } @@ -238,7 +240,7 @@ public class NumberGUI return null; } - return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description, this.lineLength), glow, clickHandler, false); } @@ -417,4 +419,9 @@ public class NumberGUI * This variable holds which operation now is processed. */ private Button currentOperation; + + /** + * This variable stores how large line can be, before warp it. + */ + private int lineLength; } diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java index ab6bdab..94da443 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java @@ -18,11 +18,12 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class SelectChallengeGUI { - public SelectChallengeGUI(User user, List challengesList, BiConsumer consumer) + public SelectChallengeGUI(User user, List challengesList, int lineLength, BiConsumer consumer) { this.consumer = consumer; this.user = user; this.challengesList = challengesList; + this.lineLength = lineLength; this.build(0); } @@ -127,7 +128,7 @@ public class SelectChallengeGUI { return new PanelItemBuilder(). name(challenge.getFriendlyName()). - description(GuiUtils.stringSplit(challenge.getDescription())). + description(GuiUtils.stringSplit(challenge.getDescription(), this.lineLength)). icon(challenge.getIcon()). clickHandler((panel, user1, clickType, slot) -> { this.consumer.accept(true, challenge); @@ -155,4 +156,9 @@ public class SelectChallengeGUI * Current value. */ private List challengesList; + + /** + * This variable stores how large line can be, before warp it. + */ + private int lineLength; } diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java index 964d531..3ea4358 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -24,17 +24,18 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class StringListGUI { - public StringListGUI(User user, Collection value, BiConsumer> consumer) + public StringListGUI(User user, Collection value, int lineLength, BiConsumer> consumer) { - this(user, new ArrayList<>(value), consumer); + this(user, new ArrayList<>(value), lineLength, consumer); } - public StringListGUI(User user, List value, BiConsumer> consumer) + public StringListGUI(User user, List value, int lineLength, BiConsumer> consumer) { this.consumer = consumer; this.user = user; this.value = value; + this.lineLength = lineLength; if (this.value.size() > 21) { @@ -177,7 +178,7 @@ public class StringListGUI return null; } - return new PanelItem(icon, name, GuiUtils.stringSplit(description), false, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description, this.lineLength), false, clickHandler, false); } @@ -243,4 +244,9 @@ public class StringListGUI * Current value. */ private List value; + + /** + * This variable stores how large line can be, before warp it. + */ + private int lineLength; } diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index 89ad053..80c02f1 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -370,9 +370,10 @@ public class GuiUtils * Simple splitter * * @param string - string to be split + * @param warpLength - whn warp should be affected. * @return list of split strings */ - public static List stringSplit(String string) + public static List stringSplit(String string, int warpLength) { // Remove all ending lines from string. string = string.replaceAll("([\\r\\n])", "\\|"); @@ -381,7 +382,7 @@ public class GuiUtils List result = new ArrayList<>(); Arrays.stream(string.split("\\|")). - map(line -> Arrays.asList(WordUtils.wrap(line, 25).split(System.getProperty("line.separator")))). + map(line -> Arrays.asList(WordUtils.wrap(line, warpLength).split(System.getProperty("line.separator")))). forEach(result::addAll); return result; @@ -391,9 +392,10 @@ public class GuiUtils /** * Simple splitter for all strings in list. * @param stringList - list of string to be split + * @param warpLength - whn warp should be affected. * @return list of split strings */ - public static List stringSplit(List stringList) + public static List stringSplit(List stringList, int warpLength) { if (stringList.isEmpty()) { @@ -401,7 +403,7 @@ public class GuiUtils } List newList = new ArrayList<>(stringList.size()); - stringList.stream().map(GuiUtils::stringSplit).forEach(newList::addAll); + stringList.stream().map(string -> GuiUtils.stringSplit(string, warpLength)).forEach(newList::addAll); return newList; } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c1a030c..293d255 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -7,20 +7,24 @@ # 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 # challenges by doing them repeatedly. -resetChallenges: true +reset-challenges: true # # Broadcast 1st time challenge completion messages to all players. # Change to false if the spam becomes too much. -broadcastMessages: true +broadcast-messages: true # # Remove non-repeatable challenges from the challenge GUI when complete. -removeCompleteOneTimeChallenges: false +remove-complete-one-time-challenges: false # # Add enchanted glow to completed challenges -addCompletedGlow: true +add-completed-glow: true # # This indicate if free challenges must be at the start (true) or at the end (false) of list. -freeChallengesFirst: false +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 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: