From 1b29f7f6ac187060db4d2018d663492a68c0c5f7 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 6 Sep 2021 11:57:32 -0700 Subject: [PATCH] Added new placeholders %Level_%gamemode%_top_island_name_%rank% - lists the island name %Level_%gamemode%_top_island_members_%rank% - a comma separated list of team members https://github.com/BentoBoxWorld/Level/issues/224 https://github.com/BentoBoxWorld/Level/issues/211 https://github.com/BentoBoxWorld/Level/issues/132 https://github.com/BentoBoxWorld/Level/issues/107 https://github.com/BentoBoxWorld/Level/issues/105 --- src/main/java/world/bentobox/level/Level.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index df3004d..1416194 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -3,8 +3,11 @@ package world.bentobox.level; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.World; @@ -208,6 +211,12 @@ public class Level extends Addon implements Listener { // Name getPlugin().getPlaceholdersManager().registerPlaceholder(this, gm.getDescription().getName().toLowerCase() + "_top_name_" + i, u -> getRankName(gm.getOverWorld(), rank)); + // Island Name + getPlugin().getPlaceholdersManager().registerPlaceholder(this, + gm.getDescription().getName().toLowerCase() + "_top_island_name_" + i, u -> getRankIslandName(gm.getOverWorld(), rank)); + // Members + getPlugin().getPlaceholdersManager().registerPlaceholder(this, + gm.getDescription().getName().toLowerCase() + "_top_members_" + i, u -> getRankMembers(gm.getOverWorld(), rank)); // Level getPlugin().getPlaceholdersManager().registerPlaceholder(this, gm.getDescription().getName().toLowerCase() + "_top_value_" + i, u -> getRankLevel(gm.getOverWorld(), rank)); @@ -224,6 +233,37 @@ public class Level extends Addon implements Listener { return getPlayers().getName(getManager().getTopTen(world, TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null)); } + String getRankIslandName(World world, int rank) { + if (rank < 1) rank = 1; + if (rank > TEN) rank = TEN; + UUID owner = getManager().getTopTen(world, TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null); + if (owner != null) { + Island island = getIslands().getIsland(world, owner); + if (island != null) { + return island.getName() == null ? "" : island.getName(); + } + } + return ""; + } + + String getRankMembers(World world, int rank) { + if (rank < 1) rank = 1; + if (rank > TEN) rank = TEN; + UUID owner = getManager().getTopTen(world, TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null); + if (owner != null) { + Island island = getIslands().getIsland(world, owner); + if (island != null) { + // Sort members by rank + return island.getMembers().entrySet().stream() + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) + .map(Map.Entry::getKey) + .map(getPlayers()::getName) + .collect(Collectors.joining(",")); + } + } + return ""; + } + String getRankLevel(World world, int rank) { if (rank < 1) rank = 1; if (rank > TEN) rank = TEN;