mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-24 11:38:42 +01:00
Run lookup for /quests top asynchronously
This commit is contained in:
parent
63579df80e
commit
4d23408e97
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user