Skip to content

Commit

Permalink
Backwards-compatibility: use older method for parsing JsonReader
Browse files Browse the repository at this point in the history
Backwards-compatibility: use older method for parsing JsonReader
  • Loading branch information
voidpointer0x00 committed Apr 3, 2023
1 parent 199d6bc commit e88b8fa
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public final class CachedProfileFetcher {
.expireAfterAccess(30, TimeUnit.MINUTES)
.build();
@AutowiredLocale private static LocaleLog log;
private static JsonParser jsonParser;

public static ConcurrentLinkedQueue<Profile> fetchProfiles(final Iterable<Whitelistable> whitelistables) {
ConcurrentLinkedQueue<Profile> profiles = new ConcurrentLinkedQueue<>();
Expand All @@ -60,7 +61,8 @@ public static CompletableFuture<String> fetchName(final UUID uniqueId) {
return completedFuture(profilesCache.asMap().get(uniqueId).getName());
return supplyAsync(() -> {
try {
JsonElement jsonElement = JsonParser.parseReader(newConnectionReader(uniqueId));
//noinspection deprecation
JsonElement jsonElement = getJsonParser().parse(newConnectionReader(uniqueId));
if (!jsonElement.isJsonObject()) {
log.warn("Profile with name for UUID {0} not found.", uniqueId);
return null;
Expand Down Expand Up @@ -104,11 +106,19 @@ private static Profile requestApi(final Whitelistable whitelistable) {

private static Profile requestApi0(final Whitelistable whitelistable) throws IOException {
Profile profile = new Profile(whitelistable);
profile.fromJson(JsonParser.parseReader(newConnectionReader(whitelistable.getUniqueId())));
//noinspection deprecation
profile.fromJson(getJsonParser().parse(newConnectionReader(whitelistable.getUniqueId())));
return profile;
}

private static InputStreamReader newConnectionReader(final UUID uuid) throws IOException {
return new InputStreamReader(new URL(API_URL + uuid.toString()).openStream());
}

private static JsonParser getJsonParser() {
if (jsonParser == null)
//noinspection deprecation
jsonParser = new JsonParser();
return jsonParser;
}
}

0 comments on commit e88b8fa

Please sign in to comment.