Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placeholder counts #2300

Merged
merged 3 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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;
Expand Down Expand Up @@ -167,6 +169,26 @@ private void registerTeamMemberPlaceholders(@NonNull GameModeAddon addon) {
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("");
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void tearDown() {
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());
}

/**
Expand All @@ -91,6 +91,7 @@ public void testRegisterDefaultPlaceholdersSomePreregistered() {
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());
}
}
Loading