Merge pull request #2300 from BentoBoxWorld/2299_placeholder_counts

Placeholder counts
This commit is contained in:
tastybento 2024-02-18 14:44:42 -08:00 committed by GitHub
commit b43197d54f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 3 deletions

View File

@ -88,7 +88,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.0.1</build.version>
<build.version>2.1.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>

View File

@ -4,6 +4,8 @@ import java.util.Arrays;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
@ -167,6 +169,26 @@ public class PlaceholdersManager {
return "";
});
}
// Counts
// Number of online members
registerPlaceholder(addon, "island_online_members_count", user -> {
if (user == null)
return "";
Island island = plugin.getIslands().getIsland(addon.getOverWorld(), user);
return island != null
? String.valueOf(island.getMemberSet(RanksManager.MEMBER_RANK).stream()
.map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).count())
: "";
});
// Number of online members of visited island
registerPlaceholder(addon, "visited_island_online_members_count", user -> {
if (user == null)
return "";
return plugin.getIslands().getIslandAt(user.getLocation())
.map(island -> String.valueOf(island.getMemberSet(RanksManager.MEMBER_RANK).stream()
.map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).count()))
.orElse("");
});
}
/**

View File

@ -77,7 +77,7 @@ public class PlaceholdersManagerTest {
public void testRegisterGameModePlaceholdersAllDefaults() {
pm.registerDefaultPlaceholders(addon);
// + 300 because we register team member placeholders up to 50 members
verify(hook, times(GameModePlaceholder.values().length + 300)).registerPlaceholder(any(), anyString(), any());
verify(hook, times(GameModePlaceholder.values().length + 302)).registerPlaceholder(any(), anyString(), any());
}
/**
@ -91,6 +91,7 @@ public class PlaceholdersManagerTest {
pm.registerDefaultPlaceholders(addon);
// 3 less registrations for this addon
verify(hook, times(GameModePlaceholder.values().length - 3 + 300)).registerPlaceholder(any(), anyString(), any());
verify(hook, times(GameModePlaceholder.values().length - 3 + 302)).registerPlaceholder(any(), anyString(),
any());
}
}