From abfbe8044bd7e4b73ce1ae26c253e3d08a12aeaf Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 14 Aug 2023 08:13:18 +0700 Subject: [PATCH] yeah --- .../chomens_bot/commands/MusicCommand.java | 2 +- .../chomens_bot/util/ComponentUtilities.java | 29 ------------------- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java index c601063..9f253c8 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java @@ -63,7 +63,7 @@ public class MusicCommand extends Command { ratelimit++; - if (ratelimit > 15) return null; + if (ratelimit > 10) return null; root = MusicPlayerPlugin.SONG_DIR; return switch (args[0]) { 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 a286e8a..326f9e8 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,7 +3,6 @@ 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; @@ -15,7 +14,6 @@ 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; @@ -33,21 +31,6 @@ public class ComponentUtilities { public static final Pattern ARG_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?([s%])"); - // is having each map for each type a great idea? - public static final Map stringCache = new HashMap<>(); - 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 @@ -109,8 +92,6 @@ public class ComponentUtilities { public static String stringify (Component message) { return stringify(message, null); } private static String stringify (Component message, String lastColor) { try { - if (stringCache.containsKey(message)) return stringCache.get(message); - final StringBuilder builder = new StringBuilder(); final PartiallyStringified output = stringifyPartially(message, false, false, lastColor); @@ -119,8 +100,6 @@ public class ComponentUtilities { for (Component child : message.children()) builder.append(stringify(child, output.lastColor)); - stringCache.put(message, builder.toString()); - return builder.toString(); } catch (Exception e) { return ""; @@ -130,8 +109,6 @@ public class ComponentUtilities { public static String stringifyMotd (Component message) { return stringifyMotd(message, null); } private static String stringifyMotd (Component message, String lastColor) { try { - if (motdCache.containsKey(message)) return motdCache.get(message); - final StringBuilder builder = new StringBuilder(); final PartiallyStringified output = stringifyPartially(message, true, false, lastColor); @@ -140,8 +117,6 @@ public class ComponentUtilities { for (Component child : message.children()) builder.append(stringifyMotd(child, output.lastColor)); - motdCache.put(message, builder.toString()); - return builder.toString(); } catch (Exception e) { return ""; @@ -151,8 +126,6 @@ public class ComponentUtilities { public static String stringifyAnsi (Component message) { return stringifyAnsi(message, null); } private static String stringifyAnsi (Component message, String lastColor) { try { - if (ansiCache.containsKey(message)) return ansiCache.get(message); - final StringBuilder builder = new StringBuilder(); final PartiallyStringified output = stringifyPartially(message, false, true, lastColor); @@ -161,8 +134,6 @@ public class ComponentUtilities { for (Component child : message.children()) builder.append(stringifyAnsi(child, output.lastColor)); - ansiCache.put(message, builder.toString()); - return builder.toString(); } catch (Exception e) { return "";