Skip to content

Commit

Permalink
fix(verify): Fixed verify error when have multiple requests to be han…
Browse files Browse the repository at this point in the history
…dled.
  • Loading branch information
CarmJos committed Oct 2, 2023
1 parent 63a574e commit 62b30f6
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Set;

public class VerifyCommand extends SubCommand<MainCommand> {

public VerifyCommand(@NotNull MainCommand parent, String identifier, String... aliases) {
Expand All @@ -25,20 +28,23 @@ public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) thro
PluginMessages.VERIFY.START.send(sender);
VoteManager voteManager = Main.getInstance().getVoteManager();

int updated = 0;
Set<RequestInformation> approved = new HashSet<>();
Set<RequestInformation> rejected = new HashSet<>();
for (RequestInformation request : voteManager.getRequests().values()) {
RequestResult result = voteManager.calculateResult(request);
if (result == RequestResult.PENDING) continue;
updated++;

if (result == RequestResult.APPROVED) {
voteManager.approve(request).join();
if (voteManager.calculateResult(request) == RequestResult.APPROVED) {
approved.add(request);
} else {
voteManager.reject(request).join();
rejected.add(request);
}
}

PluginMessages.VERIFY.SUCCESS.prepare(updated, System.currentTimeMillis() - s1).to(sender);
approved.forEach(requestInformation -> voteManager.approve(requestInformation).join());
rejected.forEach(requestInformation -> voteManager.reject(requestInformation).join());

PluginMessages.VERIFY.SUCCESS.prepare(
approved.size() + rejected.size(),
System.currentTimeMillis() - s1
).to(sender);
});
return null;
}
Expand Down

0 comments on commit 62b30f6

Please sign in to comment.