Skip to content

Commit

Permalink
Allows the setPlaceholders method to specify if color codes should be…
Browse files Browse the repository at this point in the history
… translated in the output string
  • Loading branch information
extendedclip committed Jan 6, 2020
1 parent 6c964ba commit 2dbf69a
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/main/java/me/clip/placeholderapi/PlaceholderAPI.java
Expand Up @@ -217,12 +217,27 @@ public static String setPlaceholders(OfflinePlayer player, String text) {
* @return text with all placeholders set to the corresponding values
*/
public static String setPlaceholders(OfflinePlayer player, String text, Pattern placeholderPattern) {
return setPlaceholders(player, text, placeholderPattern, true);
}

/**
* set placeholders in the text specified placeholders are matched with the pattern
* %<(identifier)_(params)>% when set with this method
*
* @param player Player to parse the placeholders for
* @param text text to parse the placeholder values to
* @param placeholderPattern the pattern to match placeholders to. Capture group 1 must contain an
* @param colorize true/false if color codes should be translated within the output text
* underscore separating the identifier from the params
* @return text with all placeholders set to the corresponding values
*/
public static String setPlaceholders(OfflinePlayer player, String text, Pattern placeholderPattern, boolean colorize) {
if (text == null) {
return null;
}

if (placeholders.isEmpty()) {
return color(text);
return colorize ? color(text) : text;
}

Matcher m = placeholderPattern.matcher(text);
Expand All @@ -247,7 +262,7 @@ public static String setPlaceholders(OfflinePlayer player, String text, Pattern
}
}

return color(text);
return colorize ? color(text) : text;
}

/**
Expand Down Expand Up @@ -278,12 +293,26 @@ public static List<String> setRelationalPlaceholders(Player one, Player two, Lis
* @return text with all relational placeholders set to the corresponding values
*/
public static String setRelationalPlaceholders(Player one, Player two, String text) {
return setRelationalPlaceholders(one,two, text, true);
}

/**
* set relational placeholders in the text specified placeholders are matched with the pattern
* %<rel_(identifier)_(params)>% when set with this method
*
* @param one Player to compare
* @param two Player to compare
* @param text text to parse the placeholder values to
* @param colorize true/false if color codes should be translated within the output text
* @return text with all relational placeholders set to the corresponding values
*/
public static String setRelationalPlaceholders(Player one, Player two, String text, boolean colorize) {
if (text == null) {
return null;
}

if (placeholders.isEmpty()) {
return color(text);
return colorize ? color(text) : text;
}

Matcher m = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
Expand Down Expand Up @@ -314,7 +343,7 @@ public static String setRelationalPlaceholders(Player one, Player two, String te
}
}

return color(text);
return colorize ? color(text) : text;
}

/**
Expand Down Expand Up @@ -350,7 +379,7 @@ public static boolean registerExpansion(PlaceholderExpansion ex) {
if (ev.isCancelled()) {
return false;
}

return registerPlaceholderHook(ex.getIdentifier(), ex);
}

Expand Down

0 comments on commit 2dbf69a

Please sign in to comment.