Fix deprecation smells

This commit is contained in:
Aurora Lahtela 2023-09-24 08:39:01 +03:00
parent 630247d884
commit f67a02775f
5 changed files with 13 additions and 21 deletions

View File

@ -114,7 +114,7 @@ public class PlanSystem implements SubSystem {
SchedulerSvc schedulerService, SchedulerSvc schedulerService,
PluginLogger logger, PluginLogger logger,
ErrorLogger errorLogger, ErrorLogger errorLogger,
PlanAPI.PlanAPIHolder apiHolder @SuppressWarnings("deprecation") PlanAPI.PlanAPIHolder apiHolder // Deprecated PlanAPI, backwards compatibility
) { ) {
this.files = files; this.files = files;
this.configSystem = configSystem; this.configSystem = configSystem;
@ -149,14 +149,6 @@ public class PlanSystem implements SubSystem {
logger.info("§2"); logger.info("§2");
} }
/**
* @deprecated Use {@link com.djrapitops.plan.delivery.webserver.Addresses} instead.
*/
@Deprecated(since = "Addresses.java")
public String getMainAddress() {
return webServerSystem.getAddresses().getMainAddress().orElse(webServerSystem.getAddresses().getFallbackLocalhostAddress());
}
/** /**
* Enables only the systems that are required for {@link com.djrapitops.plan.commands.PlanCommand}. * Enables only the systems that are required for {@link com.djrapitops.plan.commands.PlanCommand}.
* *

View File

@ -115,7 +115,12 @@ public class PlayersTableJSONCreator {
} }
} }
@Deprecated /**
* This method is kept for /v1/players backwards compatibility.
*
* @deprecated Use {@link PlayersTableJSONCreator#toPlayerList()}.
*/
@Deprecated(since = "5.6")
public Map<String, Object> toJSONMap() { public Map<String, Object> toJSONMap() {
return Maps.builder(String.class, Object.class) return Maps.builder(String.class, Object.class)
.put("columns", createColumnHeaders()) .put("columns", createColumnHeaders())

View File

@ -101,6 +101,7 @@ public class ResourceSvc implements ResourceService {
} }
@Nullable @Nullable
@SuppressWarnings("deprecation") // Legacy method, backwards compatibility
private static String applyLegacy(Map<Position, StringBuilder> byPosition, String html) { private static String applyLegacy(Map<Position, StringBuilder> byPosition, String html) {
StringBuilder toHead = byPosition.get(Position.PRE_CONTENT); StringBuilder toHead = byPosition.get(Position.PRE_CONTENT);
if (toHead != null) { if (toHead != null) {

View File

@ -107,6 +107,7 @@ public class PlayersJSONResolver extends JSONResolver {
return getCachedOrNewResponse(request, storedJSON); return getCachedOrNewResponse(request, storedJSON);
} }
@SuppressWarnings("deprecation") // /v1/players is deprecated but kept for backwards compatibility.
private JSONStorage.StoredJSON getStoredJSON(@Untrusted Request request) { private JSONStorage.StoredJSON getStoredJSON(@Untrusted Request request) {
Optional<Long> timestamp = Identifiers.getTimestamp(request); Optional<Long> timestamp = Identifiers.getTimestamp(request);
JSONStorage.StoredJSON storedJSON; JSONStorage.StoredJSON storedJSON;

View File

@ -22,11 +22,11 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -79,7 +79,7 @@ public class OreVersionInfoLoader {
connection.setRequestProperty("User-Agent", "Player Analytics Update Checker"); connection.setRequestProperty("User-Agent", "Player Analytics Update Checker");
connection.connect(); connection.connect();
try (InputStream in = connection.getInputStream()) { try (InputStream in = connection.getInputStream()) {
JsonArray versions = new JsonParser().parse(readInputFully(in)).getAsJsonObject().get("result").getAsJsonArray(); JsonArray versions = JsonParser.parseString(readInputFully(in)).getAsJsonObject().get("result").getAsJsonArray();
return new Gson().getAdapter(new TypeToken<List<OreVersionDto>>() {}).fromJsonTree(versions); return new Gson().getAdapter(new TypeToken<List<OreVersionDto>>() {}).fromJsonTree(versions);
} }
@ -98,21 +98,14 @@ public class OreVersionInfoLoader {
connection.setRequestProperty("User-Agent", "Player Analytics Update Checker"); connection.setRequestProperty("User-Agent", "Player Analytics Update Checker");
connection.connect(); connection.connect();
try (InputStream in = connection.getInputStream()) { try (InputStream in = connection.getInputStream()) {
return new JsonParser().parse(readInputFully(in)).getAsJsonObject().get("session").getAsString(); return JsonParser.parseString(readInputFully(in)).getAsJsonObject().get("session").getAsString();
} }
} finally { } finally {
connection.disconnect(); connection.disconnect();
} }
} }
// I want Java 9 already...
private static String readInputFully(InputStream in) throws IOException { private static String readInputFully(InputStream in) throws IOException {
try (ByteArrayOutputStream buf = new ByteArrayOutputStream(512)) { return new String(in.readAllBytes(), StandardCharsets.UTF_8);
int b;
while ((b = in.read()) != -1) {
buf.write((byte) b);
}
return buf.toString();
}
} }
} }