From af49ddf5feb7e1886c0a4aeaa011dadec57aa232 Mon Sep 17 00:00:00 2001 From: Derek Chen Date: Sat, 17 May 2025 13:56:22 -0500 Subject: [PATCH] feat: make placeholder use same math logic as playerprofile stats command --- .../thebusybiscuit/slimefun4/api/player/PlayerProfile.java | 2 +- .../slimefun4/integrations/PlaceholderAPIIntegration.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 8dfc7414f8..5c430521ab 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -280,7 +280,7 @@ public final void markDirty() { return Optional.empty(); } - private int countNonEmptyResearches(@Nonnull Collection researches) { + public int countNonEmptyResearches(@Nonnull Collection researches) { int count = 0; for (Research research : researches) { if (research.hasEnabledItems()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java index 826fb1e4b5..1ec0497d63 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/PlaceholderAPIIntegration.java @@ -106,8 +106,9 @@ public String onRequest(@Nullable OfflinePlayer p, @Nonnull String params) { Optional profile = PlayerProfile.find(p); if (profile.isPresent()) { - Set set = profile.get().getResearches(); - return String.valueOf(Math.round(((set.size() * 100.0F) / Slimefun.getRegistry().getResearches().size()) * 100.0F) / 100.0F); + int unlockedResearches = profile.get().countNonEmptyResearches(profile.get().getResearches()); + int allResearches = profile.get().countNonEmptyResearches(Slimefun.getRegistry().getResearches()); + return String.valueOf(Math.round(((unlockedResearches * 100.0F) / allResearches) * 100.0F) / 100.0F); } else if (p instanceof Player player) { return getProfilePlaceholder(player); }