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
This commit is contained in:
tastybento 2021-09-06 11:57:32 -07:00
parent b16d458cae
commit 1b29f7f6ac

View File

@ -3,8 +3,11 @@ package world.bentobox.level;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
@ -208,6 +211,12 @@ public class Level extends Addon implements Listener {
// Name // Name
getPlugin().getPlaceholdersManager().registerPlaceholder(this, getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_top_name_" + i, u -> getRankName(gm.getOverWorld(), rank)); 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 // Level
getPlugin().getPlaceholdersManager().registerPlaceholder(this, getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_top_value_" + i, u -> getRankLevel(gm.getOverWorld(), rank)); 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)); 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) { String getRankLevel(World world, int rank) {
if (rank < 1) rank = 1; if (rank < 1) rank = 1;
if (rank > TEN) rank = TEN; if (rank > TEN) rank = TEN;