aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/server/players/GameProfileCache.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/server/players/GameProfileCache.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/server/players/GameProfileCache.java.patch416
1 files changed, 416 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/server/players/GameProfileCache.java.patch b/patch-remap/mache-vineflower/net/minecraft/server/players/GameProfileCache.java.patch
new file mode 100644
index 0000000000..2181de7a61
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/server/players/GameProfileCache.java.patch
@@ -0,0 +1,416 @@
+--- a/net/minecraft/server/players/GameProfileCache.java
++++ b/net/minecraft/server/players/GameProfileCache.java
+@@ -1,3 +1,4 @@
++// mc-dev import
+ package net.minecraft.server.players;
+
+ import com.google.common.collect.ImmutableList;
+@@ -14,21 +15,23 @@
+ import com.mojang.authlib.GameProfileRepository;
+ import com.mojang.authlib.ProfileLookupCallback;
+ import com.mojang.logging.LogUtils;
++import java.io.BufferedReader;
++import java.io.BufferedWriter;
+ import java.io.File;
+ import java.io.FileNotFoundException;
+ import java.io.IOException;
+-import java.io.Reader;
+-import java.io.Writer;
+ import java.nio.charset.StandardCharsets;
+ import java.text.DateFormat;
+ import java.text.ParseException;
+ import java.text.SimpleDateFormat;
++import java.util.ArrayList;
+ import java.util.Calendar;
+ import java.util.Comparator;
+ import java.util.Date;
+ import java.util.List;
+ import java.util.Locale;
+ import java.util.Map;
++import java.util.Objects;
+ import java.util.Optional;
+ import java.util.UUID;
+ import java.util.concurrent.CompletableFuture;
+@@ -43,6 +46,7 @@
+ import org.slf4j.Logger;
+
+ public class GameProfileCache {
++
+ private static final Logger LOGGER = LogUtils.getLogger();
+ private static final int GAMEPROFILES_MRU_LIMIT = 1000;
+ private static final int GAMEPROFILES_EXPIRATION_MONTHS = 1;
+@@ -51,7 +55,7 @@
+ private final Map<UUID, GameProfileCache.GameProfileInfo> profilesByUUID = Maps.newConcurrentMap();
+ private final Map<String, CompletableFuture<Optional<GameProfile>>> requests = Maps.newConcurrentMap();
+ private final GameProfileRepository profileRepository;
+- private final Gson gson = new GsonBuilder().create();
++ private final Gson gson = (new GsonBuilder()).create();
+ private final File file;
+ private final AtomicLong operationCount = new AtomicLong();
+ @Nullable
+@@ -64,53 +68,56 @@
+ }
+
+ private void safeAdd(GameProfileCache.GameProfileInfo profile) {
+- GameProfile profile1 = profile.getProfile();
++ GameProfile gameprofile = profile.getProfile();
++
+ profile.setLastAccess(this.getNextOperation());
+- this.profilesByName.put(profile1.getName().toLowerCase(Locale.ROOT), profile);
+- this.profilesByUUID.put(profile1.getId(), profile);
++ this.profilesByName.put(gameprofile.getName().toLowerCase(Locale.ROOT), profile);
++ this.profilesByUUID.put(gameprofile.getId(), profile);
+ }
+
+ private static Optional<GameProfile> lookupGameProfile(GameProfileRepository profileRepo, String name) {
+ if (!Player.isValidUsername(name)) {
+ return createUnknownProfile(name);
+ } else {
+- final AtomicReference<GameProfile> atomicReference = new AtomicReference<>();
+- ProfileLookupCallback profileLookupCallback = new ProfileLookupCallback() {
+- @Override
+- public void onProfileLookupSucceeded(GameProfile profile) {
+- atomicReference.set(profile);
++ final AtomicReference<GameProfile> atomicreference = new AtomicReference();
++ ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() {
++ public void onProfileLookupSucceeded(GameProfile gameprofile) {
++ atomicreference.set(gameprofile);
+ }
+
+- @Override
+- public void onProfileLookupFailed(String string, Exception exception) {
+- atomicReference.set(null);
++ public void onProfileLookupFailed(String s1, Exception exception) {
++ atomicreference.set(null); // CraftBukkit - decompile error
+ }
+ };
+- profileRepo.findProfilesByNames(new String[]{name}, profileLookupCallback);
+- GameProfile gameProfile = atomicReference.get();
+- return gameProfile != null ? Optional.of(gameProfile) : createUnknownProfile(name);
++
++ profileRepo.findProfilesByNames(new String[]{name}, profilelookupcallback);
++ GameProfile gameprofile = (GameProfile) atomicreference.get();
++
++ return gameprofile != null ? Optional.of(gameprofile) : createUnknownProfile(name);
+ }
+ }
+
+- private static Optional<GameProfile> createUnknownProfile(String string) {
+- return usesAuthentication() ? Optional.empty() : Optional.of(UUIDUtil.createOfflineProfile(string));
++ private static Optional<GameProfile> createUnknownProfile(String s) {
++ return usesAuthentication() ? Optional.empty() : Optional.of(UUIDUtil.createOfflineProfile(s));
+ }
+
+ public static void setUsesAuthentication(boolean onlineMode) {
+- usesAuthentication = onlineMode;
++ GameProfileCache.usesAuthentication = onlineMode;
+ }
+
+ private static boolean usesAuthentication() {
+- return usesAuthentication;
++ return GameProfileCache.usesAuthentication;
+ }
+
+ public void add(GameProfile gameProfile) {
+- Calendar instance = Calendar.getInstance();
+- instance.setTime(new Date());
+- instance.add(2, 1);
+- Date time = instance.getTime();
+- GameProfileCache.GameProfileInfo gameProfileInfo = new GameProfileCache.GameProfileInfo(gameProfile, time);
+- this.safeAdd(gameProfileInfo);
++ Calendar calendar = Calendar.getInstance();
++
++ calendar.setTime(new Date());
++ calendar.add(2, 1);
++ Date date = calendar.getTime();
++ GameProfileCache.GameProfileInfo usercache_usercacheentry = new GameProfileCache.GameProfileInfo(gameProfile, date);
++
++ this.safeAdd(usercache_usercacheentry);
+ this.save();
+ }
+
+@@ -119,24 +126,26 @@
+ }
+
+ public Optional<GameProfile> get(String name) {
+- String string = name.toLowerCase(Locale.ROOT);
+- GameProfileCache.GameProfileInfo gameProfileInfo = this.profilesByName.get(string);
++ String s1 = name.toLowerCase(Locale.ROOT);
++ GameProfileCache.GameProfileInfo usercache_usercacheentry = (GameProfileCache.GameProfileInfo) this.profilesByName.get(s1);
+ boolean flag = false;
+- if (gameProfileInfo != null && new Date().getTime() >= gameProfileInfo.expirationDate.getTime()) {
+- this.profilesByUUID.remove(gameProfileInfo.getProfile().getId());
+- this.profilesByName.remove(gameProfileInfo.getProfile().getName().toLowerCase(Locale.ROOT));
++
++ if (usercache_usercacheentry != null && (new Date()).getTime() >= usercache_usercacheentry.expirationDate.getTime()) {
++ this.profilesByUUID.remove(usercache_usercacheentry.getProfile().getId());
++ this.profilesByName.remove(usercache_usercacheentry.getProfile().getName().toLowerCase(Locale.ROOT));
+ flag = true;
+- gameProfileInfo = null;
++ usercache_usercacheentry = null;
+ }
+
+- Optional<GameProfile> optional;
+- if (gameProfileInfo != null) {
+- gameProfileInfo.setLastAccess(this.getNextOperation());
+- optional = Optional.of(gameProfileInfo.getProfile());
++ Optional optional;
++
++ if (usercache_usercacheentry != null) {
++ usercache_usercacheentry.setLastAccess(this.getNextOperation());
++ optional = Optional.of(usercache_usercacheentry.getProfile());
+ } else {
+- optional = lookupGameProfile(this.profileRepository, string);
++ optional = lookupGameProfile(this.profileRepository, s1);
+ if (optional.isPresent()) {
+- this.add(optional.get());
++ this.add((GameProfile) optional.get());
+ flag = false;
+ }
+ }
+@@ -148,31 +157,35 @@
+ return optional;
+ }
+
+- public CompletableFuture<Optional<GameProfile>> getAsync(String string) {
++ public CompletableFuture<Optional<GameProfile>> getAsync(String s) {
+ if (this.executor == null) {
+ throw new IllegalStateException("No executor");
+ } else {
+- CompletableFuture<Optional<GameProfile>> completableFuture = this.requests.get(string);
+- if (completableFuture != null) {
+- return completableFuture;
++ CompletableFuture<Optional<GameProfile>> completablefuture = (CompletableFuture) this.requests.get(s);
++
++ if (completablefuture != null) {
++ return completablefuture;
+ } else {
+- CompletableFuture<Optional<GameProfile>> completableFuture1 = CompletableFuture.<Optional<GameProfile>>supplyAsync(
+- () -> this.get(string), Util.backgroundExecutor()
+- )
+- .whenCompleteAsync((optional, throwable) -> this.requests.remove(string), this.executor);
+- this.requests.put(string, completableFuture1);
+- return completableFuture1;
++ CompletableFuture<Optional<GameProfile>> completablefuture1 = CompletableFuture.supplyAsync(() -> {
++ return this.get(s);
++ }, Util.backgroundExecutor()).whenCompleteAsync((optional, throwable) -> {
++ this.requests.remove(s);
++ }, this.executor);
++
++ this.requests.put(s, completablefuture1);
++ return completablefuture1;
+ }
+ }
+ }
+
+ public Optional<GameProfile> get(UUID uuid) {
+- GameProfileCache.GameProfileInfo gameProfileInfo = this.profilesByUUID.get(uuid);
+- if (gameProfileInfo == null) {
++ GameProfileCache.GameProfileInfo usercache_usercacheentry = (GameProfileCache.GameProfileInfo) this.profilesByUUID.get(uuid);
++
++ if (usercache_usercacheentry == null) {
+ return Optional.empty();
+ } else {
+- gameProfileInfo.setLastAccess(this.getNextOperation());
+- return Optional.of(gameProfileInfo.getProfile());
++ usercache_usercacheentry.setLastAccess(this.getNextOperation());
++ return Optional.of(usercache_usercacheentry.getProfile());
+ }
+ }
+
+@@ -189,83 +202,140 @@
+ }
+
+ public List<GameProfileCache.GameProfileInfo> load() {
+- List<GameProfileCache.GameProfileInfo> list = Lists.newArrayList();
++ ArrayList arraylist = Lists.newArrayList();
+
+ try {
+- Object var9;
+- try (Reader reader = Files.newReader(this.file, StandardCharsets.UTF_8)) {
+- JsonArray jsonArray = this.gson.fromJson(reader, JsonArray.class);
+- if (jsonArray != null) {
+- DateFormat dateFormat = createDateFormat();
+- jsonArray.forEach(jsonElement -> readGameProfile(jsonElement, dateFormat).ifPresent(list::add));
+- return list;
++ BufferedReader bufferedreader = Files.newReader(this.file, StandardCharsets.UTF_8);
++
++ label54:
++ {
++ ArrayList arraylist1;
++
++ try {
++ JsonArray jsonarray = (JsonArray) this.gson.fromJson(bufferedreader, JsonArray.class);
++
++ if (jsonarray != null) {
++ DateFormat dateformat = createDateFormat();
++
++ jsonarray.forEach((jsonelement) -> {
++ Optional optional = readGameProfile(jsonelement, dateformat);
++
++ Objects.requireNonNull(arraylist);
++ optional.ifPresent(arraylist::add);
++ });
++ break label54;
++ }
++
++ arraylist1 = arraylist;
++ } catch (Throwable throwable) {
++ if (bufferedreader != null) {
++ try {
++ bufferedreader.close();
++ } catch (Throwable throwable1) {
++ throwable.addSuppressed(throwable1);
++ }
++ }
++
++ throw throwable;
+ }
+
+- var9 = list;
++ if (bufferedreader != null) {
++ bufferedreader.close();
++ }
++
++ return arraylist1;
+ }
+
+- return (List<GameProfileCache.GameProfileInfo>)var9;
+- } catch (FileNotFoundException var7) {
+- } catch (JsonParseException | IOException var8) {
+- LOGGER.warn("Failed to load profile cache {}", this.file, var8);
++ if (bufferedreader != null) {
++ bufferedreader.close();
++ }
++ } catch (FileNotFoundException filenotfoundexception) {
++ ;
++ } catch (JsonParseException | IOException ioexception) {
++ GameProfileCache.LOGGER.warn("Failed to load profile cache {}", this.file, ioexception);
+ }
+
+- return list;
++ return arraylist;
+ }
+
+ public void save() {
+- JsonArray jsonArray = new JsonArray();
+- DateFormat dateFormat = createDateFormat();
+- this.getTopMRUProfiles(1000).forEach(gameProfileInfo -> jsonArray.add(writeGameProfile(gameProfileInfo, dateFormat)));
+- String string = this.gson.toJson((JsonElement)jsonArray);
++ JsonArray jsonarray = new JsonArray();
++ DateFormat dateformat = createDateFormat();
+
+- try (Writer writer = Files.newWriter(this.file, StandardCharsets.UTF_8)) {
+- writer.write(string);
+- } catch (IOException var9) {
++ this.getTopMRUProfiles(1000).forEach((usercache_usercacheentry) -> {
++ jsonarray.add(writeGameProfile(usercache_usercacheentry, dateformat));
++ });
++ String s = this.gson.toJson(jsonarray);
++
++ try {
++ BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
++
++ try {
++ bufferedwriter.write(s);
++ } catch (Throwable throwable) {
++ if (bufferedwriter != null) {
++ try {
++ bufferedwriter.close();
++ } catch (Throwable throwable1) {
++ throwable.addSuppressed(throwable1);
++ }
++ }
++
++ throw throwable;
++ }
++
++ if (bufferedwriter != null) {
++ bufferedwriter.close();
++ }
++ } catch (IOException ioexception) {
++ ;
+ }
++
+ }
+
+ private Stream<GameProfileCache.GameProfileInfo> getTopMRUProfiles(int limit) {
+- return ImmutableList.copyOf(this.profilesByUUID.values())
+- .stream()
+- .sorted(Comparator.comparing(GameProfileCache.GameProfileInfo::getLastAccess).reversed())
+- .limit((long)limit);
++ return ImmutableList.copyOf(this.profilesByUUID.values()).stream().sorted(Comparator.comparing(GameProfileCache.GameProfileInfo::getLastAccess).reversed()).limit((long) limit);
+ }
+
+ private static JsonElement writeGameProfile(GameProfileCache.GameProfileInfo profileInfo, DateFormat dateFormat) {
+- JsonObject jsonObject = new JsonObject();
+- jsonObject.addProperty("name", profileInfo.getProfile().getName());
+- jsonObject.addProperty("uuid", profileInfo.getProfile().getId().toString());
+- jsonObject.addProperty("expiresOn", dateFormat.format(profileInfo.getExpirationDate()));
+- return jsonObject;
++ JsonObject jsonobject = new JsonObject();
++
++ jsonobject.addProperty("name", profileInfo.getProfile().getName());
++ jsonobject.addProperty("uuid", profileInfo.getProfile().getId().toString());
++ jsonobject.addProperty("expiresOn", dateFormat.format(profileInfo.getExpirationDate()));
++ return jsonobject;
+ }
+
+ private static Optional<GameProfileCache.GameProfileInfo> readGameProfile(JsonElement json, DateFormat dateFormat) {
+ if (json.isJsonObject()) {
+- JsonObject asJsonObject = json.getAsJsonObject();
+- JsonElement jsonElement = asJsonObject.get("name");
+- JsonElement jsonElement1 = asJsonObject.get("uuid");
+- JsonElement jsonElement2 = asJsonObject.get("expiresOn");
+- if (jsonElement != null && jsonElement1 != null) {
+- String asString = jsonElement1.getAsString();
+- String asString1 = jsonElement.getAsString();
++ JsonObject jsonobject = json.getAsJsonObject();
++ JsonElement jsonelement1 = jsonobject.get("name");
++ JsonElement jsonelement2 = jsonobject.get("uuid");
++ JsonElement jsonelement3 = jsonobject.get("expiresOn");
++
++ if (jsonelement1 != null && jsonelement2 != null) {
++ String s = jsonelement2.getAsString();
++ String s1 = jsonelement1.getAsString();
+ Date date = null;
+- if (jsonElement2 != null) {
++
++ if (jsonelement3 != null) {
+ try {
+- date = dateFormat.parse(jsonElement2.getAsString());
+- } catch (ParseException var12) {
++ date = dateFormat.parse(jsonelement3.getAsString());
++ } catch (ParseException parseexception) {
++ ;
+ }
+ }
+
+- if (asString1 != null && asString != null && date != null) {
+- UUID uUID;
++ if (s1 != null && s != null && date != null) {
++ UUID uuid;
++
+ try {
+- uUID = UUID.fromString(asString);
+- } catch (Throwable var11) {
++ uuid = UUID.fromString(s);
++ } catch (Throwable throwable) {
+ return Optional.empty();
+ }
+
+- return Optional.of(new GameProfileCache.GameProfileInfo(new GameProfile(uUID, asString1), date));
++ return Optional.of(new GameProfileCache.GameProfileInfo(new GameProfile(uuid, s1), date));
+ } else {
+ return Optional.empty();
+ }
+@@ -277,7 +347,8 @@
+ }
+ }
+
+- static class GameProfileInfo {
++ private static class GameProfileInfo {
++
+ private final GameProfile profile;
+ final Date expirationDate;
+ private volatile long lastAccess;