Search in sources :

Example 1 with PageResult

use of gg.projecteden.nexus.models.hours.HoursService.PageResult in project Nexus by ProjectEdenGG.

the class HoursCommand method top2.

// TODO Update paginate to support database-level pagination
@Async
@Description("View the play time leaderboard for any year, month, or day")
@Path("top [args...]")
void top2(@Arg("1") HoursTopArguments args, @Switch boolean onlyStaff) {
    int page = args.getPage();
    List<PageResult> results = service.getPage(args);
    String onlyStaffSwitch = "";
    if (onlyStaff) {
        onlyStaffSwitch = " --onlyStaff";
        results.removeIf(result -> !Rank.of(result.getUuid()).isStaff());
    }
    if (results.size() == 0)
        error("&cNo results on page " + page);
    int totalHours = 0;
    for (PageResult result : results) totalHours += result.getTotal();
    send("");
    send(PREFIX + "Total: " + Timespan.ofSeconds(totalHours).format() + (page > 1 ? "&e  |  &3Page " + page : ""));
    BiFunction<PageResult, String, JsonBuilder> formatter = (result, index) -> json(index + " &e" + Nerd.of(result.getUuid()).getColoredName() + " &7- " + Timespan.ofSeconds(result.getTotal()).format());
    paginate(results, formatter, "/hours top " + args.getInput() + onlyStaffSwitch, page);
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) BiFunction(java.util.function.BiFunction) Async(gg.projecteden.annotations.Async) Arg(gg.projecteden.nexus.framework.commands.models.annotations.Arg) ConverterFor(gg.projecteden.nexus.framework.commands.models.annotations.ConverterFor) Player(org.bukkit.entity.Player) AFK(gg.projecteden.nexus.features.afk.AFK) ArrayList(java.util.ArrayList) Hours(gg.projecteden.nexus.models.hours.Hours) HashSet(java.util.HashSet) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) Nickname(gg.projecteden.nexus.models.nickname.Nickname) TimespanBuilder(gg.projecteden.utils.TimeUtils.Timespan.TimespanBuilder) Timespan(gg.projecteden.utils.TimeUtils.Timespan) Nexus(gg.projecteden.nexus.Nexus) Description(gg.projecteden.nexus.framework.commands.models.annotations.Description) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Nerd(gg.projecteden.nexus.models.nerd.Nerd) Rank(gg.projecteden.nexus.models.nerd.Rank) Koda(gg.projecteden.nexus.features.chat.Koda) CustomCommand(gg.projecteden.nexus.framework.commands.models.CustomCommand) Tasks(gg.projecteden.nexus.utils.Tasks) Set(java.util.Set) GroupChange(gg.projecteden.nexus.utils.LuckPermsUtils.GroupChange) Collectors(java.util.stream.Collectors) Aliases(gg.projecteden.nexus.framework.commands.models.annotations.Aliases) TickTime(gg.projecteden.utils.TimeUtils.TickTime) Switch(gg.projecteden.nexus.framework.commands.models.annotations.Switch) HoursTopArguments(gg.projecteden.nexus.models.hours.HoursService.HoursTopArguments) List(java.util.List) Jingle(gg.projecteden.nexus.utils.SoundUtils.Jingle) CommandEvent(gg.projecteden.nexus.framework.commands.models.events.CommandEvent) LocalDate(java.time.LocalDate) HoursService(gg.projecteden.nexus.models.hours.HoursService) TabCompleterFor(gg.projecteden.nexus.framework.commands.models.annotations.TabCompleterFor) OnlinePlayers(gg.projecteden.nexus.utils.PlayerUtils.OnlinePlayers) PageResult(gg.projecteden.nexus.models.hours.HoursService.PageResult) PageResult(gg.projecteden.nexus.models.hours.HoursService.PageResult) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Description(gg.projecteden.nexus.framework.commands.models.annotations.Description) Async(gg.projecteden.annotations.Async)

Aggregations

Async (gg.projecteden.annotations.Async)1 Nexus (gg.projecteden.nexus.Nexus)1 AFK (gg.projecteden.nexus.features.afk.AFK)1 Koda (gg.projecteden.nexus.features.chat.Koda)1 CustomCommand (gg.projecteden.nexus.framework.commands.models.CustomCommand)1 Aliases (gg.projecteden.nexus.framework.commands.models.annotations.Aliases)1 Arg (gg.projecteden.nexus.framework.commands.models.annotations.Arg)1 ConverterFor (gg.projecteden.nexus.framework.commands.models.annotations.ConverterFor)1 Description (gg.projecteden.nexus.framework.commands.models.annotations.Description)1 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)1 Switch (gg.projecteden.nexus.framework.commands.models.annotations.Switch)1 TabCompleterFor (gg.projecteden.nexus.framework.commands.models.annotations.TabCompleterFor)1 CommandEvent (gg.projecteden.nexus.framework.commands.models.events.CommandEvent)1 Hours (gg.projecteden.nexus.models.hours.Hours)1 HoursService (gg.projecteden.nexus.models.hours.HoursService)1 HoursTopArguments (gg.projecteden.nexus.models.hours.HoursService.HoursTopArguments)1 PageResult (gg.projecteden.nexus.models.hours.HoursService.PageResult)1 Nerd (gg.projecteden.nexus.models.nerd.Nerd)1 Rank (gg.projecteden.nexus.models.nerd.Rank)1 Nickname (gg.projecteden.nexus.models.nickname.Nickname)1