Added the new top ten placeholders

Level_[gamemode]-island-top-name-# -> Level_[gamemode]_top_name_#
Level_[gamemode]-island-top-value-# -> Level_[gamemode]_top_value_#
This commit is contained in:
Florian CUNY 2019-11-23 14:55:58 +01:00
parent 801bfe6a39
commit dae58b8dff
3 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package world.bentobox.level;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -165,6 +166,26 @@ public class Level extends Addon {
.map(island -> getIslandLevel(gm.getOverWorld(), island.getOwner()))
.map(level -> getLevelPresenter().getLevelString(level))
.orElse("0"));
// Top Ten
for (int i = 1; i <= 10; i++) {
final int rank = i;
// Value
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_top_value_" + rank,
user -> {
Collection<Long> values = getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values();
return values.size() < rank ? "" : values.stream().skip(rank).findFirst().map(String::valueOf).orElse("");
});
// Name
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_top_name_" + rank,
user -> {
Collection<UUID> values = getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet();
return values.size() < rank ? "" : getPlayers().getName(values.stream().skip(rank).findFirst().orElse(null));
});
}
}
});

View File

@ -32,7 +32,7 @@ public class TopTenNamePlaceholder implements PlaceholderReplacer {
public String onReplace(User user) {
level.logWarning("You are using a deprecated placeholder.");
level.log("Please replace any occurrence of 'Level_" + gm.getDescription().getName().toLowerCase() + "-island-top-name-#'");
level.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_island_top_name_#'");
level.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_top_name_#'");
Collection<UUID> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet();
return values.size() < i ? "" : level.getPlayers().getName(values.stream().skip(i).findFirst().orElse(null));
}

View File

@ -32,7 +32,7 @@ public class TopTenPlaceholder implements PlaceholderReplacer {
public String onReplace(User user) {
level.logWarning("You are using a deprecated placeholder.");
level.log("Please replace any occurrence of 'Level_" + gm.getDescription().getName().toLowerCase() + "-island-top-value-#'");
level.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_island_top_value_#'");
level.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_top_value_#'");
Collection<Long> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values();
return values.size() < i ? "" : values.stream().skip(i).findFirst().map(String::valueOf).orElse("");
}