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,6 +537,9 @@ public class CmdExecutor implements CommandExecutor {
.replace("<greatest>", String.valueOf(plugin.getSettings().getTopLimit())));
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
File folder = new File(plugin.getDataFolder(), "data");
File[] playerFiles = folder.listFiles();
Map<String, Integer> questPoints = new HashMap<String, Integer>();
@ -551,8 +554,8 @@ public class CmdExecutor implements CommandExecutor {
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
String name = f.getName().substring(0, (f.getName().indexOf(".")));
questPoints.put(name, data.getInt("quest-points"));
questPoints.put(data.getString("lastKnownName", "Unknown"),
data.getInt("quest-points", 0));
}
}
}
@ -561,24 +564,18 @@ public class CmdExecutor implements CommandExecutor {
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;
}
for (Entry<String, Integer> entry : sortedMap.entrySet()) {
numPrinted++;
cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + s + " - " + ChatColor.DARK_PURPLE
+ i + ChatColor.YELLOW + " " + Lang.get("questPoints"));
cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + entry.getKey() + " - "
+ ChatColor.DARK_PURPLE + entry.getValue() + ChatColor.YELLOW + " "
+ Lang.get("questPoints"));
if (numPrinted == topNumber) {
break;
}
}
}
});
}
return true;
}