Package nl.minetopiasdb.api.election
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
-
Method Summary
Modifier and TypeMethodDescriptionaddCandidate
(UUID uuid, String extraInfo) Add a candidate to the electionend()
Mark the current election as ended.void
Reinitialize the candidate cacheGet a list of candidatesstatic ElectionManager
Get an instance of the ElectionManagergetVotes()
Get a HashMap containing the UUID of the candidate and the amount of votes they have.boolean
Check if this player has already voted in the current elections.See if the election is started.boolean
removeCandidate
(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:
CompletableFuture
with 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:
CompletableFuture
with 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:
CompletableFuture
with 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:
CompletableFuture
with a boolean that is true when the vote has been counted successfully.
-
getCandidates
Get a list of candidates- Returns:
- A cached HashMap containing the UUID of the participant and their description.
-
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:
CompletableFuture
with 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:
CompletableFuture
with a boolean that is true when the candidate has been removed successfully.
-
fillCandidateCache
public void fillCandidateCache()Reinitialize the candidate cache -
onMessageReceive
- Specified by:
onMessageReceive
in interfacenl.mrwouter.channelmanager.MessageListener
-