Class ElectionManager
java.lang.Object
nl.minetopiasdb.api.election.ElectionManager
- All Implemented Interfaces:
nl.mrwouter.channelmanager.MessageListener
Class responsible for managing the election
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCandidate(UUID uuid, String extraInfo) Add a candidate to the electionend()Mark the current election as ended.voidReinitialize the candidate cacheGet a list of candidatesstatic ElectionManagerGet an instance of the ElectionManagergetVotes()Get a HashMap containing the UUID of the candidate and the amount of votes they have.booleanCheck if this player has already voted in the current elections.See if the election is started.booleanremoveCandidate(UUID uuid) Remove a candidate from this electionstart()Start an election.Process a vote from voter to candidate.
-
Constructor Details
-
ElectionManager
public ElectionManager()
-
-
Method Details
-
getInstance
Get an instance of the ElectionManager- Returns:
- instance of ElectionManager
-
isStarted
See if the election is started.- Returns:
CompletableFuturewith a boolean that is true when the election has started.
-
start
Start an election. Starting an election means deleting the current participants and their votes.- Returns:
CompletableFuturewith a boolean that is true when the election has been successfully started.
-
end
Mark the current election as ended. This won't throw away any data, that only happens when thestart()method is called.- Returns:
- Empty CompletableFuture
-
getVotes
Get a HashMap containing the UUID of the candidate and the amount of votes they have.- Returns:
CompletableFuturewith a HashMap containing the voting data.
-
hasVoted
Check if this player has already voted in the current elections.- Parameters:
uuid- UUID of player- Returns:
- a boolean that is true if the player has already voted
-
vote
Process a vote from voter to candidate.- Parameters:
voter- UUID of player who hasn't voted in the current election beforecandidate- candidate who needs to be added usingaddCandidate(UUID, String)- Returns:
CompletableFuturewith a boolean that is true when the vote has been counted successfully.
-
getCandidates
-
addCandidate
Add a candidate to the election- Parameters:
uuid- UUID of the candidateextraInfo- the extra info for this candidate. This is usually shown as a lore in the voting menu.- Returns:
CompletableFuturewith a boolean that is true when the candidate has been added successfully.
-
removeCandidate
Remove a candidate from this election- Parameters:
uuid- UUID of the candidate- Returns:
CompletableFuturewith a boolean that is true when the candidate has been removed successfully.
-
fillCandidateCache
public void fillCandidateCache()Reinitialize the candidate cache -
onMessageReceive
-