Merge branch '2.x' into fix-5054

This commit is contained in:
pop4959 2024-02-26 03:39:27 -08:00 committed by GitHub
commit e847640723
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 37 deletions

View File

@ -34,6 +34,12 @@ jobs:
chmod +x gradlew
./gradlew build --stacktrace
- name: Publish JUnit report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # Run even if the previous step fails
with:
report_paths: '**/build/test-results/test*/TEST-*.xml'
- name: Archive plugin jars on GitHub
uses: actions/upload-artifact@v4
with:

View File

@ -36,6 +36,12 @@ jobs:
chmod +x gradlew
./gradlew build --stacktrace
- name: Publish JUnit report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # Run even if the previous step fails
with:
report_paths: '**/build/test-results/test*/TEST-*.xml'
- name: Archive plugin jars on GitHub
uses: actions/upload-artifact@v4
with:

View File

@ -182,8 +182,10 @@ public class I18n implements net.ess3.api.II18n {
}
final Object[] processedArgs = mutateArgs(objects, arg -> {
final String str = arg instanceof AdventureUtil.ParsedPlaceholder ? arg.toString() : AdventureUtil.miniMessage().escapeTags(arg.toString());
return AdventureUtil.legacyToMini(str);
if (arg instanceof AdventureUtil.ParsedPlaceholder) {
return arg.toString();
}
return AdventureUtil.legacyToMini(AdventureUtil.miniMessage().escapeTags(arg.toString()));
});
return messageFormat.format(processedArgs).replace(' ', ' '); // replace nbsp with a space

View File

@ -8,18 +8,12 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.ChatColor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class AdventureUtil {
private static final LegacyComponentSerializer LEGACY_SERIALIZER;
private static final Pattern NAMED_PATTERN = Pattern.compile(ChatColor.COLOR_CHAR + "[0-9a-fk-orA-FK-OR]");
private static final Pattern HEX_PATTERN = Pattern.compile(ChatColor.COLOR_CHAR + "x((?:" + ChatColor.COLOR_CHAR + "[0-9a-fA-F]){6})");
private static final MiniMessage MINI_MESSAGE_NO_TAGS;
private static final String LOOKUP = "0123456789abcdefklmnor";
private static final String[] MINI_TAGS = new String[] {"black", "dark_blue", "dark_green", "dark_aqua", "dark_red", "dark_purple", "gold", "gray", "dark_gray", "blue", "green", "aqua", "red", "light_purple", "yellow", "white", "obf", "b", "st", "u", "i", "reset"};
private static final NamedTextColor[] COLORS = new NamedTextColor[] {NamedTextColor.BLACK, NamedTextColor.DARK_BLUE, NamedTextColor.DARK_GREEN, NamedTextColor.DARK_AQUA, NamedTextColor.DARK_RED, NamedTextColor.DARK_PURPLE, NamedTextColor.GOLD, NamedTextColor.GRAY, NamedTextColor.DARK_GRAY, NamedTextColor.BLUE, NamedTextColor.GREEN, NamedTextColor.AQUA, NamedTextColor.RED, NamedTextColor.LIGHT_PURPLE, NamedTextColor.YELLOW, NamedTextColor.WHITE};
private static final NamedTextColor[] COLORS = new NamedTextColor[]{NamedTextColor.BLACK, NamedTextColor.DARK_BLUE, NamedTextColor.DARK_GREEN, NamedTextColor.DARK_AQUA, NamedTextColor.DARK_RED, NamedTextColor.DARK_PURPLE, NamedTextColor.GOLD, NamedTextColor.GRAY, NamedTextColor.DARK_GRAY, NamedTextColor.BLUE, NamedTextColor.GREEN, NamedTextColor.AQUA, NamedTextColor.RED, NamedTextColor.LIGHT_PURPLE, NamedTextColor.YELLOW, NamedTextColor.WHITE};
private static IEssentials ess;
private static MiniMessage miniMessageInstance;
@ -29,6 +23,9 @@ public final class AdventureUtil {
builder.hexColors();
}
LEGACY_SERIALIZER = builder.build();
MINI_MESSAGE_NO_TAGS = MiniMessage.miniMessage();
miniMessageInstance = createMiniMessageInstance();
}
@ -84,37 +81,16 @@ public final class AdventureUtil {
/**
* Converts a section sign legacy string to a MiniMessage string.
*
* @param useCustomTags true if gold and red colors should use primary and secondary tags instead.
*/
public static String legacyToMini(String text, boolean useCustomTags) {
StringBuffer buffer = new StringBuffer();
Matcher matcher = HEX_PATTERN.matcher(text);
while (matcher.find()) {
final String code = matcher.group(1).replace(String.valueOf(ChatColor.COLOR_CHAR), "");
matcher.appendReplacement(buffer, "<#" + code + ">");
final Component deserializedText = LEGACY_SERIALIZER.deserialize(text);
if (useCustomTags) {
return miniMessageInstance.serialize(deserializedText);
} else {
return MINI_MESSAGE_NO_TAGS.serialize(deserializedText);
}
matcher.appendTail(buffer);
matcher = NAMED_PATTERN.matcher(buffer.toString());
buffer = new StringBuffer();
while (matcher.find()) {
final int format = LOOKUP.indexOf(Character.toLowerCase(matcher.group().charAt(1)));
if (format != -1) {
String tagName = MINI_TAGS[format];
if (useCustomTags) {
if (tagName.equals("gold")) {
tagName = "primary";
} else if (tagName.equals("red")) {
tagName = "secondary";
}
}
matcher.appendReplacement(buffer, "<" + tagName + ">");
}
}
matcher.appendTail(buffer);
return buffer.toString();
}
/**