Guest User

Untitled

a guest
Dec 7th, 2019
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package pw.navigations.qChronium.commands;
  2.  
  3. import com.hcrival.chronium.Chronium;
  4. import com.hcrival.chronium.profile.Profile;
  5. import com.hcrival.chronium.rank.Rank;
  6. import com.mongodb.client.MongoCollection;
  7. import org.bson.Document;
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandExecutor;
  12. import org.bukkit.command.CommandSender;
  13. import pw.navigations.qChronium.qChronium;
  14.  
  15. import java.util.ArrayList;
  16. import java.util.Comparator;
  17. import java.util.List;
  18. import java.util.UUID;
  19.  
  20. public class DumpCommand implements CommandExecutor {
  21.  
  22. @Override
  23. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  24. Bukkit.getScheduler().runTaskAsynchronously(qChronium.instance, () -> {
  25. List<Rank> ranks = new ArrayList<>(Rank.getRanks().values());
  26. ranks.sort(new Comparator<Rank>() {
  27. @Override
  28. public int compare(Rank o1, Rank o2) {
  29. return o2.getWeight() - o1.getWeight();
  30. }
  31. });
  32.  
  33. long ms = System.currentTimeMillis();
  34.  
  35. MongoCollection<Document> collection = Chronium.get().getMongoDatabase().getCollection("profiles");
  36.  
  37. for (Document document : collection.find()) {
  38. Profile profile = Profile.getByUuid(UUID.fromString((String) document.get("uuid")));
  39.  
  40. qChronium.instance.getConfig().set("DATA.PROFILES." + profile.getUuid() + ".RANK", ChatColor.stripColor(profile.getActiveGrant().getRank().getDisplayName()));
  41. qChronium.instance.getConfig().set("DATA.PROFILES." + profile.getUuid() + ".PERMISSIONS", profile.getPermissions());
  42. qChronium.instance.getConfig().set("DATA.PROFILES." + profile.getUuid() + ".ADDRESSES", profile.getIpAddresses());
  43.  
  44. Bukkit.broadcastMessage(profile.getUuid().toString());
  45. }
  46.  
  47. for (Rank rank : ranks) {
  48. ArrayList<String> inheritedNames = new ArrayList<>();
  49.  
  50. qChronium.instance.getConfig().set("DATA.RANKS." + ChatColor.stripColor(rank.getDisplayName()) + ".PREFIX", rank.getPrefix());
  51. qChronium.instance.getConfig().set("DATA.RANKS." + ChatColor.stripColor(rank.getDisplayName()) + ".COLOR", rank.getColor());
  52. qChronium.instance.getConfig().set("DATA.RANKS." + ChatColor.stripColor(rank.getDisplayName()) + ".DISPLAY_NAME", rank.getDisplayName());
  53. qChronium.instance.getConfig().set("DATA.RANKS." + ChatColor.stripColor(rank.getDisplayName()) + ".WEIGHT", rank.getWeight());
  54. qChronium.instance.getConfig().set("DATA.RANKS." + ChatColor.stripColor(rank.getDisplayName()) + ".UUID", rank.getUuid().toString());
  55. qChronium.instance.getConfig().set("DATA.RANKS." + ChatColor.stripColor(rank.getDisplayName()) + ".PERMISSIONS", rank.getPermissions());
  56. qChronium.instance.getConfig().set("DATA.RANKS." + ChatColor.stripColor(rank.getDisplayName()) + ".ALL_PERMISSIONS", rank.getAllPermissions());
  57.  
  58. for (Rank r : rank.getInherited()) {
  59. inheritedNames.add(ChatColor.stripColor(r.getDisplayName()));
  60. }
  61.  
  62. qChronium.instance.getConfig().set("DATA.RANKS." + ChatColor.stripColor(rank.getDisplayName()) + ".INHERITED", inheritedNames);
  63.  
  64. }
  65.  
  66. qChronium.instance.saveConfig();
  67.  
  68. Bukkit.broadcastMessage("┬žaComplete. That took " + (System.currentTimeMillis() - ms) + "ms.");
  69. });
  70.  
  71. return false;
  72. }
  73.  
  74. }
RAW Paste Data