mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-06-27 07:04:45 +02:00
* NEW: Improved rendering error messages. Fixes #22.
This commit is contained in:
parent
a2cdb02834
commit
b5d41b25d0
|
@ -75,7 +75,10 @@ public class NewCommand extends IoMCommand
|
||||||
public void errored(Throwable exception)
|
public void errored(Throwable exception)
|
||||||
{
|
{
|
||||||
player.sendMessage("§cMap rendering failed : " + exception.getMessage());
|
player.sendMessage("§cMap rendering failed : " + exception.getMessage());
|
||||||
PluginLogger.warning("Rendering from '{0}' failed", exception, player.getName());
|
PluginLogger.warning("Rendering from {0} failed : {1} : {2}",
|
||||||
|
player.getName(),
|
||||||
|
exception.getClass().getCanonicalName(),
|
||||||
|
exception.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,10 @@ import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
@ -58,7 +61,20 @@ public class ImageRendererExecutor extends Worker
|
||||||
@Override
|
@Override
|
||||||
public ImageMap run() throws Throwable
|
public ImageMap run() throws Throwable
|
||||||
{
|
{
|
||||||
final BufferedImage image = ImageIO.read(url);
|
final URLConnection connection = url.openConnection();
|
||||||
|
connection.connect();
|
||||||
|
if(connection instanceof HttpURLConnection)
|
||||||
|
{
|
||||||
|
final HttpURLConnection httpConnection = (HttpURLConnection) connection;
|
||||||
|
final int httpCode = httpConnection.getResponseCode();
|
||||||
|
if((httpCode / 100) != 2)
|
||||||
|
{
|
||||||
|
throw new IOException("HTTP error : " + httpCode + " " + httpConnection.getResponseMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final InputStream stream = connection.getInputStream();
|
||||||
|
final BufferedImage image = ImageIO.read(stream);
|
||||||
|
|
||||||
if (image == null) throw new IOException("The given URL is not a valid image");
|
if (image == null) throw new IOException("The given URL is not a valid image");
|
||||||
|
|
||||||
if (scaling) return RenderSingle(image, playerUUID);
|
if (scaling) return RenderSingle(image, playerUUID);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user