Fix some command parsing issues

Tab complete runs on main thread - that could be an issue
This commit is contained in:
Jesse Boyd 2018-08-17 20:13:33 +10:00
parent 43d5459595
commit ae65708d82
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
5 changed files with 71 additions and 7 deletions

View File

@ -307,8 +307,15 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
private ChunkSnapshot tryGetSnasphot(Chunk chunk) { private ChunkSnapshot tryGetSnasphot(Chunk chunk) {
try { try {
return chunk.getChunkSnapshot(false, true, false); return chunk.getChunkSnapshot(false, true, false);
} catch (IllegalStateException ignore) { } catch (Throwable ignore) {
return null; Throwable cause = ignore;
while (cause.getCause() != null) {
cause = cause.getCause();
}
if (cause instanceof IllegalStateException) {
return null;
}
throw ignore;
} }
} }

View File

@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.extent.NullExtent; import com.boydti.fawe.object.extent.NullExtent;
import com.boydti.fawe.object.extent.ResettableExtent; import com.boydti.fawe.object.extent.ResettableExtent;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.TextureUtil; import com.boydti.fawe.util.TextureUtil;
import com.boydti.fawe.util.image.ImageUtil; import com.boydti.fawe.util.image.ImageUtil;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
@ -32,7 +33,11 @@ import com.sk89q.worldedit.util.command.parametric.BindingMatch;
import com.sk89q.worldedit.util.command.parametric.ParameterException; import com.sk89q.worldedit.util.command.parametric.ParameterException;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.net.URI;
import java.net.URL;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class FawePrimitiveBinding extends BindingHelper { public class FawePrimitiveBinding extends BindingHelper {
@ -69,14 +74,34 @@ public class FawePrimitiveBinding extends BindingHelper {
} }
} }
} }
public class ImageUri {
public final URI uri;
public ImageUri(URI uri) {
this.uri = uri;
}
public BufferedImage load() throws ParameterException {
try {
String uriStr = uri.toString();
if (uriStr.startsWith("file:/")) {
File file = new File(uri.getPath());
return MainUtil.readImage(file);
}
return MainUtil.readImage(new URL(uriStr));
} catch (IOException e) {
throw new ParameterException(e);
}
}
}
@BindingMatch( @BindingMatch(
type = {BufferedImage.class}, type = {ImageUri.class},
behavior = BindingBehavior.CONSUMES, behavior = BindingBehavior.CONSUMES,
consumedCount = 1, consumedCount = 1,
provideModifiers = true provideModifiers = true
) )
public BufferedImage getImage(ArgumentStack context, Annotation[] modifiers) throws ParameterException { public ImageUri getImage(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
return ImageUtil.getImage(context.next()); return new ImageUri(ImageUtil.getImageURI(context.next()));
} }
@BindingMatch( @BindingMatch(

View File

@ -24,7 +24,7 @@ public class SummedColorTable {
this.hasAlpha = new int[raw.length]; this.hasAlpha = new int[raw.length];
this.alpha = calculateAlpha ? new long[raw.length] : null; this.alpha = calculateAlpha ? new long[raw.length] : null;
this.alphaInverse = calculateAlpha ? new float[256] : null; this.alphaInverse = calculateAlpha ? new float[256] : null;
this.areaInverses = new float[Character.MAX_VALUE]; this.areaInverses = new float[1024 * 1024]; // 1 MB should be enough to cover scaling
for (int i = 0; i < areaInverses.length; i++) { for (int i = 0; i < areaInverses.length; i++) {
areaInverses[i] = 1f / (i + 1); areaInverses[i] = 1f / (i + 1);
} }

View File

@ -11,6 +11,8 @@ 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.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
public class ImageUtil { public class ImageUtil {
@ -177,4 +179,31 @@ public class ImageUtil {
throw new ParameterException(e); throw new ParameterException(e);
} }
} }
public static URI getImageURI(String arg) throws ParameterException {
try {
if (arg.startsWith("http")) {
if (arg.contains("imgur.com") && !arg.contains("i.imgur.com")) {
arg = "https://i.imgur.com/" + arg.split("imgur.com/")[1] + ".png";
}
return new URL(arg).toURI();
} else if (arg.startsWith("file:/")) {
arg = arg.replaceFirst("file:/+", "");
File file = MainUtil.getFile(MainUtil.getFile(Fawe.imp().getDirectory(), com.boydti.fawe.config.Settings.IMP.PATHS.HEIGHTMAP), arg);
if (file.exists()) {
throw new ParameterException("File not found " + file);
}
if (file.isDirectory()) {
throw new ParameterException("File is a directory " + file);
}
return file.toURI();
} else {
throw new ParameterException("Invalid image " + arg);
}
} catch (IOException e) {
throw new ParameterException(e);
} catch (URISyntaxException e) {
throw new ParameterException(e);
}
}
} }

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.FawePrimitiveBinding;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FaweLimit;
@ -52,6 +53,7 @@ import com.sk89q.worldedit.util.command.InvalidUsageException;
import com.sk89q.worldedit.util.command.binding.Range; import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.util.command.parametric.ParameterException;
import com.sk89q.worldedit.world.block.*; import com.sk89q.worldedit.world.block.*;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -376,7 +378,8 @@ public class BrushCommands extends BrushProcessor {
max = -1 max = -1
) )
@CommandPermissions("worldedit.brush.stencil") @CommandPermissions("worldedit.brush.stencil")
public BrushSettings imageBrush(Player player, EditSession editSession, LocalSession session, @Optional("5") double radius, BufferedImage image, @Optional("1") @Range(min=Double.MIN_NORMAL) final double yscale, @Switch('a') boolean alpha, @Switch('f') boolean fadeOut, CommandContext context) throws WorldEditException, IOException { public BrushSettings imageBrush(Player player, EditSession editSession, LocalSession session, @Optional("5") double radius, FawePrimitiveBinding.ImageUri imageUri, @Optional("1") @Range(min=Double.MIN_NORMAL) final double yscale, @Switch('a') boolean alpha, @Switch('f') boolean fadeOut, CommandContext context) throws WorldEditException, IOException, ParameterException {
BufferedImage image = imageUri.load();
getWorldEdit().checkMaxBrushRadius(radius); getWorldEdit().checkMaxBrushRadius(radius);
if (yscale != 1) { if (yscale != 1) {
ImageUtil.scaleAlpha(image, yscale); ImageUtil.scaleAlpha(image, yscale);