Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lore-length readded + Ability to set some GUI default colors #340

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ local.properties
checkstyle.xml
classes/
/.DS_Store

#Netbeans
nbactions.xml
27 changes: 27 additions & 0 deletions src/main/java/world/bentobox/challenges/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public class Settings implements ConfigObject
private VisibilityMode visibilityMode = VisibilityMode.VISIBLE;


@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. Set it to -1 to disable it.")
@ConfigEntry(path = "gui-settings.lore-length")
private int loreLength = 25;

@ConfigComment("")
@ConfigComment("This allows to change default locked level icon. This option may be")
@ConfigComment("overwritten by each challenge level. If challenge level has specified")
Expand Down Expand Up @@ -384,6 +390,17 @@ public VisibilityMode getVisibilityMode()
{
return this.visibilityMode;
}



/**
* This method returns the loreLength value.
* @return the value of loreLength.
*/
public int getLoreLength()
{
return this.loreLength;
}


// ---------------------------------------------------------------------
Expand Down Expand Up @@ -603,6 +620,16 @@ public void setVisibilityMode(VisibilityMode visibilityMode)
{
this.visibilityMode = visibilityMode;
}

/**
* This method sets the loreLength value.
* @param loreLength the loreLength new value.
*
*/
public void setLoreLength(int loreLength)
{
this.loreLength = loreLength;
}


/**
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/world/bentobox/challenges/panel/CommonPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;

import org.bukkit.Material;
import org.bukkit.World;
Expand Down Expand Up @@ -131,13 +132,20 @@ protected List<String> generateChallengeDescription(Challenge challenge, @Nullab
final String reference = Constants.DESCRIPTIONS + "challenge.";

// Get description from custom translations
String description = this.user
.getTranslationOrNothing("challenges.challenges." + challenge.getUniqueId() + ".description");
String description = this.user.getTranslationOrNothing("challenges.challenges." + challenge.getUniqueId() + ".description");

if (description.isEmpty()) {
// Get data from object in single string.
description = Util.translateColorCodes(String.join("\n", challenge.getDescription()));
}

String descriptionColor = this.user.getTranslationOrNothing(reference + "description.color");

description = descriptionColor + description;

if (this.addon.getChallengesSettings().getLoreLength() > -1 ) {
description = Utils.stringSplit(description, this.addon.getChallengesSettings().getLoreLength());
}

// Non-memory optimal code used for easier debugging and nicer code layout for
// my eye :)
Expand Down Expand Up @@ -586,12 +594,20 @@ private String generateRepeatReward(Challenge challenge) {
}

String rewardText = this.user
.getTranslationOrNothing("challenges.challenges." + challenge.getUniqueId() + ".repeat-reward-text");
.getTranslationOrNothing("challenges.challenges." + challenge.getUniqueId() + ".repeat-reward-text");

if (rewardText.isEmpty()) {
rewardText = Util.translateColorCodes(String.join("\n", challenge.getRepeatRewardText()));
}


String rewardTextColor = this.user.getTranslationOrNothing(reference + "text-color");

rewardText = rewardTextColor + rewardText;

if (this.addon.getChallengesSettings().getLoreLength() > -1 ) {
rewardText = Utils.stringSplit(rewardText, this.addon.getChallengesSettings().getLoreLength());
}

return this.user.getTranslationOrNothing(reference + "lore", "[text]", rewardText, "[items]", items,
"[experience]", experience, "[money]", money, "[commands]", commands);
}
Expand Down Expand Up @@ -670,6 +686,14 @@ private String generateReward(Challenge challenge) {
if (rewardText.isEmpty()) {
rewardText = Util.translateColorCodes(String.join("\n", challenge.getRewardText()));
}

String rewardTextColor = this.user.getTranslationOrNothing(reference + "text-color");

rewardText = rewardTextColor + rewardText;

if (this.addon.getChallengesSettings().getLoreLength() > -1 ) {
rewardText = Utils.stringSplit(rewardText, this.addon.getChallengesSettings().getLoreLength());
}

return this.user.getTranslationOrNothing(reference + "lore", "[text]", rewardText, "[items]", items,
"[experience]", experience, "[money]", money, "[commands]", commands);
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/world/bentobox/challenges/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.commons.lang3.text.WordUtils;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -922,4 +924,37 @@ public static String parseDuration(Duration duration, User user)

return returnString;
}

/**
* This method splits a string in lines with a maximum length
*
* @param maxLength that each line can be.
* @return a list of the splitted lines.
*/
public static List<String> stringSplitList(String string, int maxLength) {
// Remove all ending lines from string.
string = string.replaceAll("([\\r\\n])", "\\|");
string = ChatColor.translateAlternateColorCodes('&', string);
// Check length of lines
List<String> result = new ArrayList<>();

Arrays.stream(string.split("\\|")).
map(line -> Arrays.asList(WordUtils.wrap(line, maxLength).split(System.getProperty("line.separator")))).
forEach(result::addAll);

// Fix colors, as splitting my lost that information.
for (int i = 0, resultSize = result.size(); i < resultSize; i++) {
if (i > 0) {
String lastColor = ChatColor.getLastColors(result.get(i - 1));
result.set(i, lastColor + result.get(i));
}
}

return result;
}

public static String stringSplit(String string, int maxLength) {
List<String> splitted = stringSplitList(string, maxLength);
return String.join("\n", splitted);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ gui-settings:
==: org.bukkit.inventory.ItemStack
v: 2730
type: BARRIER
#
# This allows to change lore description line length. By default it is 25, but some server
# owners may like it to be larger. Set it to -1 to disable it.
lore-length: 25
#
# This indicate if challenges data will be stored per island (true) or per player (false).
store-island-data: true
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,9 @@ challenges:
[cooldown]
[requirements]
[rewards]
description:
# Formatting applied to description text ([description])
color: '&b'
# Contains a text generated inside [status] lore
status:
# Status message for completed unrepeatable challenge
Expand Down Expand Up @@ -988,6 +991,8 @@ challenges:
[experience]
[money]
[commands]
# Formatting applied to reward text ([text])
text-color: '&b'
# Title that will be used if there are list of items for rewards
item-title: "&7 Items:"
# Listing of an item that are rewards multiple times.
Expand Down