From a5a6f8fa219e79e71accc026f2a4a92c8cefa821 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 5 Apr 2024 13:10:00 +0100 Subject: [PATCH] refactor: reduce I/O on Discord hook postage --- .../net/william278/huskchat/discord/DiscordHook.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/net/william278/huskchat/discord/DiscordHook.java b/common/src/main/java/net/william278/huskchat/discord/DiscordHook.java index 953e61b..6595b4a 100644 --- a/common/src/main/java/net/william278/huskchat/discord/DiscordHook.java +++ b/common/src/main/java/net/william278/huskchat/discord/DiscordHook.java @@ -62,12 +62,17 @@ enum Format { EMBEDDED, INLINE; + private String format; + @NotNull private String getPostMessageFormat(@NotNull HuskChat plugin) { + if (this.format != null) { + return this.format; + } try { - return new String(plugin.getResource( - String.format("discord/%s_message.json", name().toLowerCase(Locale.ENGLISH)) - ).readAllBytes(), StandardCharsets.UTF_8); + return this.format = new String(plugin.getResource(String.format( + "discord/%s_message.json", name().toLowerCase(Locale.ENGLISH) + )).readAllBytes(), StandardCharsets.UTF_8); } catch (IOException e) { throw new IllegalStateException("Unable to load \"" + name() + "\" Discord message format", e); }