Class ElectionManager

java.lang.Object
nl.minetopiasdb.api.election.ElectionManager
All Implemented Interfaces:
nl.mrwouter.channelmanager.MessageListener

public class ElectionManager extends Object implements nl.mrwouter.channelmanager.MessageListener
Class responsible for managing the election
  • Constructor Details

    • ElectionManager

      public ElectionManager()
  • Method Details

    • getInstance

      public static ElectionManager getInstance()
      Get an instance of the ElectionManager
      Returns:
      instance of ElectionManager
    • isStarted

      public CompletableFuture<Boolean> isStarted()
      See if the election is started.
      Returns:
      CompletableFuture with a boolean that is true when the election has started.
    • start

      public CompletableFuture<Boolean> 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

      public CompletableFuture<Void> end()
      Mark the current election as ended. This won't throw away any data, that only happens when the start() method is called.
      Returns:
      Empty CompletableFuture
    • getVotes

      public CompletableFuture<HashMap<UUID,Integer>> 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

      public boolean hasVoted(UUID uuid)
      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

      public CompletableFuture<Boolean> vote(UUID voter, UUID candidate)
      Process a vote from voter to candidate.
      Parameters:
      voter - UUID of player who hasn't voted in the current election before
      candidate - candidate who needs to be added using addCandidate(UUID, String)
      Returns:
      CompletableFuture with a boolean that is true when the vote has been counted successfully.
    • getCandidates

      public HashMap<UUID,String> getCandidates()
      Get a list of candidates
      Returns:
      A cached HashMap containing the UUID of the participant and their description.
    • addCandidate

      public CompletableFuture<Boolean> addCandidate(UUID uuid, String extraInfo)
      Add a candidate to the election
      Parameters:
      uuid - UUID of the candidate
      extraInfo - 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

      public CompletableFuture<Boolean> removeCandidate(UUID uuid)
      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

      public boolean onMessageReceive(String channel, String subChannel, Map<String,String> data)
      Specified by:
      onMessageReceive in interface nl.mrwouter.channelmanager.MessageListener