How to get the top five players from YAMLs int value

Discussion in 'Plugin Development' started by Orcem12, Oct 4, 2012.

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

    Orcem12

    Hello all, I'm working on a custom economy plugin and the OP requested for a certain command to display the top 5 most richest players. Thing is, I'm using YAMLs on request! How do I do this?

    I'd imagine it would be something like this:
    Code:
        File[] YAMLS = new File(plugin.getDataFolder()+"Metro-Players"+File.separator).listFiles();
    Then maybe adding the files to an ArrayList or something? Then filter through it? Help, haha.
     
  2. Java has a class called TreeSet/TreeMap, it's like a HashSet/HashMap, but it orders the elements automatically.

    There's probably a better way to get the top 5 from a list. Some perfect algorithm that doesn't take up too much extra time. I'd say: forget about that, just use TreeSet/TreeMap
     
  3. Offline

    hockeygoalie5

    You can do as Mtihc said, and that should work well for you, but I recommend not using YAML to store information like that. It's great for configs and things, but you should use databases for that kind of storage. If it's not out of your way and you already know SQL, look into using the SQLite driver for JDBC. SQLite is like a MySQL database, but instead of needing a database server, it uses a small file stored in the plugin's directory. SQLite is built into CraftBukkit, so implementing will be easy.
     
    Mtihc likes this.
Thread Status:
Not open for further replies.

Share This Page