Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void load() throws Exception {
- final Document document = PracticePlayer.collection.find(Filters.eq("uuid", this.uuid.toString())).first();
- if (document == null) {
- this.save();
- return;
- }
- final Document options = (Document)document.get("settings");
- this.settings.setAllowScoreboard(options.getBoolean("scoreboard"));
- this.settings.setGiveBookKit(options.getBoolean("bookKit"));
- this.settings.setAllowDuels(options.getBoolean("duelRequests"));
- this.settings.setAllowPlayers(options.getBoolean("players"));
- this.settings.setScoreboardPing(options.getBoolean("scoreboardPing"));
- this.settings.setAllowSpectators(options.getBoolean("spectators"));
- final Document kitStatistics = (Document)document.get("kitStatistics");
- for (final String key : kitStatistics.keySet()) {
- final Document kitDocument = (Document)kitStatistics.get(key);
- final Kit kit = Kit.getByName(key);
- if (kit != null) {
- final PracticeKitData profileKitData = new PracticeKitData();
- profileKitData.setElo(kitDocument.getInteger("elo"));
- profileKitData.setUnrankedWon(kitDocument.getInteger("unrankedWon"));
- profileKitData.setUnrankedLost(kitDocument.getInteger("unrankedLost"));
- profileKitData.setUnrankedPlayed(kitDocument.getInteger("unrankedPlayed"));
- profileKitData.setRankedWon(kitDocument.getInteger("rankedWon"));
- profileKitData.setRankedLost(kitDocument.getInteger("rankedLost"));
- profileKitData.setRankedPlayed(kitDocument.getInteger("rankedPlayed"));
- this.kitData.put(kit, profileKitData);
- }
- }
- final Document kitsDocument = (Document)document.get("loadouts");
- for (final String key : kitsDocument.keySet()) {
- final Document kitDocument = (Document)kitsDocument.get(key);
- final Kit kit = Kit.getByName(key);
- if (kit != null) {
- KitLoadout loadout = new KitLoadout();
- loadout.setCustomName(kitDocument.getString("name"));
- loadout.setArmor(InventoryUtil.deserializeInventory(kitDocument.getString("armor")));
- loadout.setContents(InventoryUtil.deserializeInventory(kitDocument.getString("contents")));
- this.kitData.get(kit).setLoadout(loadout);
- }
- }
- }
- public void save() {
- final Document document = new Document();
- document.put("uuid", this.uuid.toString());
- final Document optionsDocument = new Document();
- optionsDocument.put("scoreboard", this.settings.isAllowScoreboard());
- optionsDocument.put("bookKit", this.settings.isGiveBookKit());
- optionsDocument.put("duelRequests", this.settings.isAllowDuels());
- optionsDocument.put("players", this.settings.isAllowPlayers());
- optionsDocument.put("scoreboardPing", this.settings.isScoreboardPing());
- optionsDocument.put("spectators", this.settings.isAllowSpectators());
- document.put("settings", optionsDocument);
- final Document totalStatisticsDocument = new Document();
- totalStatisticsDocument.put("globalElo", this.getGlobalELO());
- totalStatisticsDocument.put("unrankedWon", this.getTotalUnrankedWon());
- totalStatisticsDocument.put("unrankedLost", this.getTotalUnrankedLost());
- totalStatisticsDocument.put("unrankedPlayed", this.getTotalUnrankedPlayed());
- totalStatisticsDocument.put("rankedWon", this.getTotalRankedWon());
- totalStatisticsDocument.put("rankedLost", this.getTotalRankedLost());
- totalStatisticsDocument.put("rankedPlayed", this.getTotalRankedPlayed());
- totalStatisticsDocument.put("gamesWon", this.getTotalGamesWon());
- totalStatisticsDocument.put("gamesLost", this.getTotalGamesLost());
- totalStatisticsDocument.put("gamesPlayed", this.getTotalGamesPlayed());
- document.put("totalStatistics", totalStatisticsDocument);
- final Document kitStatisticsDocument = new Document();
- for (final Map.Entry<Kit, PracticeKitData> entry : this.kitData.entrySet()) {
- final Document kitDocument = new Document();
- kitDocument.put("elo", entry.getValue().getElo());
- kitDocument.put("unrankedWon", entry.getValue().getUnrankedWon());
- kitDocument.put("unrankedLost", entry.getValue().getUnrankedLost());
- kitDocument.put("unrankedPlayed", entry.getValue().getUnrankedPlayed());
- kitDocument.put("rankedWon", entry.getValue().getRankedWon());
- kitDocument.put("rankedLost", entry.getValue().getRankedLost());
- kitDocument.put("rankedPlayed", entry.getValue().getRankedPlayed());
- kitStatisticsDocument.put(entry.getKey().getName(), kitDocument);
- }
- document.put("kitStatistics", kitStatisticsDocument);
- final Document kitsDocument = new Document();
- for (final Map.Entry<Kit, PracticeKitData> entry2 : this.kitData.entrySet()) {
- if(entry2.getValue().getLoadout() != null){
- final Document kitDocument = new Document();
- final KitLoadout kitLoadout = entry2.getValue().getLoadout();
- kitDocument.put("name", kitLoadout.getCustomName());
- kitDocument.put("armor", InventoryUtil.serializeInventory(kitLoadout.getArmor()));
- kitDocument.put("contents", InventoryUtil.serializeInventory(kitLoadout.getContents()));
- kitsDocument.put(entry2.getKey().getName(), kitDocument);
- }
- }
- document.put("loadouts", kitsDocument);
- PracticePlayer.collection.replaceOne(Filters.eq("uuid", this.uuid.toString()), document, new ReplaceOptions().upsert(true));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement