Top Stats

Discussion in 'Plugin Development' started by Blah1, Jan 9, 2014.

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

    Blah1

    So this works for like 1 hour but then it just breaks, as in all the "kills" become 0.
    The stats's are still there (like in the player file) but it doesn't show up on the list.
    I don't know why...

    Code:java
    1. public final HashMap<String, Integer> kills = new HashMap<>();
    2.  
    3. public static <K, V extends Comparable<? super V>> Map<K, V>
    4. sortByValue(Map<K, V> map) {
    5. List<Map.Entry<K, V>> list =
    6. new LinkedList<>(map.entrySet());
    7. Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
    8. public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
    9. return (o1.getValue()).compareTo(o2.getValue());
    10. }
    11. });
    12.  
    13. Map<K, V> result = new LinkedHashMap<>();
    14. for (Map.Entry<K, V> entry : list) {
    15. result.put(entry.getKey(), entry.getValue());
    16. }
    17. return result;
    18. }
    19.  
    20. public void onSortKills(String s, Player player) {
    21. switch (s.toLowerCase()) {
    22. case "kills":
    23. String path = plugin.getDataFolder().getAbsolutePath();
    24. String plugins = path.substring(0, path.lastIndexOf(File.separator));
    25. File users = new File(plugins + File.separator + "PVPScores", "userdata");
    26. if (users.exists()) {
    27. for (File file : users.listFiles()) {
    28. String ss = file.getName().toLowerCase().replace(".yml", "");
    29. YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
    30. int i = config.getInt(ss + ".kills");
    31. String name = config.getString(ss + ".name");
    32. kills.put(name, i);
    33. }
    34. }
    35. String msg = plugin.getConfig().getString("statstop.kills");
    36. List<String> strings = new ArrayList<>();
    37. int count = 0;
    38. for (Map.Entry<String, Integer> in : sortByValue(kills).entrySet()) {
    39. count++;
    40. strings.add(msg.replace("{NAME}", in.getKey()).replace("{KILLS}", Integer.toString(in.getValue())));
    41. if (count == 10) {
    42. break;
    43. }
    44. }
    45. count = 0;
    46. Collections.reverse(strings);
    47. if (plugin.getConfig().getBoolean("statstop.this-before-kills")) {
    48. for (String pm : plugin.getConfig().getStringList("statstop.before-kills")) {
    49. player.sendMessage(ChatColor.translateAlternateColorCodes('&', pm));
    50. }
    51. }
    52. for (String fin : strings) {
    53. count++;
    54. player.sendMessage(ChatColor.translateAlternateColorCodes('&', fin.replace("{RANK}", Integer.toString(count))));
    55. }
    56. if (plugin.getConfig().getBoolean("statstop.this-after-kills")) {
    57. for (String pm : plugin.getConfig().getStringList("statstop.after-kills")) {
    58. player.sendMessage(ChatColor.translateAlternateColorCodes('&', pm));
    59. }
    60. }
    61. break;
    62. }
    63. }
     
  2. Offline

    Blah1

    Bump
     
  3. Offline

    Blah1

Thread Status:
Not open for further replies.

Share This Page