Skip to content

Commit 6d72e30

Browse files
committed
Add manual closed-result publication command
1 parent c56693b commit 6d72e30

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/main/java/com/modnmetl/modnvote/commands/PollCommand.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,38 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
689689
}
690690
return true;
691691
}
692+
case "publishresult" -> {
693+
if (!sender.hasPermission("modnvote.admin.poll.close")) {
694+
sender.sendMessage(messages.get("general.no_permission"));
695+
return true;
696+
}
697+
698+
if (args.length < 2) {
699+
sender.sendMessage("§cUsage: /" + label + " publishresult <pollId>");
700+
return true;
701+
}
702+
703+
try {
704+
long pollId = parsePollId(args[1]);
705+
Poll poll = requirePoll(pollId);
706+
707+
if (poll.status() != PollStatus.CLOSED) {
708+
sender.sendMessage("§cOnly CLOSED polls can have results published.");
709+
return true;
710+
}
711+
712+
ResultService.PollResult result = resultService.getPollResult(pollId);
713+
witnessPublicationService.publishPollClosed(poll, findOptions(pollId), result);
714+
715+
sender.sendMessage("§aPublished closed result for poll §f#" + pollId
716+
+ "§a to configured witness webhook(s).");
717+
} catch (PollServiceException e) {
718+
sender.sendMessage(messages.format("errors.result_failed",
719+
Map.of("reason", e.getMessage())));
720+
}
721+
722+
return true;
723+
}
692724
case "mypolls" -> {
693725
if (!(sender instanceof Player player)) {
694726
sender.sendMessage(messages.get("general.players_only"));

src/main/java/com/modnmetl/modnvote/presentation/ResultDisplayFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static List<String> formatRankedInGame(ResultService.PollResult result)
8888
lines.add("§7Ballots: §f" + result.totalVotes());
8989

9090
if (result.winnerName() != null && !result.winnerName().isBlank()) {
91-
lines.add(aWinner after transfers: §f" + result.winnerName());
91+
lines.add(aPoll winner: §f" + result.winnerName());
9292
}
9393

9494
if (result.finalWinnerTally() != null) {

src/main/java/com/modnmetl/modnvote/service/ResultService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ private RankedChoiceReport determineRankedChoiceReport(List<PollOption> options,
205205
Long winnerOptionId = null;
206206
OptionTally winnerTally = null;
207207
int finalExhaustedBallots = 0;
208-
208+
if (ballots.isEmpty()) {
209+
return new RankedChoiceReport(null, null, 0, List.of());
210+
}
209211
while (!active.isEmpty()) {
210212
Map<Long, Integer> roundCounts = new LinkedHashMap<>();
211213
for (Long optionId : active) {

0 commit comments

Comments
 (0)