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
5 changed files with 71 additions and 7 deletions

View File

@ -11,6 +11,8 @@ import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
public class ImageUtil {
@ -177,4 +179,31 @@ public class ImageUtil {
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);
}
}
}