Added placeholders for team online member counts #2299

This commit is contained in:
tastybento 2024-02-18 14:36:42 -08:00
parent 5e4634400a
commit 83479ac8a4
1 changed files with 22 additions and 0 deletions

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("");
});
}
/**