From cebb27c1b56b83a47cfdbb8a2ddfee420d7f94ef Mon Sep 17 00:00:00 2001 From: Crazy Date: Mon, 8 Jan 2024 15:00:22 +0100 Subject: [PATCH] Possible Fix for review --- .../net/crazy/badges/core/AddonConfiguration.java | 4 ++++ .../main/java/net/crazy/badges/core/Badges.java | 15 +++++++++++++++ .../java/net/crazy/badges/core/tags/BadgeTag.java | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/net/crazy/badges/core/AddonConfiguration.java b/core/src/main/java/net/crazy/badges/core/AddonConfiguration.java index 926646c..61f6142 100644 --- a/core/src/main/java/net/crazy/badges/core/AddonConfiguration.java +++ b/core/src/main/java/net/crazy/badges/core/AddonConfiguration.java @@ -50,4 +50,8 @@ public boolean compact() { public boolean showOwn() { return this.showOwn.get(); } + + public ConfigProperty getCompactBadges() { + return this.compactBadges; + } } diff --git a/core/src/main/java/net/crazy/badges/core/Badges.java b/core/src/main/java/net/crazy/badges/core/Badges.java index 8ce565b..eb54b52 100644 --- a/core/src/main/java/net/crazy/badges/core/Badges.java +++ b/core/src/main/java/net/crazy/badges/core/Badges.java @@ -44,6 +44,21 @@ protected void enable() { configuration().size() )); + addon.configuration().getCompactBadges().addChangeListener((state) -> { + if (state) { + // Don't purge "cache" when enabling compact mode as this doesn't cause any issues + return; + } + + /** + * Purge "Cache" + * Meaning: Clear the playerCache as due to the #removeIf inside BadgeTag the badges list get's updated + * This should not really be a performance bottleneck as it's just resets everything back to the beginning + * and when a player is rendered, their correct badges are loaded from the normal badges cache + */ + playerCache.clear(); + }); + this.logger().info("[Badges] Addon enabled."); } diff --git a/core/src/main/java/net/crazy/badges/core/tags/BadgeTag.java b/core/src/main/java/net/crazy/badges/core/tags/BadgeTag.java index 79c19dd..7b761e4 100644 --- a/core/src/main/java/net/crazy/badges/core/tags/BadgeTag.java +++ b/core/src/main/java/net/crazy/badges/core/tags/BadgeTag.java @@ -37,7 +37,7 @@ public void render(Stack stack, Entity livingEntity) { return; } - LinkedList badges = new LinkedList<>(addon.playerCache.get(player.getUniqueId())); + LinkedList badges = addon.playerCache.get(player.getUniqueId()); if (badges.isEmpty()) { return;