[HELP] Stats top command...

Discussion in 'Plugin Development' started by Mr360zack, Jul 26, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Mr360zack

    I'm trying to get the top 10 of a player stat using a command (/stats top)
    Ex /stats top - shows top 10 kills
    Here is my current code:
    (its kinda messy, I need to know an EASIER way to do this.. or what im doing wrong)
    Code:java
    1. Map<Integer, PlayerFile> i = new HashMap<>();
    2. Map<Integer, String> uuids = new HashMap<>();
    3. for(String s : Core.UUIDS.values()){
    4. if(XPlayerManager.containsStats(s)) {
    5. XPlayer t = XPlayerManager.getStats(s);
    6. i.put(t.getKills(), new PlayerFile(s));
    7. uuids.put(t.getKills(), s);
    8. }
    9. else{
    10. PlayerFile pf = new PlayerFile(s);
    11. i.put(pf.getData().getInt("kills"), pf);
    12. uuids.put(pf.getData().getInt("kills"), pf.getFile().getName().toString());
    13. }
    14. }
    15. List<Integer> li = new ArrayList<>();
    16. for(Integer in : i.keySet()){
    17. li.add(in);
    18. }
    19.  
    20. Collections.sort(li, new ComparableHighToLow());
    21. int count = 0;
    22. for (Integer integer : li) {
    23. if(count <10) {
    24. String name = "null";
    25. for(String s : Core.UUIDS.keySet()){
    26. //li stores list of kills
    27. //i stores map of kills, playerfile
    28. //count is the amount ((0)1-10)
    29. //name = player name
    30. if(Core.UUIDS.get(s).equalsIgnoreCase(uuids.get(li.get(count)))){
    31. for(String v : Core.UUIDS.values()){
    32. for(String k : Core.UUIDS.keySet()){
    33. if(Core.UUIDS.get(k).equalsIgnoreCase(v)){
    34. name = k;
    35. }
    36. }
    37. }
    38. }
    39.  
    40. }
    41.  
    42. //old p.sendMessage(ChatColor.RED + ""+ count + ". §6" + li.get(count) + " ratio points" + " "+i.get(li.get(count)).getName());
    43. p.sendMessage(ChatColor.RED + "" + (count+1) + ". §b" + name+"§7 - §b"+ li.get(count) + "§7 kills");
    44. count++;
    45. }
    46.  
    47. }

    When I do the command it shows up like this: http://prntscr.com/46o6gs
    When in actuality, it should say I (Shockz__) am #1 and have 70 kills
    while XZhunter should be #2 with 0 kills.
    Help is appreciated! thanks

    Update - heres my new code. http://hastebin.com/ecomokaqag.avrasm
    But instead of showing Xz for #2 now it shows his UUID.
    And my name is now correctly displayed as #1.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page