1
mirror of https://github.com/CarmJos/EasyPlugin.git synced 2024-09-19 19:25:45 +00:00

feat(color): 渐变色支持在其中添加额外格式代码

This commit is contained in:
Carm Jos 2023-09-05 04:26:39 +08:00
parent 19f25db0b7
commit 2efdc5f5a6
2 changed files with 18 additions and 4 deletions

View File

@ -162,9 +162,14 @@ public class ColorParser {
startColor.getBlue() + bStep * i * bDirection startColor.getBlue() + bStep * i * bDirection
)).toArray(String[]::new); )).toArray(String[]::new);
return IntStream.range(0, characters.length) StringBuilder sb = new StringBuilder();
.mapToObj(i -> colorText(characters[i], extraFormats.get(i), buildHexColor(hexes[i]))) String extra = null;
.collect(Collectors.joining()); for (int i = 0; i < characters.length; i++) {
extra = buildExtraFormat(extra, extraFormats.get(i));
String s = colorText(characters[i], extra, buildHexColor(hexes[i]));
sb.append(s);
}
return sb.toString();
} }
protected static String gradientText(@NotNull String text, @Nullable String startHex, @Nullable String endHex) { protected static String gradientText(@NotNull String text, @Nullable String startHex, @Nullable String endHex) {
@ -205,4 +210,13 @@ public class ColorParser {
.collect(Collectors.joining("", '§' + "x", "")); .collect(Collectors.joining("", '§' + "x", ""));
} }
protected static String buildExtraFormat(String current, String extra) {
if (extra != null) current = (current == null ? "" : current) + extra;
return isResetCode(current) ? null : current;
}
protected static boolean isResetCode(String input) {
return input != null && (input.toLowerCase().endsWith("&r") || input.toLowerCase().endsWith("§r"));
}
} }

View File

@ -15,7 +15,7 @@ public class ColorParseTest {
System.out.println(parseGradientColor("&<#AAAAAA>我真的&<#BBBBBB>爱死&<#111111>你&<#FFFFFF>")); System.out.println(parseGradientColor("&<#AAAAAA>我真的&<#BBBBBB>爱死&<#111111>你&<#FFFFFF>"));
// 测试穿插 // 测试穿插
System.out.println(parse("&<#AAAAAA>&l我&r真&b的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r")); System.out.println(parse("&<#AAAAAA>&l&m真的&o尊的&r真的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r"));
System.out.println(parse("&<#AAAAAA>&l我&r真&(#666666)的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r")); System.out.println(parse("&<#AAAAAA>&l我&r真&(#666666)的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r"));
System.out.println(parse("&r正常的颜色理应&c&l不受影响&r。")); System.out.println(parse("&r正常的颜色理应&c&l不受影响&r。"));