From da7c775ed38a84c6afa69a4cfd65c9af3b68279c Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:09:43 +0700 Subject: [PATCH] sex --- .../chomens_bot/util/ComponentUtilities.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ComponentUtilities.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ComponentUtilities.java index bb6b85b..a286e8a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ComponentUtilities.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/util/ComponentUtilities.java @@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.util; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import land.chipmunk.chayapak.chomens_bot.Main; import net.kyori.adventure.text.*; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.Style; @@ -14,6 +15,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -36,6 +38,16 @@ public class ComponentUtilities { public static final Map motdCache = new HashMap<>(); public static final Map ansiCache = new HashMap<>(); + static { + Main.executor.scheduleAtFixedRate(() -> { + final int maxSize = 1024; + + if (stringCache.size() > maxSize) stringCache.clear(); + else if (motdCache.size() > maxSize) motdCache.clear(); + else if (ansiCache.size() > maxSize) ansiCache.clear(); + }, 0, 1, TimeUnit.SECONDS); + } + public static final Map ansiMap = new HashMap<>(); static { // map totallynotskidded™ from https://github.com/PrismarineJS/prismarine-chat/blob/master/index.js#L10