Skip to content

Commit

Permalink
Allow listing top 10 of timed types in the list command
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Oct 13, 2023
1 parent dedab6d commit 03d1c50
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static us.ajg0702.leaderboards.LeaderboardPlugin.message;

Expand All @@ -29,7 +28,7 @@ public MainCommand(LeaderboardPlugin plugin) {
addSubCommand(new UpdatePlayer(plugin));
addSubCommand(new RemovePlayer(plugin));
addSubCommand(new Remove(plugin));
addSubCommand(new ListBoards(plugin));
addSubCommand(new ListCommand(plugin));
addSubCommand(new Signs(plugin));
addSubCommand(new Export(plugin));
addSubCommand(new Import(plugin));
Expand All @@ -45,7 +44,7 @@ public MainCommand(LeaderboardPlugin plugin) {
}

@Override
public List<String> autoComplete(CommandSender sender, String[] args) {
public java.util.List<String> autoComplete(CommandSender sender, String[] args) {
if(!checkPermission(sender)) {
return Collections.emptyList();
}
Expand All @@ -66,7 +65,7 @@ public void execute(CommandSender sender, String[] args, String label) {
sendHelp(sender, label, getSubCommands());
}

public static void sendHelp(CommandSender sender, String label, List<SubCommand> subCommands) {
public static void sendHelp(CommandSender sender, String label, java.util.List<SubCommand> subCommands) {
sender.sendMessage(message(""));
for(SubCommand subCommand : subCommands) {
if(!subCommand.showInTabComplete()) continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package us.ajg0702.leaderboards.commands.main.subcommands;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.bukkit.Bukkit;
import us.ajg0702.commands.CommandSender;
import us.ajg0702.commands.SubCommand;
import us.ajg0702.leaderboards.LeaderboardPlugin;
import us.ajg0702.leaderboards.cache.helpers.DbRow;

import java.io.*;
import java.sql.SQLException;
import java.util.*;
import java.util.logging.Level;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.bukkit.Bukkit;
import us.ajg0702.commands.CommandSender;
import us.ajg0702.commands.SubCommand;
import us.ajg0702.leaderboards.Debug;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package us.ajg0702.leaderboards.commands.main.subcommands;

import org.bukkit.Bukkit;
import us.ajg0702.commands.CommandSender;
import us.ajg0702.commands.SubCommand;
import us.ajg0702.leaderboards.LeaderboardPlugin;
Expand All @@ -11,17 +10,23 @@

import static us.ajg0702.leaderboards.LeaderboardPlugin.message;

public class ListBoards extends SubCommand {
public class ListCommand extends SubCommand {
private final LeaderboardPlugin plugin;

public ListBoards(LeaderboardPlugin plugin) {
public ListCommand(LeaderboardPlugin plugin) {
super("list", Collections.emptyList(), "ajleaderboards.use", "List all boards in ajleaderboards, or list the top 10 players in a certain board.");
this.plugin = plugin;
}

@Override
public java.util.List<String> autoComplete(CommandSender commandSender, String[] args) {
return filterCompletion(plugin.getTopManager().getBoards(), args[0]);
if(args.length <= 1) {
return filterCompletion(plugin.getTopManager().getBoards(), args[0]);
} else if(args.length == 2) {
return filterCompletion(TimedType.lowerNames(), args[1]);
} else {
return Collections.emptyList();
}
}

@Override
Expand All @@ -35,14 +40,15 @@ public void execute(CommandSender sender, String[] args, String label) {
sender.sendMessage(message(list.toString()));
return;
}
String boardn = args[0];
if(!plugin.getCache().boardExists(boardn)) {
sender.sendMessage(message("&cThe board '"+boardn+"' does not exist."));
String board = args[0];
TimedType timedType = args.length > 1 ? TimedType.of(args[1]) : TimedType.ALLTIME;
if(!plugin.getCache().boardExists(board)) {
sender.sendMessage(message("&cThe board '"+board+"' does not exist."));
return;
}
StringBuilder list = new StringBuilder("&6Top for " + boardn);
StringBuilder list = new StringBuilder("&6Top for " + board + " " + timedType.lowerName());
for(int i = 1;i<=10;i++) {
StatEntry e = plugin.getCache().getStat(i, boardn, TimedType.ALLTIME);
StatEntry e = plugin.getCache().getStat(i, board, timedType);
list.append("\n&6").append(i).append(". &e").append(e.getPlayerName()).append(" &7- &e").append(e.getScorePretty());
}
sender.sendMessage(message(list.toString()));
Expand Down

0 comments on commit 03d1c50

Please sign in to comment.