Unformat item lore and name when serializing items (#4095)

Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com>
This commit is contained in:
Josh Roy 2021-05-02 16:18:35 -04:00 committed by GitHub
parent 16627d10b6
commit 4976484d91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials.items;
import com.earth2me.essentials.IConf;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.MaterialUtil;
import com.earth2me.essentials.utils.VersionUtil;
import net.ess3.api.IEssentials;
@ -203,7 +204,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
if (is.hasItemMeta()) {
final ItemMeta meta = is.getItemMeta();
if (meta.hasDisplayName()) {
sb.append("name:").append(meta.getDisplayName().replaceAll(" ", "_")).append(" ");
sb.append("name:").append(FormatUtil.unformatString(meta.getDisplayName()).replace(" ", "_")).append(" ");
}
if (meta.hasLore()) {
@ -216,7 +217,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
sb.append("|");
}
first = false;
sb.append(s.replaceAll(" ", "_"));
sb.append(FormatUtil.unformatString(s).replace(" ", "_"));
}
sb.append(" ");
}

View File

@ -148,16 +148,27 @@ public final class FormatUtil {
return builder.toString();
}
public static String unformatString(final IUser user, final String permBase, String message) {
public static String unformatString(final String message) {
if (message == null) {
return null;
}
return unformatString(message, EnumSet.allOf(ChatColor.class), true);
}
public static String unformatString(final IUser user, final String permBase, final String message) {
if (message == null) {
return null;
}
return unformatString(message, getSupported(user, permBase), user.isAuthorized(permBase + ".rgb"));
}
public static String unformatString(String message, final EnumSet<ChatColor> supported, boolean rgb) {
if (message == null) {
return null;
}
final EnumSet<ChatColor> supported = getSupported(user, permBase);
// RGB Codes
final StringBuffer rgbBuilder = new StringBuffer();
final Matcher rgbMatcher = STRIP_RGB_PATTERN.matcher(message);
final boolean rgb = user.isAuthorized(permBase + ".rgb");
while (rgbMatcher.find()) {
final String code = rgbMatcher.group(1).replace(String.valueOf(ChatColor.COLOR_CHAR), "");
if (rgb) {