mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Fix heightmap brush with imgur images (#2680)
fix: heightmap brush with imgur / remote images
This commit is contained in:
parent
d0b676210b
commit
a0ef151341
@ -554,8 +554,15 @@ public class MainUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BufferedImage readImage(URL url) throws IOException {
|
public static BufferedImage readImage(URL url) throws IOException {
|
||||||
|
try (final InputStream stream = readImageStream(url.toURI())) {
|
||||||
|
return readImage(stream);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IOException("failed to parse url to uri reference", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InputStream readImageStream(final URI uri) throws IOException {
|
||||||
try {
|
try {
|
||||||
final URI uri = url.toURI();
|
|
||||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(uri).GET();
|
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(uri).GET();
|
||||||
|
|
||||||
if (uri.getHost().equalsIgnoreCase("i.imgur.com")) {
|
if (uri.getHost().equalsIgnoreCase("i.imgur.com")) {
|
||||||
@ -566,16 +573,13 @@ public class MainUtil {
|
|||||||
requestBuilder.build(),
|
requestBuilder.build(),
|
||||||
HttpResponse.BodyHandlers.ofInputStream()
|
HttpResponse.BodyHandlers.ofInputStream()
|
||||||
);
|
);
|
||||||
try (final InputStream body = response.body()) {
|
final InputStream body = response.body();
|
||||||
if (response.statusCode() > 299) {
|
if (response.statusCode() > 299) {
|
||||||
throw new IOException("Expected 2xx as response code, but received " + response.statusCode());
|
throw new IOException("Expected 2xx as response code, but received " + response.statusCode());
|
||||||
}
|
}
|
||||||
return readImage(body);
|
return body;
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new IOException("request was interrupted", e);
|
throw new IOException("request was interrupted", e);
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new IOException("failed to parse url to uri reference", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +176,8 @@ public class ImageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BufferedImage load(URI uri) throws InputParseException {
|
public static BufferedImage load(URI uri) throws InputParseException {
|
||||||
try {
|
try (final InputStream stream = getInputStream(uri)) {
|
||||||
return MainUtil.readImage(getInputStream(uri));
|
return MainUtil.readImage(stream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new InputParseException(TextComponent.of(e.getMessage()));
|
throw new InputParseException(TextComponent.of(e.getMessage()));
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ public class ImageUtil {
|
|||||||
File file = new File(uri.getPath());
|
File file = new File(uri.getPath());
|
||||||
return new FileInputStream(file);
|
return new FileInputStream(file);
|
||||||
}
|
}
|
||||||
return new URL(uriStr).openStream();
|
return MainUtil.readImageStream(uri);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new InputParseException(TextComponent.of(e.getMessage()));
|
throw new InputParseException(TextComponent.of(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user