--- a/net/minecraft/server/players/GameProfileCache.java +++ b/net/minecraft/server/players/GameProfileCache.java @@ -85,7 +85,7 @@ } public void onProfileLookupFailed(String s1, Exception exception) { - atomicreference.set((Object) null); + atomicreference.set(null); // CraftBukkit - decompile error } }; @@ -117,7 +117,7 @@ GameProfileCache.GameProfileInfo usercache_usercacheentry = new GameProfileCache.GameProfileInfo(profile, date); this.safeAdd(usercache_usercacheentry); - this.save(); + if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(true); // Spigot - skip saving if disabled // Paper - Perf: Async GameProfileCache saving } private long getNextOperation() { @@ -142,15 +142,15 @@ usercache_usercacheentry.setLastAccess(this.getNextOperation()); optional = Optional.of(usercache_usercacheentry.getProfile()); } else { - optional = GameProfileCache.lookupGameProfile(this.profileRepository, s1); + optional = GameProfileCache.lookupGameProfile(this.profileRepository, name); // CraftBukkit - use correct case for offline players if (optional.isPresent()) { this.add((GameProfile) optional.get()); flag = false; } } - if (flag) { - this.save(); + if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled + this.save(true); // Paper - Perf: Async GameProfileCache saving } return optional; @@ -208,7 +208,7 @@ label54: { - ArrayList arraylist; + List arraylist; // CraftBukkit - decompile error try { JsonArray jsonarray = (JsonArray) this.gson.fromJson(bufferedreader, JsonArray.class); @@ -217,7 +217,7 @@ DateFormat dateformat = GameProfileCache.createDateFormat(); jsonarray.forEach((jsonelement) -> { - Optional optional = GameProfileCache.readGameProfile(jsonelement, dateformat); + Optional optional = GameProfileCache.readGameProfile(jsonelement, dateformat); // CraftBukkit - decompile error Objects.requireNonNull(list); optional.ifPresent(list::add); @@ -250,6 +250,11 @@ } } catch (FileNotFoundException filenotfoundexception) { ; + // Spigot Start + } catch (com.google.gson.JsonSyntaxException | NullPointerException ex) { + GameProfileCache.LOGGER.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." ); + this.file.delete(); + // Spigot End } catch (JsonParseException | IOException ioexception) { GameProfileCache.LOGGER.warn("Failed to load profile cache {}", this.file, ioexception); } @@ -257,14 +262,15 @@ return list; } - public void save() { + public void save(boolean asyncSave) { // Paper - Perf: Async GameProfileCache saving JsonArray jsonarray = new JsonArray(); DateFormat dateformat = GameProfileCache.createDateFormat(); - this.getTopMRUProfiles(1000).forEach((usercache_usercacheentry) -> { + this.getTopMRUProfiles(org.spigotmc.SpigotConfig.userCacheCap).forEach((usercache_usercacheentry) -> { // Spigot jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat)); }); String s = this.gson.toJson(jsonarray); + Runnable save = () -> { // Paper - Perf: Async GameProfileCache saving try { BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8); @@ -289,6 +295,14 @@ } catch (IOException ioexception) { ; } + // Paper start - Perf: Async GameProfileCache saving + }; + if (asyncSave) { + io.papermc.paper.util.MCUtil.scheduleAsyncTask(save); + } else { + save.run(); + } + // Paper end - Perf: Async GameProfileCache saving }