Run lookup for /quests top asynchronously

This commit is contained in:
PikaMug 2020-01-11 03:32:34 -05:00
parent 63579df80e
commit 4d23408e97

View File

@ -537,47 +537,44 @@ public class CmdExecutor implements CommandExecutor {
.replace("<greatest>", String.valueOf(plugin.getSettings().getTopLimit()))); .replace("<greatest>", String.valueOf(plugin.getSettings().getTopLimit())));
return true; return true;
} }
File folder = new File(plugin.getDataFolder(), "data"); Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
File[] playerFiles = folder.listFiles(); @Override
Map<String, Integer> questPoints = new HashMap<String, Integer>(); public void run() {
if (playerFiles != null) { File folder = new File(plugin.getDataFolder(), "data");
for (File f : playerFiles) { File[] playerFiles = folder.listFiles();
if (!f.isDirectory()) { Map<String, Integer> questPoints = new HashMap<String, Integer>();
FileConfiguration data = new YamlConfiguration(); if (playerFiles != null) {
try { for (File f : playerFiles) {
data.load(f); if (!f.isDirectory()) {
} catch (IOException e) { FileConfiguration data = new YamlConfiguration();
e.printStackTrace(); try {
} catch (InvalidConfigurationException e) { data.load(f);
e.printStackTrace(); } catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
questPoints.put(data.getString("lastKnownName", "Unknown"),
data.getInt("quest-points", 0));
}
}
}
LinkedHashMap<String, Integer> sortedMap = (LinkedHashMap<String, Integer>) sort(questPoints);
int numPrinted = 0;
String msg = Lang.get("topQuestersTitle");
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD);
cs.sendMessage(ChatColor.GOLD + msg);
for (Entry<String, Integer> entry : sortedMap.entrySet()) {
numPrinted++;
cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + entry.getKey() + " - "
+ ChatColor.DARK_PURPLE + entry.getValue() + ChatColor.YELLOW + " "
+ Lang.get("questPoints"));
if (numPrinted == topNumber) {
break;
} }
String name = f.getName().substring(0, (f.getName().indexOf(".")));
questPoints.put(name, data.getInt("quest-points"));
} }
} }
} });
LinkedHashMap<String, Integer> sortedMap = (LinkedHashMap<String, Integer>) sort(questPoints);
int numPrinted = 0;
String msg = Lang.get("topQuestersTitle");
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD);
cs.sendMessage(ChatColor.GOLD + msg);
for (String s : sortedMap.keySet()) {
int i = (Integer) sortedMap.get(s);
s = s.trim();
try {
UUID id = UUID.fromString(s);
s = Bukkit.getOfflinePlayer(id).getName();
} catch (IllegalArgumentException e) {
plugin.getLogger().warning("File name \"" + s + "\"in /data folder is not a valid player UUID!");
break;
}
numPrinted++;
cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + s + " - " + ChatColor.DARK_PURPLE
+ i + ChatColor.YELLOW + " " + Lang.get("questPoints"));
if (numPrinted == topNumber) {
break;
}
}
} }
return true; return true;
} }