1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
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;
|