From 59ab56bdd71ffee46a8030c318edd6ac736c06c7 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 13 May 2017 14:43:15 +1000 Subject: [PATCH] Allow other image urls --- .../regions/general/plot/CreateFromImage.java | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/regions/general/plot/CreateFromImage.java b/core/src/main/java/com/boydti/fawe/regions/general/plot/CreateFromImage.java index 1379d5ac..e6b25e64 100644 --- a/core/src/main/java/com/boydti/fawe/regions/general/plot/CreateFromImage.java +++ b/core/src/main/java/com/boydti/fawe/regions/general/plot/CreateFromImage.java @@ -87,13 +87,8 @@ public class CreateFromImage extends Command { final BufferedImage image; if (argList.get(0).toLowerCase().startsWith("http")) { try { - URL url = new URL(argList.get(0)); - if (!url.getHost().equals("i.imgur.com")) { - player.sendMessage("Images can only be loaded from i.imgur.com"); - return; - } player.sendMessage(BBC.getPrefix() + "Loading image... (1)"); - image = com.boydti.fawe.util.MainUtil.toRGB(ImageIO.read(url)); + image = getImage(argList.get(0), fp); } catch (IOException e) { player.sendMessage(e.getMessage()); return; @@ -201,7 +196,7 @@ public class CreateFromImage extends Command { int argOffset = 0; BufferedImage img = null; if (argList.get(1).startsWith("http")) { - img = getImgurImage(argList.get(1), fp); + img = getImage(argList.get(1), fp); argOffset++; } World world = fp.getWorld(); @@ -299,7 +294,7 @@ public class CreateFromImage extends Command { C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " "); return; } - BufferedImage image = getImgurImage(argList.get(1), fp); + BufferedImage image = getImage(argList.get(1), fp); generator.setColor(image); player.sendMessage("Set color, what's next?"); return; @@ -310,7 +305,7 @@ public class CreateFromImage extends Command { C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " "); return; } - BufferedImage image = getImgurImage(argList.get(1), fp); + BufferedImage image = getImage(argList.get(1), fp); generator.setBiomeColor(image); player.sendMessage("Set color, what's next?"); return; @@ -321,7 +316,7 @@ public class CreateFromImage extends Command { C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " "); return; } - BufferedImage image = getImgurImage(argList.get(1), fp); + BufferedImage image = getImage(argList.get(1), fp); generator.setBlockAndBiomeColor(image); player.sendMessage("Set color, what's next?"); return; @@ -333,7 +328,7 @@ public class CreateFromImage extends Command { C.COMMAND_SYNTAX.send(player, "/2 cfi " + argList.get(0) + " "); return; } - BufferedImage image = getImgurImage(argList.get(1), fp); + BufferedImage image = getImage(argList.get(1), fp); generator.setColorWithGlass(image); player.sendMessage("Set glass color, what's next?"); return; @@ -370,7 +365,7 @@ public class CreateFromImage extends Command { } if (argList.get(1).startsWith("http")) { player.sendMessage("Loading image (3)..."); - BufferedImage image = getImgurImage(argList.get(1), fp); + BufferedImage image = getImage(argList.get(1), fp); generator.setHeight(image); } else { generator.setHeights(Integer.parseInt(args[1])); @@ -424,7 +419,7 @@ public class CreateFromImage extends Command { generator.setBiome(id); } else { id = getBiome(argList.get(2), fp).getId(); - BufferedImage img = getImgurImage(argList.get(1), fp); + BufferedImage img = getImage(argList.get(1), fp); if (img != null) { boolean whiteOnly = argList.size() == 4 && Boolean.parseBoolean(argList.get(3)); generator.setBiome(img, (byte) id, whiteOnly); @@ -443,7 +438,7 @@ public class CreateFromImage extends Command { } int radius = Integer.parseInt(argList.get(2)); int iterations = Integer.parseInt(argList.get(3)); - BufferedImage img = getImgurImage(argList.get(1), fp); + BufferedImage img = getImage(argList.get(1), fp); if (img != null) { boolean whiteOnly = argList.size() == 5 && Boolean.parseBoolean(argList.get(4)); generator.smooth(img, whiteOnly, radius, iterations); @@ -466,7 +461,7 @@ public class CreateFromImage extends Command { generator.setOverlay(id); } else { id = we.getPatternFactory().parseFromInput(argList.get(2), context); - BufferedImage img = getImgurImage(argList.get(1), fp); + BufferedImage img = getImage(argList.get(1), fp); if (img != null) { boolean whiteOnly = argList.size() == 4 && Boolean.parseBoolean(argList.get(3)); generator.setOverlay(img, id, whiteOnly); @@ -489,7 +484,7 @@ public class CreateFromImage extends Command { generator.setMain(id); } else { id = we.getPatternFactory().parseFromInput(argList.get(2), context); - BufferedImage img = getImgurImage(argList.get(1), fp); + BufferedImage img = getImage(argList.get(1), fp); if (img != null) { boolean whiteOnly = argList.size() == 4 && Boolean.parseBoolean(argList.get(3)); generator.setMain(img, id, whiteOnly); @@ -512,7 +507,7 @@ public class CreateFromImage extends Command { generator.setFloor(id); } else { id = we.getPatternFactory().parseFromInput(argList.get(2), context); - BufferedImage img = getImgurImage(argList.get(1), fp); + BufferedImage img = getImage(argList.get(1), fp); if (img != null) { boolean whiteOnly = argList.size() == 4 && Boolean.parseBoolean(argList.get(3)); generator.setFloor(img, id, whiteOnly); @@ -535,7 +530,7 @@ public class CreateFromImage extends Command { generator.setColumn(id); } else { id = we.getPatternFactory().parseFromInput(argList.get(2), context); - BufferedImage img = getImgurImage(argList.get(1), fp); + BufferedImage img = getImage(argList.get(1), fp); if (img != null) { boolean whiteOnly = argList.size() == 4 && Boolean.parseBoolean(argList.get(3)); generator.setColumn(img, id, whiteOnly); @@ -602,12 +597,9 @@ public class CreateFromImage extends Command { return Biomes.findBiomeByName(knownBiomes, arg, biomeRegistry); } - private BufferedImage getImgurImage(String arg, FawePlayer fp) throws IOException { + private BufferedImage getImage(String arg, FawePlayer fp) throws IOException { if (arg.startsWith("http")) { URL url = new URL(arg); - if (!url.getHost().equalsIgnoreCase("i.imgur.com")) { - throw new IOException("Only i.imgur.com links are allowed!"); - } fp.sendMessage(BBC.getPrefix() + "Downloading image... (3)"); return com.boydti.fawe.util.MainUtil.toRGB(ImageIO.read(url)); }