mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-26 04:35:56 +01:00
Added top ten placeholders
This commit is contained in:
parent
d4e1bbf0bd
commit
97fb434244
@ -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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<UUID> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet();
|
||||
return values.size() < i ? "" : level.getPlayers().getName(values.stream().skip(i).findFirst().orElse(null));
|
||||
}
|
||||
|
||||
}
|
@ -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<Long> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values();
|
||||
return values.size() < i ? "" : values.stream().skip(i).findFirst().map(String::valueOf).orElse("");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user