mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 11:45:19 +01:00
Address deprecated URL instantiation (#4178)
Fixes https://github.com/IntellectualSites/PlotSquared/issues/4166
This commit is contained in:
parent
aae6ea4fee
commit
4fe0c586d9
@ -35,7 +35,7 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
|
||||||
public class UpdateUtility implements Listener {
|
public class UpdateUtility implements Listener {
|
||||||
|
|
||||||
@ -59,8 +59,9 @@ public class UpdateUtility implements Listener {
|
|||||||
public void updateChecker() {
|
public void updateChecker() {
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> {
|
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> {
|
||||||
try {
|
try {
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(
|
HttpsURLConnection connection = (HttpsURLConnection) URI.create(
|
||||||
"https://api.spigotmc.org/simple/0.2/index.php?action=getResource&id=77506")
|
"https://api.spigotmc.org/simple/0.2/index.php?action=getResource&id=77506")
|
||||||
|
.toURL()
|
||||||
.openConnection();
|
.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
JsonObject result = new JsonParser()
|
JsonObject result = new JsonParser()
|
||||||
|
@ -84,7 +84,7 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -210,9 +210,10 @@ public class PlotSquared {
|
|||||||
try {
|
try {
|
||||||
URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
|
URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
|
||||||
this.jarFile = new File(
|
this.jarFile = new File(
|
||||||
new URL(logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
|
URI.create(
|
||||||
.toURI().getPath());
|
logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
|
||||||
} catch (MalformedURLException | URISyntaxException | SecurityException e) {
|
.getPath());
|
||||||
|
} catch (URISyntaxException | SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
|
this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
|
||||||
if (!this.jarFile.exists()) {
|
if (!this.jarFile.exists()) {
|
||||||
|
@ -41,6 +41,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -116,7 +117,7 @@ public class Load extends SubCommand {
|
|||||||
}
|
}
|
||||||
final URL url;
|
final URL url;
|
||||||
try {
|
try {
|
||||||
url = new URL(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schematic);
|
url = URI.create(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schematic).toURL();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
player.sendMessage(TranslatableCaption.of("web.load_failed"));
|
player.sendMessage(TranslatableCaption.of("web.load_failed"));
|
||||||
|
@ -40,6 +40,7 @@ import net.kyori.adventure.text.minimessage.tag.Tag;
|
|||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -130,8 +131,7 @@ public class SchematicCmd extends SubCommand {
|
|||||||
if (location.startsWith("url:")) {
|
if (location.startsWith("url:")) {
|
||||||
try {
|
try {
|
||||||
UUID uuid = UUID.fromString(location.substring(4));
|
UUID uuid = UUID.fromString(location.substring(4));
|
||||||
URL base = new URL(Settings.Web.URL);
|
URL url = URI.create(Settings.Web.URL + "uploads/" + uuid + ".schematic").toURL();
|
||||||
URL url = new URL(base, "uploads/" + uuid + ".schematic");
|
|
||||||
schematic = this.schematicHandler.getSchematic(url);
|
schematic = this.schematicHandler.getSchematic(url);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -83,6 +83,7 @@ import java.io.OutputStreamWriter;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
@ -144,7 +145,7 @@ public abstract class SchematicHandler {
|
|||||||
}
|
}
|
||||||
final URL url;
|
final URL url;
|
||||||
try {
|
try {
|
||||||
url = new URL(Settings.Web.URL + "?key=" + uuid + "&type=" + extension);
|
url = URI.create(Settings.Web.URL + "?key=" + uuid + "&type=" + extension).toURL();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
whenDone.run();
|
whenDone.run();
|
||||||
@ -153,7 +154,7 @@ public abstract class SchematicHandler {
|
|||||||
TaskManager.runTaskAsync(() -> {
|
TaskManager.runTaskAsync(() -> {
|
||||||
try {
|
try {
|
||||||
String boundary = Long.toHexString(System.currentTimeMillis());
|
String boundary = Long.toHexString(System.currentTimeMillis());
|
||||||
URLConnection con = new URL(website).openConnection();
|
URLConnection con = URI.create(website).toURL().openConnection();
|
||||||
con.setDoOutput(true);
|
con.setDoOutput(true);
|
||||||
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
||||||
try (OutputStream output = con.getOutputStream();
|
try (OutputStream output = con.getOutputStream();
|
||||||
@ -498,9 +499,10 @@ public abstract class SchematicHandler {
|
|||||||
public List<String> getSaves(UUID uuid) {
|
public List<String> getSaves(UUID uuid) {
|
||||||
String rawJSON;
|
String rawJSON;
|
||||||
try {
|
try {
|
||||||
String website = Settings.Web.URL + "list.php?" + uuid.toString();
|
URLConnection connection = URI.create(
|
||||||
URL url = new URL(website);
|
Settings.Web.URL + "list.php?" + uuid.toString())
|
||||||
URLConnection connection = new URL(url.toString()).openConnection();
|
.toURL()
|
||||||
|
.openConnection();
|
||||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
rawJSON = reader.lines().collect(Collectors.joining());
|
rawJSON = reader.lines().collect(Collectors.joining());
|
||||||
|
Loading…
Reference in New Issue
Block a user