mcMMO/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java

73 lines
2.3 KiB
Java
Raw Normal View History

2013-03-21 20:46:23 +01:00
package com.gmail.nossr50.runnables.commands;
import java.util.List;
2013-03-21 20:46:23 +01:00
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2013-03-21 20:46:23 +01:00
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.skills.SkillType;
2013-03-21 20:46:23 +01:00
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
2013-03-21 20:46:23 +01:00
/**
* Display the results of {@link MctopCommandAsyncTask} to the sender.
*/
2013-03-21 20:46:23 +01:00
public class MctopCommandDisplayTask extends BukkitRunnable {
private final List<PlayerStat> userStats;
private final CommandSender sender;
private final SkillType skill;
private final int page;
private final boolean useBoard, useChat;
2013-03-21 20:46:23 +01:00
/*package-private*/ MctopCommandDisplayTask(List<PlayerStat> userStats, int page, SkillType skill, CommandSender sender, boolean useBoard, boolean useChat) {
this.userStats = userStats;
2013-03-21 20:46:23 +01:00
this.page = page;
this.skill = skill;
2013-03-21 20:46:23 +01:00
this.sender = sender;
this.useBoard = useBoard;
this.useChat = useChat;
2013-03-21 20:46:23 +01:00
}
@Override
public void run() {
if (useBoard) {
displayBoard();
}
if (useChat) {
displayChat();
}
sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip"));
}
private void displayChat() {
if (skill == null) {
2013-03-21 20:46:23 +01:00
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getSkillName()));
2013-03-21 20:46:23 +01:00
}
int place = (page * 10) - 9;
for (PlayerStat stat : userStats) {
// Format:
// 01. Playername - skill value
// 12. Playername - skill value
sender.sendMessage(String.format("%2d. %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal));
2013-03-21 20:46:23 +01:00
place++;
}
}
2013-03-21 20:46:23 +01:00
private void displayBoard() {
if (skill == null) {
ScoreboardManager.showTopPowerScoreboard((Player) sender, page, userStats);
}
else {
ScoreboardManager.showTopScoreboard((Player) sender, skill, page, userStats);
}
2013-03-21 20:46:23 +01:00
}
}