Skip to content

Commit e96334a

Browse files
committed
Resolve the performance issue of adventure processor.
1 parent 49d74f5 commit e96334a

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.eternalcode.commons.adventure;
2+
3+
import java.util.function.Consumer;
4+
import java.util.function.UnaryOperator;
5+
import java.util.regex.Pattern;
6+
import net.kyori.adventure.text.Component;
7+
import net.kyori.adventure.text.TextReplacementConfig;
8+
import net.kyori.adventure.text.TextReplacementConfig.Builder;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
public class AdventureLegacyColorPostProcessor implements UnaryOperator<Component> {
12+
13+
private static final TextReplacementConfig LEGACY_REPLACEMENT_CONFIG = TextReplacementConfig.builder()
14+
.match(Pattern.compile(".*"))
15+
.replacement((matchResult, build) -> AdventureUtil.component(matchResult.group()))
16+
.build();
17+
18+
@Override
19+
public Component apply(Component component) {
20+
return component.replaceText(LEGACY_REPLACEMENT_CONFIG);
21+
}
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.eternalcode.commons.adventure;
2+
3+
import java.util.function.UnaryOperator;
4+
import java.util.regex.Pattern;
5+
import net.kyori.adventure.text.Component;
6+
import net.kyori.adventure.text.TextReplacementConfig;
7+
8+
public class AdventureLegacyColorPreProcessor implements UnaryOperator<String> {
9+
10+
@Override
11+
public String apply(String component) {
12+
return component.replace("§", "&");
13+
}
14+
15+
}

eternalcode-commons-adventure/src/main/java/com/eternalcode/commons/adventure/AdventureLegacyColorProcessor.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)