Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. public void load() throws Exception {
  2. final Document document = PracticePlayer.collection.find(Filters.eq("uuid", this.uuid.toString())).first();
  3. if (document == null) {
  4. this.save();
  5. return;
  6. }
  7. final Document options = (Document)document.get("settings");
  8.  
  9. this.settings.setAllowScoreboard(options.getBoolean("scoreboard"));
  10. this.settings.setGiveBookKit(options.getBoolean("bookKit"));
  11. this.settings.setAllowDuels(options.getBoolean("duelRequests"));
  12. this.settings.setAllowPlayers(options.getBoolean("players"));
  13. this.settings.setScoreboardPing(options.getBoolean("scoreboardPing"));
  14. this.settings.setAllowSpectators(options.getBoolean("spectators"));
  15.  
  16.  
  17. final Document kitStatistics = (Document)document.get("kitStatistics");
  18.  
  19. for (final String key : kitStatistics.keySet()) {
  20. final Document kitDocument = (Document)kitStatistics.get(key);
  21. final Kit kit = Kit.getByName(key);
  22. if (kit != null) {
  23. final PracticeKitData profileKitData = new PracticeKitData();
  24. profileKitData.setElo(kitDocument.getInteger("elo"));
  25. profileKitData.setUnrankedWon(kitDocument.getInteger("unrankedWon"));
  26. profileKitData.setUnrankedLost(kitDocument.getInteger("unrankedLost"));
  27. profileKitData.setUnrankedPlayed(kitDocument.getInteger("unrankedPlayed"));
  28. profileKitData.setRankedWon(kitDocument.getInteger("rankedWon"));
  29. profileKitData.setRankedLost(kitDocument.getInteger("rankedLost"));
  30. profileKitData.setRankedPlayed(kitDocument.getInteger("rankedPlayed"));
  31. this.kitData.put(kit, profileKitData);
  32. }
  33. }
  34.  
  35. final Document kitsDocument = (Document)document.get("loadouts");
  36.  
  37. for (final String key : kitsDocument.keySet()) {
  38. final Document kitDocument = (Document)kitsDocument.get(key);
  39. final Kit kit = Kit.getByName(key);
  40.  
  41. if (kit != null) {
  42. KitLoadout loadout = new KitLoadout();
  43. loadout.setCustomName(kitDocument.getString("name"));
  44. loadout.setArmor(InventoryUtil.deserializeInventory(kitDocument.getString("armor")));
  45. loadout.setContents(InventoryUtil.deserializeInventory(kitDocument.getString("contents")));
  46.  
  47. this.kitData.get(kit).setLoadout(loadout);
  48. }
  49. }
  50. }
  51.  
  52. public void save() {
  53. final Document document = new Document();
  54. document.put("uuid", this.uuid.toString());
  55.  
  56. final Document optionsDocument = new Document();
  57.  
  58. optionsDocument.put("scoreboard", this.settings.isAllowScoreboard());
  59. optionsDocument.put("bookKit", this.settings.isGiveBookKit());
  60. optionsDocument.put("duelRequests", this.settings.isAllowDuels());
  61. optionsDocument.put("players", this.settings.isAllowPlayers());
  62. optionsDocument.put("scoreboardPing", this.settings.isScoreboardPing());
  63. optionsDocument.put("spectators", this.settings.isAllowSpectators());
  64.  
  65. document.put("settings", optionsDocument);
  66.  
  67. final Document totalStatisticsDocument = new Document();
  68.  
  69. totalStatisticsDocument.put("globalElo", this.getGlobalELO());
  70. totalStatisticsDocument.put("unrankedWon", this.getTotalUnrankedWon());
  71. totalStatisticsDocument.put("unrankedLost", this.getTotalUnrankedLost());
  72. totalStatisticsDocument.put("unrankedPlayed", this.getTotalUnrankedPlayed());
  73. totalStatisticsDocument.put("rankedWon", this.getTotalRankedWon());
  74. totalStatisticsDocument.put("rankedLost", this.getTotalRankedLost());
  75. totalStatisticsDocument.put("rankedPlayed", this.getTotalRankedPlayed());
  76. totalStatisticsDocument.put("gamesWon", this.getTotalGamesWon());
  77. totalStatisticsDocument.put("gamesLost", this.getTotalGamesLost());
  78. totalStatisticsDocument.put("gamesPlayed", this.getTotalGamesPlayed());
  79.  
  80. document.put("totalStatistics", totalStatisticsDocument);
  81.  
  82. final Document kitStatisticsDocument = new Document();
  83.  
  84. for (final Map.Entry<Kit, PracticeKitData> entry : this.kitData.entrySet()) {
  85. final Document kitDocument = new Document();
  86. kitDocument.put("elo", entry.getValue().getElo());
  87. kitDocument.put("unrankedWon", entry.getValue().getUnrankedWon());
  88. kitDocument.put("unrankedLost", entry.getValue().getUnrankedLost());
  89. kitDocument.put("unrankedPlayed", entry.getValue().getUnrankedPlayed());
  90. kitDocument.put("rankedWon", entry.getValue().getRankedWon());
  91. kitDocument.put("rankedLost", entry.getValue().getRankedLost());
  92. kitDocument.put("rankedPlayed", entry.getValue().getRankedPlayed());
  93. kitStatisticsDocument.put(entry.getKey().getName(), kitDocument);
  94. }
  95.  
  96. document.put("kitStatistics", kitStatisticsDocument);
  97.  
  98. final Document kitsDocument = new Document();
  99.  
  100. for (final Map.Entry<Kit, PracticeKitData> entry2 : this.kitData.entrySet()) {
  101. if(entry2.getValue().getLoadout() != null){
  102. final Document kitDocument = new Document();
  103. final KitLoadout kitLoadout = entry2.getValue().getLoadout();
  104.  
  105. kitDocument.put("name", kitLoadout.getCustomName());
  106. kitDocument.put("armor", InventoryUtil.serializeInventory(kitLoadout.getArmor()));
  107. kitDocument.put("contents", InventoryUtil.serializeInventory(kitLoadout.getContents()));
  108.  
  109. kitsDocument.put(entry2.getKey().getName(), kitDocument);
  110. }
  111. }
  112.  
  113. document.put("loadouts", kitsDocument);
  114.  
  115. PracticePlayer.collection.replaceOne(Filters.eq("uuid", this.uuid.toString()), document, new ReplaceOptions().upsert(true));
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement