diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index e93255d..05aadc1 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -15,10 +15,12 @@ import world.bentobox.level.commands.admin.AdminTopCommand; import world.bentobox.level.commands.island.IslandLevelCommand; import world.bentobox.level.commands.island.IslandTopCommand; import world.bentobox.level.config.Settings; -import world.bentobox.level.listeners.JoinLeaveListener; import world.bentobox.level.listeners.IslandTeamListeners; +import world.bentobox.level.listeners.JoinLeaveListener; import world.bentobox.level.objects.LevelsData; import world.bentobox.level.placeholders.LevelPlaceholder; +import world.bentobox.level.placeholders.TopTenNamePlaceholder; +import world.bentobox.level.placeholders.TopTenPlaceholder; import world.bentobox.level.requests.LevelRequestHandler; /** @@ -129,6 +131,11 @@ public class Level extends Addon { // Register placeholders if (getPlugin().getPlaceholdersManager() != null) { getPlugin().getPlaceholdersManager().registerPlaceholder(this, "island-level", new LevelPlaceholder(this, gm)); + // Top Ten + for (int i = 1; i < 11; i++) { + getPlugin().getPlaceholdersManager().registerPlaceholder(this, "island-level-top-value-" + i, new TopTenPlaceholder(this, gm, i)); + getPlugin().getPlaceholdersManager().registerPlaceholder(this, "island-level-top-name-" + i, new TopTenNamePlaceholder(this, gm, i)); + } } }); diff --git a/src/main/java/world/bentobox/level/placeholders/LevelPlaceholder.java b/src/main/java/world/bentobox/level/placeholders/LevelPlaceholder.java index b7b3486..da61bf0 100644 --- a/src/main/java/world/bentobox/level/placeholders/LevelPlaceholder.java +++ b/src/main/java/world/bentobox/level/placeholders/LevelPlaceholder.java @@ -19,7 +19,8 @@ public class LevelPlaceholder implements PlaceholderReplacer { /** * Provides placeholder support - * @param gm + * @param addon - Level addon + * @param gm - Game mode */ public LevelPlaceholder(Level addon, GameModeAddon gm) { this.addon = addon; diff --git a/src/main/java/world/bentobox/level/placeholders/TopTenNamePlaceholder.java b/src/main/java/world/bentobox/level/placeholders/TopTenNamePlaceholder.java new file mode 100644 index 0000000..593b18d --- /dev/null +++ b/src/main/java/world/bentobox/level/placeholders/TopTenNamePlaceholder.java @@ -0,0 +1,39 @@ +/** + * + */ +package world.bentobox.level.placeholders; + +import java.util.Collection; +import java.util.UUID; + +import world.bentobox.bentobox.api.addons.GameModeAddon; +import world.bentobox.bentobox.api.placeholders.PlaceholderReplacer; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.level.Level; + +/** + * @author tastybento + * + */ +public class TopTenNamePlaceholder implements PlaceholderReplacer { + + private final Level level; + private final GameModeAddon gm; + private final int i; + + public TopTenNamePlaceholder(Level level, GameModeAddon gm, int i) { + this.level = level; + this.gm = gm; + this.i = i - 1; + } + + /* (non-Javadoc) + * @see world.bentobox.bentobox.api.placeholders.PlaceholderReplacer#onReplace(world.bentobox.bentobox.api.user.User) + */ + @Override + public String onReplace(User user) { + Collection values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet(); + return values.size() < i ? "" : level.getPlayers().getName(values.stream().skip(i).findFirst().orElse(null)); + } + +} diff --git a/src/main/java/world/bentobox/level/placeholders/TopTenPlaceholder.java b/src/main/java/world/bentobox/level/placeholders/TopTenPlaceholder.java new file mode 100644 index 0000000..27849e4 --- /dev/null +++ b/src/main/java/world/bentobox/level/placeholders/TopTenPlaceholder.java @@ -0,0 +1,39 @@ +/** + * + */ +package world.bentobox.level.placeholders; + +import java.util.Collection; + +import world.bentobox.bentobox.api.addons.GameModeAddon; +import world.bentobox.bentobox.api.placeholders.PlaceholderReplacer; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.level.Level; + +/** + * Provides the level values to placeholders + * @author tastybento + * + */ +public class TopTenPlaceholder implements PlaceholderReplacer { + + private final Level level; + private final GameModeAddon gm; + private final int i; + + public TopTenPlaceholder(Level level, GameModeAddon gm, int i) { + this.level = level; + this.gm = gm; + this.i = i - 1; + } + + /* (non-Javadoc) + * @see world.bentobox.bentobox.api.placeholders.PlaceholderReplacer#onReplace(world.bentobox.bentobox.api.user.User) + */ + @Override + public String onReplace(User user) { + Collection values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values(); + return values.size() < i ? "" : values.stream().skip(i).findFirst().map(String::valueOf).orElse(""); + } + +}