diff --git a/core/src/main/java/tc/oc/pgm/command/ModeCommand.java b/core/src/main/java/tc/oc/pgm/command/ModeCommand.java index 15e42c01c5..0315ad0e5e 100644 --- a/core/src/main/java/tc/oc/pgm/command/ModeCommand.java +++ b/core/src/main/java/tc/oc/pgm/command/ModeCommand.java @@ -17,9 +17,11 @@ import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang.WordUtils; +import org.jetbrains.annotations.NotNull; import tc.oc.pgm.api.Permissions; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.countdowns.CountdownContext; +import tc.oc.pgm.modes.Mode; import tc.oc.pgm.modes.ModeChangeCountdown; import tc.oc.pgm.modes.ModesPaginatedResult; import tc.oc.pgm.modes.ObjectiveModesMatchModule; @@ -34,43 +36,35 @@ public final class ModeCommand { public void next(Audience audience, Match match) { ObjectiveModesMatchModule modes = getModes(match); - if (modes == null) { - throwNoResults(); + List countdowns = modes.getActiveCountdowns(); + + if (countdowns.isEmpty()) throwNoResults(); + + TextComponent.Builder builder = + text().append(translatable("command.nextMode", NamedTextColor.DARK_PURPLE).append(space())); + + ModeChangeCountdown next = countdowns.get(0); + Duration timeLeft = modes.getCountdown().getTimeLeft(next); + + if (timeLeft == null) { + builder.append(text(next.getMode().getPreformattedMaterialName(), NamedTextColor.GOLD)); + } else if (timeLeft.getSeconds() >= 0) { + builder.append( + text( + WordUtils.capitalize(next.getMode().getPreformattedMaterialName()), + NamedTextColor.GOLD) + .append(space()) + .append(text("(", NamedTextColor.AQUA)) + .append( + new ModesPaginatedResult(modes) + .formatSingleCountdown(next) + .color(NamedTextColor.AQUA)) + .append(text(")", NamedTextColor.AQUA))); } else { - List countdowns = modes.getActiveCountdowns(); - - if (countdowns.isEmpty()) { - throwNoResults(); - } else { - TextComponent.Builder builder = - text() - .append( - translatable("command.nextMode", NamedTextColor.DARK_PURPLE).append(space())); - - ModeChangeCountdown next = countdowns.get(0); - Duration timeLeft = modes.getCountdown().getTimeLeft(next); - - if (timeLeft == null) { - builder.append(text(next.getMode().getPreformattedMaterialName(), NamedTextColor.GOLD)); - } else if (timeLeft.getSeconds() >= 0) { - builder.append( - text( - WordUtils.capitalize(next.getMode().getPreformattedMaterialName()), - NamedTextColor.GOLD) - .append(space()) - .append(text("(", NamedTextColor.AQUA)) - .append( - new ModesPaginatedResult(modes) - .formatSingleCountdown(next) - .color(NamedTextColor.AQUA)) - .append(text(")", NamedTextColor.AQUA))); - } else { - throwNoResults(); - } - - audience.sendMessage(builder.build()); - } + throwNoResults(); } + + audience.sendMessage(builder.build()); } @CommandMethod("list|page [page]") @@ -79,7 +73,20 @@ public void list( Audience audience, Match match, @Argument(value = "page", defaultValue = "1") @Range(min = "1") int page) { - showList(page, audience, getModes(match)); + ObjectiveModesMatchModule modes = getModes(match); + List modeList = modes.getSortedCountdowns(true); + int resultsPerPage = 8; + int pages = (modeList.size() + resultsPerPage - 1) / resultsPerPage; + Component header = + TextFormatter.paginate( + translatable("command.monumentModes"), + page, + pages, + NamedTextColor.DARK_AQUA, + NamedTextColor.AQUA, + true); + + new ModesPaginatedResult(header, resultsPerPage, modes).display(audience, modeList, page); } @CommandMethod("push