mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Allow local images for brushes
This commit is contained in:
parent
b24d322d29
commit
5f8e2ed4d8
@ -13,7 +13,9 @@ import java.awt.Transparency;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.DataBufferInt;
|
import java.awt.image.DataBufferInt;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -164,13 +166,21 @@ public class ImageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BufferedImage load(URI uri) throws ParameterException {
|
public static BufferedImage load(URI uri) throws ParameterException {
|
||||||
|
try {
|
||||||
|
return MainUtil.readImage(getInputStream(uri));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ParameterException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InputStream getInputStream(URI uri) throws ParameterException {
|
||||||
try {
|
try {
|
||||||
String uriStr = uri.toString();
|
String uriStr = uri.toString();
|
||||||
if (uriStr.startsWith("file:/")) {
|
if (uriStr.startsWith("file:/")) {
|
||||||
File file = new File(uri.getPath());
|
File file = new File(uri.getPath());
|
||||||
return MainUtil.readImage(file);
|
return new FileInputStream(file);
|
||||||
}
|
}
|
||||||
return MainUtil.readImage(new URL(uriStr));
|
return new URL(uriStr).openStream();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ParameterException(e);
|
throw new ParameterException(e);
|
||||||
}
|
}
|
||||||
@ -210,7 +220,7 @@ public class ImageUtil {
|
|||||||
} else if (arg.startsWith("file:/")) {
|
} else if (arg.startsWith("file:/")) {
|
||||||
arg = arg.replaceFirst("file:/+", "");
|
arg = arg.replaceFirst("file:/+", "");
|
||||||
File file = MainUtil.getFile(MainUtil.getFile(Fawe.imp().getDirectory(), com.boydti.fawe.config.Settings.IMP.PATHS.HEIGHTMAP), arg);
|
File file = MainUtil.getFile(MainUtil.getFile(Fawe.imp().getDirectory(), com.boydti.fawe.config.Settings.IMP.PATHS.HEIGHTMAP), arg);
|
||||||
if (file.exists()) {
|
if (!file.exists()) {
|
||||||
throw new ParameterException("File not found " + file);
|
throw new ParameterException("File not found " + file);
|
||||||
}
|
}
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
|
@ -62,6 +62,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
@ -348,7 +349,7 @@ public class BrushCommands extends BrushProcessor {
|
|||||||
max = -1
|
max = -1
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.brush.stencil")
|
@CommandPermissions("worldedit.brush.stencil")
|
||||||
public BrushSettings stencilBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") Expression radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('w') boolean onlyWhite, @Switch('r') boolean randomRotate, CommandContext context) throws WorldEditException {
|
public BrushSettings stencilBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") Expression radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('w') boolean onlyWhite, @Switch('r') boolean randomRotate, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||||
getWorldEdit().checkMaxBrushRadius(radius);
|
getWorldEdit().checkMaxBrushRadius(radius);
|
||||||
InputStream stream = getHeightmapStream(image);
|
InputStream stream = getHeightmapStream(image);
|
||||||
HeightBrush brush;
|
HeightBrush brush;
|
||||||
@ -689,7 +690,7 @@ public class BrushCommands extends BrushProcessor {
|
|||||||
max = 4
|
max = 4
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.brush.height")
|
@CommandPermissions("worldedit.brush.height")
|
||||||
public BrushSettings heightBrush(Player player, LocalSession session, @Optional("5") Expression radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth, CommandContext context) throws WorldEditException {
|
public BrushSettings heightBrush(Player player, LocalSession session, @Optional("5") Expression radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||||
return terrainBrush(player, session, radius, image, rotation, yscale, false, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context);
|
return terrainBrush(player, session, radius, image, rotation, yscale, false, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,7 +708,7 @@ public class BrushCommands extends BrushProcessor {
|
|||||||
max = 4
|
max = 4
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.brush.height")
|
@CommandPermissions("worldedit.brush.height")
|
||||||
public BrushSettings cliffBrush(Player player, LocalSession session, @Optional("5") Expression radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth, CommandContext context) throws WorldEditException {
|
public BrushSettings cliffBrush(Player player, LocalSession session, @Optional("5") Expression radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||||
return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CYLINDER, context);
|
return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CYLINDER, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,11 +725,11 @@ public class BrushCommands extends BrushProcessor {
|
|||||||
max = 4
|
max = 4
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.brush.height")
|
@CommandPermissions("worldedit.brush.height")
|
||||||
public BrushSettings flattenBrush(Player player, LocalSession session, @Optional("5") Expression radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth, CommandContext context) throws WorldEditException {
|
public BrushSettings flattenBrush(Player player, LocalSession session, @Optional("5") Expression radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('r') boolean randomRotate, @Switch('l') boolean layers, @Switch('s') boolean dontSmooth, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||||
return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context);
|
return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BrushSettings terrainBrush(Player player, LocalSession session, Expression radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape, CommandContext context) throws WorldEditException {
|
private BrushSettings terrainBrush(Player player, LocalSession session, Expression radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||||
getWorldEdit().checkMaxBrushRadius(radius);
|
getWorldEdit().checkMaxBrushRadius(radius);
|
||||||
InputStream stream = getHeightmapStream(image);
|
InputStream stream = getHeightmapStream(image);
|
||||||
HeightBrush brush;
|
HeightBrush brush;
|
||||||
@ -753,35 +754,12 @@ public class BrushCommands extends BrushProcessor {
|
|||||||
.setSize(radius);
|
.setSize(radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getHeightmapStream(String filename) {
|
private InputStream getHeightmapStream(String filename) throws FileNotFoundException, ParameterException {
|
||||||
String filenamePng = (filename.endsWith(".png") ? filename : filename + ".png");
|
String filenamePng = (filename.endsWith(".png") ? filename : filename + ".png");
|
||||||
File file = new File(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP + File.separator + filenamePng);
|
File file = new File(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP + File.separator + filenamePng);
|
||||||
if (!file.exists()) {
|
if (file.exists()) return new FileInputStream(file);
|
||||||
if (!filename.equals("#clipboard") && filename.length() >= 7) {
|
URI uri = ImageUtil.getImageURI(filename);
|
||||||
try {
|
return ImageUtil.getInputStream(uri);
|
||||||
URL url;
|
|
||||||
if (filename.startsWith("http")) {
|
|
||||||
url = new URL(filename);
|
|
||||||
if (!url.getHost().equals("i.imgur.com")) {
|
|
||||||
throw new FileNotFoundException(filename);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
url = new URL("https://i.imgur.com/" + filenamePng);
|
|
||||||
}
|
|
||||||
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
|
|
||||||
return Channels.newInputStream(rbc);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!filename.equalsIgnoreCase("#clipboard")) {
|
|
||||||
try {
|
|
||||||
return new FileInputStream(file);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user