Fix clipboard upload/download

This commit is contained in:
Jesse Boyd 2019-04-15 21:05:26 +10:00
parent 7c54f16d43
commit f849caf655
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 19 additions and 25 deletions

View File

@ -295,7 +295,7 @@ public class ClipboardCommands extends MethodCommands {
@Command(aliases = {"download"}, desc = "Downloads your clipboard through the configured web interface")
@Deprecated
@CommandPermissions({"worldedit.clipboard.download"})
public void download(final Player player, final LocalSession session, @Optional("schematic") final String formatName) throws CommandException, WorldEditException {
public void download(final Player player, final LocalSession session, @Optional("schem") final String formatName) throws CommandException, WorldEditException {
final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) {
BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName);
@ -356,29 +356,23 @@ public class ClipboardCommands extends MethodCommands {
} else {
target = clipboard;
}
switch (format.getName()) {
case "PNG":
try {
FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE);
ClipboardWriter writer = format.getWriter(baos);
writer.write(target);
baos.flush();
url = ImgurUtility.uploadImage(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
url = null;
}
break;
case "SCHEMATIC":
if (Settings.IMP.WEB.URL.isEmpty()) {
BBC.SETTING_DISABLE.send(player, "web.url");
return;
}
url = FaweAPI.upload(target, format);
break;
default:
if (format == BuiltInClipboardFormat.PNG) {
try {
FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE);
ClipboardWriter writer = format.getWriter(baos);
writer.write(target);
baos.flush();
url = ImgurUtility.uploadImage(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
url = null;
break;
}
} else {
if (Settings.IMP.WEB.URL.isEmpty()) {
BBC.SETTING_DISABLE.send(player, "web.url");
return;
}
url = FaweAPI.upload(target, format);
}
if (url == null) {
BBC.GENERATING_LINK_FAILED.send(player);

View File

@ -176,7 +176,7 @@ public interface ClipboardFormat {
}
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}

View File

@ -178,7 +178,7 @@ public class ClipboardFormats {
return null;
}
URL base = new URL(Settings.IMP.WEB.URL);
input = new URL(base, "uploads/" + input.substring(4) + ".schematic").toString();
input = new URL(base, "uploads/" + input.substring(4) + "." + format.getPrimaryFileExtension()).toString();
}
if (input.startsWith("http")) {
if (!player.hasPermission("worldedit.schematic.load.asset")) {