Files
2021-09-03 18:31:01 +08:00

206 lines
9.4 KiB
Diff

--- ../src-base/minecraft/net/minecraft/server/management/PlayerProfileCache.java
+++ ../src-work/minecraft/net/minecraft/server/management/PlayerProfileCache.java
@@ -45,9 +45,9 @@
{
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
private static boolean onlineMode;
- private final Map<String, PlayerProfileCache.ProfileEntry> usernameToProfileEntryMap = Maps.<String, PlayerProfileCache.ProfileEntry>newHashMap();
- private final Map<UUID, PlayerProfileCache.ProfileEntry> uuidToProfileEntryMap = Maps.<UUID, PlayerProfileCache.ProfileEntry>newHashMap();
- private final Deque<GameProfile> gameProfiles = Lists.<GameProfile>newLinkedList();
+ private final Map<String, ProfileEntry> usernameToProfileEntryMap = Maps.<String, ProfileEntry>newHashMap();
+ private final Map<UUID, ProfileEntry> uuidToProfileEntryMap = Maps.<UUID, ProfileEntry>newHashMap();
+ private final Deque<GameProfile> gameProfiles = new java.util.concurrent.LinkedBlockingDeque<>();
private final GameProfileRepository profileRepo;
protected final Gson gson;
private final File usercacheFile;
@@ -55,7 +55,7 @@
{
public Type[] getActualTypeArguments()
{
- return new Type[] {PlayerProfileCache.ProfileEntry.class};
+ return new Type[] {ProfileEntry.class};
}
public Type getRawType()
{
@@ -72,7 +72,7 @@
this.profileRepo = profileRepoIn;
this.usercacheFile = usercacheFileIn;
GsonBuilder gsonbuilder = new GsonBuilder();
- gsonbuilder.registerTypeHierarchyAdapter(PlayerProfileCache.ProfileEntry.class, new PlayerProfileCache.Serializer());
+ gsonbuilder.registerTypeHierarchyAdapter(ProfileEntry.class, new Serializer());
this.gson = gsonbuilder.create();
this.load();
}
@@ -91,6 +91,7 @@
agameprofile[0] = null;
}
};
+ if (!catserver.server.CatServer.getConfig().disableUpdateGameProfile || isOnlineMode()) // CatServer
profileRepoIn.findProfilesByNames(new String[] {name}, Agent.MINECRAFT, profilelookupcallback);
if (!isOnlineMode() && agameprofile[0] == null)
@@ -118,7 +119,7 @@
this.addEntry(gameProfile, (Date)null);
}
- private void addEntry(GameProfile gameProfile, Date expirationDate)
+ private synchronized void addEntry(GameProfile gameProfile, Date expirationDate) // Paper - synchronize
{
UUID uuid = gameProfile.getId();
@@ -131,11 +132,11 @@
}
String s = gameProfile.getName().toLowerCase(Locale.ROOT);
- PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = new PlayerProfileCache.ProfileEntry(gameProfile, expirationDate);
+ ProfileEntry playerprofilecache$profileentry = new ProfileEntry(gameProfile, expirationDate);
- if (this.uuidToProfileEntryMap.containsKey(uuid))
- {
- PlayerProfileCache.ProfileEntry playerprofilecache$profileentry1 = this.uuidToProfileEntryMap.get(uuid);
+ // if (this.uuidToProfileEntryMap.containsKey(uuid)) { // Paper
+ ProfileEntry playerprofilecache$profileentry1 = this.uuidToProfileEntryMap.get(uuid);
+ if (playerprofilecache$profileentry1 != null) { // Paper
this.usernameToProfileEntryMap.remove(playerprofilecache$profileentry1.getGameProfile().getName().toLowerCase(Locale.ROOT));
this.gameProfiles.remove(gameProfile);
}
@@ -143,14 +144,14 @@
this.usernameToProfileEntryMap.put(gameProfile.getName().toLowerCase(Locale.ROOT), playerprofilecache$profileentry);
this.uuidToProfileEntryMap.put(uuid, playerprofilecache$profileentry);
this.gameProfiles.addFirst(gameProfile);
- this.save();
+ if(!org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) this.save(); // Spigot - skip saving if disabled
}
@Nullable
- public GameProfile getGameProfileForUsername(String username)
+ public synchronized GameProfile getGameProfileForUsername(String username) // Paper - synchronize
{
String s = username.toLowerCase(Locale.ROOT);
- PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.usernameToProfileEntryMap.get(s);
+ ProfileEntry playerprofilecache$profileentry = this.usernameToProfileEntryMap.get(s);
if (playerprofilecache$profileentry != null && (new Date()).getTime() >= playerprofilecache$profileentry.expirationDate.getTime())
{
@@ -177,26 +178,26 @@
}
}
- this.save();
+ if(!org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) this.save(); // Spigot - skip saving if disabled
return playerprofilecache$profileentry == null ? null : playerprofilecache$profileentry.getGameProfile();
}
- public String[] getUsernames()
+ public synchronized String[] getUsernames() // Paper - synchronize
{
List<String> list = Lists.newArrayList(this.usernameToProfileEntryMap.keySet());
return (String[])list.toArray(new String[list.size()]);
}
@Nullable
- public GameProfile getProfileByUUID(UUID uuid)
+ public synchronized GameProfile getProfileByUUID(UUID uuid) // Paper - synchronize
{
- PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.uuidToProfileEntryMap.get(uuid);
+ ProfileEntry playerprofilecache$profileentry = this.uuidToProfileEntryMap.get(uuid);
return playerprofilecache$profileentry == null ? null : playerprofilecache$profileentry.getGameProfile();
}
- private PlayerProfileCache.ProfileEntry getByUUID(UUID uuid)
+ private ProfileEntry getByUUID(UUID uuid)
{
- PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.uuidToProfileEntryMap.get(uuid);
+ ProfileEntry playerprofilecache$profileentry = this.uuidToProfileEntryMap.get(uuid);
if (playerprofilecache$profileentry != null)
{
@@ -215,14 +216,14 @@
try
{
bufferedreader = Files.newReader(this.usercacheFile, StandardCharsets.UTF_8);
- List<PlayerProfileCache.ProfileEntry> list = (List)JsonUtils.fromJson(this.gson, bufferedreader, TYPE);
+ List<ProfileEntry> list = (List)JsonUtils.fromJson(this.gson, bufferedreader, TYPE);
this.usernameToProfileEntryMap.clear();
this.uuidToProfileEntryMap.clear();
this.gameProfiles.clear();
if (list != null)
{
- for (PlayerProfileCache.ProfileEntry playerprofilecache$profileentry : Lists.reverse(list))
+ for (ProfileEntry playerprofilecache$profileentry : Lists.reverse(list))
{
if (playerprofilecache$profileentry != null)
{
@@ -245,9 +246,16 @@
}
}
+ // Paper start
public void save()
{
- String s = this.gson.toJson(this.getEntriesWithLimit(1000));
+ save(true);
+ }
+ public void save(boolean asyncSave)
+ {
+ // Paper end
+ String s = this.gson.toJson(this.getEntriesWithLimit(org.spigotmc.SpigotConfig.userCacheCap)); // Spigot
+ Runnable save = () -> {
BufferedWriter bufferedwriter = null;
try
@@ -268,15 +276,24 @@
{
IOUtils.closeQuietly((Writer)bufferedwriter);
}
+ // Paper start
+ };
+ if (asyncSave) {
+ catserver.server.CatServer.scheduleAsyncTask(save);
+ } else {
+ save.run();
+ }
+ // Paper end
+
}
- private List<PlayerProfileCache.ProfileEntry> getEntriesWithLimit(int limitSize)
+ private List<ProfileEntry> getEntriesWithLimit(int limitSize)
{
- List<PlayerProfileCache.ProfileEntry> list = Lists.<PlayerProfileCache.ProfileEntry>newArrayList();
+ List<ProfileEntry> list = Lists.<ProfileEntry>newArrayList();
for (GameProfile gameprofile : Lists.newArrayList(Iterators.limit(this.gameProfiles.iterator(), limitSize)))
{
- PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.getByUUID(gameprofile.getId());
+ ProfileEntry playerprofilecache$profileentry = this.getByUUID(gameprofile.getId());
if (playerprofilecache$profileentry != null)
{
@@ -309,13 +326,13 @@
}
}
- class Serializer implements JsonDeserializer<PlayerProfileCache.ProfileEntry>, JsonSerializer<PlayerProfileCache.ProfileEntry>
+ class Serializer implements JsonDeserializer<ProfileEntry>, JsonSerializer<ProfileEntry>
{
private Serializer()
{
}
- public JsonElement serialize(PlayerProfileCache.ProfileEntry p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
+ public JsonElement serialize(ProfileEntry p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
JsonObject jsonobject = new JsonObject();
jsonobject.addProperty("name", p_serialize_1_.getGameProfile().getName());
@@ -325,7 +342,7 @@
return jsonobject;
}
- public PlayerProfileCache.ProfileEntry deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
+ public ProfileEntry deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
if (p_deserialize_1_.isJsonObject())
{