2024-12-11 22:26:55 +01:00
|
|
|
--- a/net/minecraft/server/players/GameProfileCache.java
|
|
|
|
+++ b/net/minecraft/server/players/GameProfileCache.java
|
2016-07-17 02:11:17 +02:00
|
|
|
@@ -85,10 +85,11 @@
|
2023-12-05 17:40:00 +01:00
|
|
|
}
|
2021-04-07 07:03:29 +02:00
|
|
|
|
2023-12-05 17:40:00 +01:00
|
|
|
public void onProfileLookupFailed(String s1, Exception exception) {
|
|
|
|
- atomicreference.set((Object) null);
|
|
|
|
+ atomicreference.set(null); // CraftBukkit - decompile error
|
|
|
|
}
|
|
|
|
};
|
2021-04-07 07:03:29 +02:00
|
|
|
|
2016-07-17 02:11:17 +02:00
|
|
|
+ if (!org.apache.commons.lang3.StringUtils.isBlank(name)) // Paper - Don't lookup a profile with a blank name
|
|
|
|
repository.findProfilesByNames(new String[]{name}, profilelookupcallback);
|
|
|
|
GameProfile gameprofile = (GameProfile) atomicreference.get();
|
|
|
|
|
|
|
|
@@ -117,7 +118,7 @@
|
2014-05-24 00:05:10 +02:00
|
|
|
GameProfileCache.GameProfileInfo usercache_usercacheentry = new GameProfileCache.GameProfileInfo(profile, date);
|
|
|
|
|
|
|
|
this.safeAdd(usercache_usercacheentry);
|
|
|
|
- this.save();
|
2016-05-17 02:47:41 +02:00
|
|
|
+ if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(true); // Spigot - skip saving if disabled // Paper - Perf: Async GameProfileCache saving
|
2014-05-24 00:05:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private long getNextOperation() {
|
2016-07-17 02:11:17 +02:00
|
|
|
@@ -142,15 +143,15 @@
|
2023-12-26 04:33:31 +01:00
|
|
|
usercache_usercacheentry.setLastAccess(this.getNextOperation());
|
|
|
|
optional = Optional.of(usercache_usercacheentry.getProfile());
|
|
|
|
} else {
|
2024-12-11 22:26:55 +01:00
|
|
|
- optional = GameProfileCache.lookupGameProfile(this.profileRepository, s1);
|
|
|
|
+ optional = GameProfileCache.lookupGameProfile(this.profileRepository, name); // CraftBukkit - use correct case for offline players
|
2023-12-26 04:33:31 +01:00
|
|
|
if (optional.isPresent()) {
|
|
|
|
this.add((GameProfile) optional.get());
|
|
|
|
flag = false;
|
2014-05-24 00:05:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (flag) {
|
2016-05-17 02:47:41 +02:00
|
|
|
- this.save();
|
2014-05-24 00:05:10 +02:00
|
|
|
+ if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
|
2016-05-17 02:47:41 +02:00
|
|
|
+ this.save(true); // Paper - Perf: Async GameProfileCache saving
|
2014-05-24 00:05:10 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 02:47:41 +02:00
|
|
|
return optional;
|
2016-07-17 02:11:17 +02:00
|
|
|
@@ -208,7 +209,7 @@
|
2024-04-23 17:15:00 +02:00
|
|
|
|
|
|
|
label54:
|
|
|
|
{
|
|
|
|
- ArrayList arraylist;
|
2024-12-11 22:26:55 +01:00
|
|
|
+ List<GameProfileCache.GameProfileInfo> arraylist; // CraftBukkit - decompile error
|
2024-04-23 17:15:00 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
JsonArray jsonarray = (JsonArray) this.gson.fromJson(bufferedreader, JsonArray.class);
|
2016-07-17 02:11:17 +02:00
|
|
|
@@ -217,7 +218,7 @@
|
2024-12-11 22:26:55 +01:00
|
|
|
DateFormat dateformat = GameProfileCache.createDateFormat();
|
2024-04-23 17:15:00 +02:00
|
|
|
|
|
|
|
jsonarray.forEach((jsonelement) -> {
|
2024-12-11 22:26:55 +01:00
|
|
|
- Optional optional = GameProfileCache.readGameProfile(jsonelement, dateformat);
|
|
|
|
+ Optional<GameProfileCache.GameProfileInfo> optional = GameProfileCache.readGameProfile(jsonelement, dateformat); // CraftBukkit - decompile error
|
2024-04-23 17:15:00 +02:00
|
|
|
|
|
|
|
Objects.requireNonNull(list);
|
|
|
|
optional.ifPresent(list::add);
|
2016-07-17 02:11:17 +02:00
|
|
|
@@ -250,6 +251,11 @@
|
2014-07-08 01:44:18 +02:00
|
|
|
}
|
|
|
|
} 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);
|
|
|
|
}
|
2016-07-17 02:11:17 +02:00
|
|
|
@@ -257,14 +263,15 @@
|
2016-05-17 02:47:41 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
- public void save() {
|
|
|
|
+ public void save(boolean asyncSave) { // Paper - Perf: Async GameProfileCache saving
|
2014-04-26 00:17:30 +02:00
|
|
|
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);
|
2016-05-17 02:47:41 +02:00
|
|
|
+ Runnable save = () -> { // Paper - Perf: Async GameProfileCache saving
|
|
|
|
|
|
|
|
try {
|
|
|
|
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
|
2016-07-17 02:11:17 +02:00
|
|
|
@@ -289,6 +296,14 @@
|
2016-05-17 02:47:41 +02:00
|
|
|
} 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
|
|
|
|
|
|
|
|
}
|
|
|
|
|