From 563df838c55d57fa1668c06cf26604fc7e5626dc Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Fri, 11 Apr 2025 08:20:42 +0700 Subject: [PATCH] fix: add depth and reduce max time (not sure if depth will break things, pretty sure not) --- build-number.txt | 2 +- .../chomens_bot/util/ComponentUtilities.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/build-number.txt b/build-number.txt index 43e249ec..f9147d24 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -2611 \ No newline at end of file +2622 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java b/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java index 5af71695..c2856b72 100644 --- a/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java +++ b/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java @@ -63,7 +63,9 @@ public class ComponentUtilities { private static class ComponentParser { public static final Pattern ARG_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?([A-Za-z%]|$)"); - public static final long MAX_TIME = 100; // this is actually more than we need + public static final long MAX_TIME = 5; // Change Clock Time And Break Bot ! + + public static final int MAX_DEPTH = 256; public static final Map ANSI_MAP = new HashMap<>(); @@ -152,6 +154,8 @@ public class ComponentUtilities { private long parseStartTime = System.currentTimeMillis(); + private int depth = 0; + private String lastColor = ""; private String lastStyle = ""; @@ -187,7 +191,7 @@ public class ComponentUtilities { private String stringify (final Component message, final ParseType type) { this.type = type; - if (System.currentTimeMillis() > parseStartTime + MAX_TIME) return ""; + if (depth > MAX_DEPTH || System.currentTimeMillis() > parseStartTime + MAX_TIME) return ""; try { final StringBuilder builder = new StringBuilder(); @@ -204,6 +208,7 @@ public class ComponentUtilities { parser.lastColor = lastColor + color; parser.lastStyle = lastStyle + style; parser.parseStartTime = parseStartTime; + parser.depth = depth; parser.isSubParsing = true; builder.append(parser.stringify(child, type)); } @@ -475,11 +480,14 @@ public class ComponentUtilities { final StringBuilder sb, final Component message ) { + depth++; + final ComponentParser parser = new ComponentParser(); parser.lastColor = lastColor + color; parser.lastStyle = lastStyle + style; parser.parseStartTime = parseStartTime; + parser.depth = depth; parser.isSubParsing = true; final String orderedStyling = type == ParseType.SECTION_SIGNS