Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.DevCodePvP.Stats;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Set;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.configuration.InvalidConfigurationException;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- public class CMDTop10 implements CommandExecutor {
- public static File f = new File("plugins/Stats/Stats.yml");
- public static YamlConfiguration yamlFile = YamlConfiguration.loadConfiguration(f);
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static void loadTopTen(Player p, int b) {
- File f = new File("plugins/Stats/Stats.yml");
- YamlConfiguration yamlFile = YamlConfiguration.loadConfiguration(f);
- try {
- yamlFile.load(f);
- } catch (FileNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (InvalidConfigurationException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- Map<String, Integer> unsorted = new HashMap<>();
- ConfigurationSection sSection = yamlFile.getConfigurationSection("Spieler"); // Wir holen die Section als Object
- Set<String> keys = sSection.getKeys(false); // Wir holen alle Subkeys in der Spieler Object
- for(String k : keys) { // Wir gehen jedes durch und adden sie in die "unsorted" List
- ConfigurationSection s = sSection.getConfigurationSection(k);
- unsorted.put(k, s.getInt("Kills"));
- }
- Object[] a = unsorted.entrySet().toArray(); // Wir verwandeln die Map in einen Array
- Arrays.sort(a, new Comparator() { // Wir sortieren den Array nach grösse
- public int compare(Object o1, Object o2) {
- return ((Map.Entry<String, Integer>) o2).getValue().compareTo(
- ((Map.Entry<String, Integer>) o1).getValue());
- }
- });
- int count = 1; // Counter (Platz)
- p.sendMessage("§8§m----------------------------------");
- p.sendMessage("");
- p.sendMessage("§6Top10 §8» §a[Platz]# §8> §6[Spieler] §7mit §6[Kills] §7Kills");
- p.sendMessage("");
- for(Object e : a) {
- if(count <= b) {
- String player = ((Map.Entry<String, Integer>) e).getKey(); //Spieler
- int kills = ((Map.Entry<String, Integer>) e).getValue(); //Kills
- p.sendMessage("§6Top10 §8» §a" + count + "# §8> §6" + player + " §7mit §6" + kills + " §7Kills");
- count++; // Vergrössern den Count
- }
- }
- p.sendMessage("");
- p.sendMessage("§8§m----------------------------------");
- }
- @Override
- public boolean onCommand(CommandSender s, Command cmd, String arg2, String[] args) {
- Player p = (Player)s;
- if(args.length == 0)
- {
- loadTopTen(p, 10);
- }else if(args.length == 1)
- {
- int i = Integer.parseInt(args[0]);
- if(i > 50)
- {
- p.sendMessage("§6Top10 §8» §7Benutzung §8> §6/Top [1-50]");
- }else
- {
- loadTopTen(p, i);
- }
- }else
- {
- p.sendMessage(Main.P + "§7Benutzung §8> §6/Top [1-50]");
- }
- return false;
- }
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static void loadRank(Player p, String pl) {
- File f = new File("plugins/Stats/Stats.yml");
- YamlConfiguration yamlFile = YamlConfiguration.loadConfiguration(f);
- try {
- yamlFile.load(f);
- } catch (FileNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (InvalidConfigurationException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- Map<String, Integer> unsorted = new HashMap<>();
- ConfigurationSection sSection = yamlFile.getConfigurationSection("Spieler"); // Wir holen die Section als Object
- Set<String> keys = sSection.getKeys(false); // Wir holen alle Subkeys in der Spieler Object
- for(String k : keys) { // Wir gehen jedes durch und adden sie in die "unsorted" List
- ConfigurationSection s = sSection.getConfigurationSection(k);
- unsorted.put(k, s.getInt("Kills"));
- }
- Object[] a = unsorted.entrySet().toArray(); // Wir verwandeln die Map in einen Array
- Arrays.sort(a, new Comparator() { // Wir sortieren den Array nach grösse
- public int compare(Object o1, Object o2) {
- return ((Map.Entry<String, Integer>) o2).getValue().compareTo(
- ((Map.Entry<String, Integer>) o1).getValue());
- }
- });
- int count = 1; // Counter (Platz)
- p.sendMessage("§8§m----------------------------------");
- p.sendMessage("");
- p.sendMessage("§8» §a[Platz]# §8> §6[Spieler] §7mit §6[Kills] §7Kills");
- p.sendMessage("");
- for(Object e : a) {
- String player = ((Map.Entry<String, Integer>) e).getKey(); //Spieler
- int kills = ((Map.Entry<String, Integer>) e).getValue(); //Kills
- p.sendMessage("§8» §a" + count + "# §8> §6" + player + " §7mit §6" + kills + " §7Kills");
- }
- p.sendMessage("");
- p.sendMessage("§8§m----------------------------------");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement