Skip to content

Commit 412a436

Browse files
committed
fix: Nick Hider might turn chat to ERROR if it fails
1 parent 9e9333c commit 412a436

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

  • src/main/java/net/apple70cents/chattools/features/general

src/main/java/net/apple70cents/chattools/features/general/NickHider.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@ public class NickHider {
1919
private static String nickname;
2020

2121
private static final CircuitBreakerExecutor executor = CircuitBreakerExecutor.of(() -> {
22+
Component original = text.copy();
2223
try {
23-
text = TextUtils.replaceComponentText(text.copy(), RegExUtils.getOrCompilePattern(Pattern.quote(playerName)), nickname);
24+
Component result = TextUtils.replaceComponentText(text.copy(),
25+
RegExUtils.getOrCompilePattern(Pattern.quote(playerName)), nickname);
26+
if (result != null && !"ERROR".equals(result.getString())) {
27+
text = result;
28+
} else {
29+
LoggerUtils.error("[ChatTools] ERROR was returned on nick-hiding this text: " + text + ", let's show it raw...");
30+
text = original;
31+
}
2432
} catch (Exception e) {
2533
LoggerUtils.error("[ChatTools] Error occurred on nick-hiding this text: " + text + ", let's show it raw...");
2634
e.printStackTrace();
35+
text = original;
2736
}
2837
}).setMaxLimitPerSecond(() -> ((Number) ConfigUtils.get("general.CircuitBreaker.NickHiderThreshold")).intValue())
2938
.setFailsafeFunction(() -> {

0 commit comments

Comments
 (0)