Top voters (Top 5 voters)

Discussion in 'Plugin Development' started by Cherwin1, Aug 12, 2014.

Thread Status:
Not open for further replies.
  1. Hello again,

    I am improving my plugin and trying to add Top Voters ( A list of 5 players with the most votes )
    But i just cant do it!
    I tried some ways, looked it up on google but i dont see a answer which helps me!

    The Names and ints are stored in config like this
    Code:
    playervotes:
      Cherwin1: 5
      Jason: 3
      random: 1
      spike: 2
      daniel: 4

    When a player uses /votetop they will see a list like:
    Code:
    [Vote Top]
    1. Cherwin1: 5
    2. Daniel: 4
    3. Jason: 3
    4. Spike: 2
    5. Random: 1
    Can someone help me?

    Thanks,
    Cherwin1
     
  2. Cherwin1
    What exactly is not working?
     
  3. DoppelRR

    I found this on the internet
    Code:
                      int first = 0;
                      String firstname = null;
                      int second = 0;
                      String secondname = null;
                      int third = 0;
                      String thirdname = null;
                      for (String playerName : voters.getConfigurationSection("playervotes").getKeys(true)){
                          int votes = voters.getInt("playervotes." + playerName);
                          if(votes > first){
                              first = votes;
                              firstname = playerName;
                          }else if(votes < first){
                              second = votes;
                              secondname = playerName;
                          }else if(votes < second){
                              third = votes;
                              thirdname = playerName;
                          }
                   
                      }
                      p.sendMessage(ChatColor.GOLD + "[Top Voters]");
                      p.sendMessage(ChatColor.GOLD + "1. " + ChatColor.RESET + firstname + ": " + ChatColor.GREEN + first + ChatColor.RESET + " votes!");
                      p.sendMessage(ChatColor.GOLD + "2. " + ChatColor.RESET + secondname + ": " + ChatColor.GREEN + second + ChatColor.RESET + " votes!");
                      p.sendMessage(ChatColor.GOLD + "3. " + ChatColor.RESET + thirdname + ": " + ChatColor.GREEN + third + ChatColor.RESET + " votes!");
    I edited a bit so i thought it would work. but it just doesn't work, Only the Number 1 works good!
    so i wanna know another method to make a Top. :$
     
  4. Cherwin1
    Again, what does not work arent you getting any Messages or are it just te wrong playernames and maybe Show how you edited the method.
     
  5. DoppelRR

    It shows like
    [Vote Top]
    1. Cherwin1: 3
    2. person2: 1
    3. null

    I just added the
    Code:
    }else if(votes < first){
                              second = votes;
                              secondname = playerName;
                          }else if(votes < second){
                              third = votes;
                              thirdname = playerName;
                          }
    Is there not a easier way?
     
  6. Offline

    MCForger

Thread Status:
Not open for further replies.

Share This Page