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") @Command(aliases = {"download"}, desc = "Downloads your clipboard through the configured web interface")
@Deprecated @Deprecated
@CommandPermissions({"worldedit.clipboard.download"}) @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); final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) { if (format == null) {
BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName); BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName);
@ -356,29 +356,23 @@ public class ClipboardCommands extends MethodCommands {
} else { } else {
target = clipboard; target = clipboard;
} }
switch (format.getName()) { if (format == BuiltInClipboardFormat.PNG) {
case "PNG": try {
try { FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE);
FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE); ClipboardWriter writer = format.getWriter(baos);
ClipboardWriter writer = format.getWriter(baos); writer.write(target);
writer.write(target); baos.flush();
baos.flush(); url = ImgurUtility.uploadImage(baos.toByteArray());
url = ImgurUtility.uploadImage(baos.toByteArray()); } catch (IOException e) {
} catch (IOException e) { e.printStackTrace();
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:
url = null; 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) { if (url == null) {
BBC.GENERATING_LINK_FAILED.send(player); BBC.GENERATING_LINK_FAILED.send(player);

View File

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

View File

@ -178,7 +178,7 @@ public class ClipboardFormats {
return null; return null;
} }
URL base = new URL(Settings.IMP.WEB.URL); 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 (input.startsWith("http")) {
if (!player.hasPermission("worldedit.schematic.load.asset")) { if (!player.hasPermission("worldedit.schematic.load.asset")) {