Fix cliff brush NPE

This commit is contained in:
Jesse Boyd 2018-09-08 02:25:38 +10:00
parent d3ddd9ea6a
commit ca5ffe081b
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F

View File

@ -368,7 +368,7 @@ public class BrushCommands extends BrushProcessor {
InputStream stream = getHeightmapStream(image); InputStream stream = getHeightmapStream(image);
HeightBrush brush; HeightBrush brush;
try { try {
brush = new StencilBrush(stream, rotation, yscale, onlyWhite, image.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null); brush = new StencilBrush(stream, rotation, yscale, onlyWhite, "#clipboard".equalsIgnoreCase(image) ? session.getClipboard().getClipboard() : null);
} catch (EmptyClipboardException ignore) { } catch (EmptyClipboardException ignore) {
brush = new StencilBrush(stream, rotation, yscale, onlyWhite, null); brush = new StencilBrush(stream, rotation, yscale, onlyWhite, null);
} }
@ -745,17 +745,17 @@ public class BrushCommands extends BrushProcessor {
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 { 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 {
checkMaxBrushRadius(radius); checkMaxBrushRadius(radius);
InputStream stream = getHeightmapStream(image); InputStream stream = image == null ? null : getHeightmapStream(image);
HeightBrush brush; HeightBrush brush;
if (flat) { if (flat) {
try { try {
brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, image.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null, shape); brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, "#clipboard".equalsIgnoreCase(image) ? session.getClipboard().getClipboard() : null, shape);
} catch (EmptyClipboardException ignore) { } catch (EmptyClipboardException ignore) {
brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, null, shape); brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, null, shape);
} }
} else { } else {
try { try {
brush = new HeightBrush(stream, rotation, yscale, layers, smooth, image.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null); brush = new HeightBrush(stream, rotation, yscale, layers, smooth, "#clipboard".equalsIgnoreCase(image) ? session.getClipboard().getClipboard() : null);
} catch (EmptyClipboardException ignore) { } catch (EmptyClipboardException ignore) {
brush = new HeightBrush(stream, rotation, yscale, layers, smooth, null); brush = new HeightBrush(stream, rotation, yscale, layers, smooth, null);
} }
@ -769,6 +769,7 @@ public class BrushCommands extends BrushProcessor {
} }
private InputStream getHeightmapStream(String filename) throws FileNotFoundException, ParameterException { private InputStream getHeightmapStream(String filename) throws FileNotFoundException, ParameterException {
if (filename == null) return null;
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()) return new FileInputStream(file); if (file.exists()) return new FileInputStream(file);