Added TranslateList and JSON parity

This commit is contained in:
Auxilor
2021-06-17 10:36:38 +01:00
parent b7d421e1a8
commit 6bfd5bd153
2 changed files with 28 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.willfp.eco.core.config.Config;
import com.willfp.eco.core.config.JSONConfig;
import com.willfp.eco.util.StringUtils;
import lombok.Getter;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
@@ -272,7 +273,7 @@ public abstract class JSONConfigWrapper implements JSONConfig, Cloneable {
@Override
@NotNull
public String getString(@NotNull final String path) {
return Objects.requireNonNullElse(getOfKnownType(path, String.class), "");
return StringUtils.translate(Objects.requireNonNullElse(getOfKnownType(path, String.class), ""));
}
@Override

View File

@@ -39,6 +39,32 @@ public class StringUtils {
.add(Pattern.compile("<#" + "([A-Fa-f0-9]{6})" + ">"))
.build();
/**
* Translate a list of strings - converts Placeholders and Color codes.
*
* @param list The messages to translate.
* @param player The player to translate placeholders with respect to.
* @return The message, translated.
*/
public List<String> translateList(@NotNull final List<String> list,
@Nullable final Player player) {
list.replaceAll(s -> translate(s, player));
return list;
}
/**
* Translate a list of strings - converts Placeholders and Color codes.
*
* @param list The messages to translate.
* @return The message, translated.
*/
public List<String> translateList(@NotNull final List<String> list) {
list.replaceAll(s -> translate(s, null));
return list;
}
/**
* Translate a string - converts Placeholders and Color codes.
*