--- a/net/minecraft/server/players/GameProfileCache.java +++ b/net/minecraft/server/players/GameProfileCache.java @@ -85,10 +85,12 @@ } public void onProfileLookupFailed(String s1, Exception exception) { - atomicreference.set((Object) null); + atomicreference.set(null); // CraftBukkit - decompile error } }; + if (!org.apache.commons.lang3.StringUtils.isBlank(name) // Paper - Don't lookup a profile with a blank name + && io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()) // Paper - Add setting for proxy online mode status repository.findProfilesByNames(new String[]{name}, profilelookupcallback); GameProfile gameprofile = (GameProfile) atomicreference.get(); @@ -105,7 +107,7 @@ } private static boolean usesAuthentication() { - return GameProfileCache.usesAuthentication; + return io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode(); // Paper - Add setting for proxy online mode status } public void add(GameProfile profile) { @@ -117,13 +119,24 @@ 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() { return this.operationCount.incrementAndGet(); } + // Paper start + public @Nullable GameProfile getProfileIfCached(String name) { + GameProfileCache.GameProfileInfo entry = this.profilesByName.get(name.toLowerCase(Locale.ROOT)); + if (entry == null) { + return null; + } + entry.setLastAccess(this.getNextOperation()); + return entry.getProfile(); + } + // Paper end + public Optional get(String name) { String s1 = name.toLowerCase(Locale.ROOT); GameProfileCache.GameProfileInfo usercache_usercacheentry = (GameProfileCache.GameProfileInfo) this.profilesByName.get(s1); @@ -142,15 +155,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; @@ -167,7 +180,7 @@ } else { CompletableFuture> completablefuture1 = CompletableFuture.supplyAsync(() -> { return this.get(username); - }, Util.backgroundExecutor().forName("getProfile")).whenCompleteAsync((optional, throwable) -> { + }, Util.PROFILE_EXECUTOR).whenCompleteAsync((optional, throwable) -> { // Paper - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread this.requests.remove(username); }, this.executor); @@ -208,7 +221,7 @@ label54: { - ArrayList arraylist; + List arraylist; // CraftBukkit - decompile error try { JsonArray jsonarray = (JsonArray) this.gson.fromJson(bufferedreader, JsonArray.class); @@ -217,7 +230,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 +263,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 +275,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 +308,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 }