use of com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder in project FastAsyncWorldEdit by IntellectualSites.
the class ClipboardCommands method download.
// FAWE start
@Command(name = "download", aliases = { "/download" }, desc = "Downloads your clipboard through the configured web interface")
@Deprecated
@CommandPermissions({ "worldedit.clipboard.download" })
public void download(final Actor actor, final LocalSession session, @Arg(name = "format", desc = "String", def = "fast") final String formatName) throws WorldEditException {
final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) {
actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.invalid.format", formatName));
return;
}
actor.print(Caption.of("fawe.web.generating.link", formatName));
ClipboardHolder holder = session.getClipboard();
URL url;
if (holder instanceof MultiClipboardHolder) {
MultiClipboardHolder multi = (MultiClipboardHolder) holder;
Set<File> files = new HashSet<>();
Set<URI> invalid = new HashSet<>();
for (ClipboardHolder cur : multi.getHolders()) {
if (cur instanceof URIClipboardHolder) {
URIClipboardHolder uriHolder = (URIClipboardHolder) cur;
URI uri = uriHolder.getUri();
File file = new File(uri.getPath());
if (file.exists() && file.isFile()) {
files.add(file.getAbsoluteFile());
} else if (!uri.getPath().isEmpty()) {
invalid.add(uri);
}
}
}
final LocalConfiguration config = WorldEdit.getInstance().getConfiguration();
final File working = WorldEdit.getInstance().getWorkingDirectoryFile(config.saveDir).getAbsoluteFile();
url = MainUtil.upload(null, null, "zip", new RunnableVal<>() {
@Override
public void run(OutputStream out) {
try (ZipOutputStream zos = new ZipOutputStream(out)) {
for (File file : files) {
String fileName = file.getName();
if (MainUtil.isInSubDirectory(working, file)) {
fileName = working.toURI().relativize(file.toURI()).getPath();
}
ZipEntry ze = new ZipEntry(fileName);
zos.putNextEntry(ze);
Files.copy(file.toPath(), zos);
zos.closeEntry();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
} else {
Clipboard clipboard = holder.getClipboard();
final Transform transform = holder.getTransform();
final Clipboard target;
// If we have a transform, bake it into the copy
if (!transform.isIdentity()) {
final FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform);
target = new BlockArrayClipboard(result.getTransformedRegion(), actor.getUniqueId());
target.setOrigin(clipboard.getOrigin());
Operations.completeLegacy(result.copyTo(target));
} else {
target = clipboard;
}
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;
}
} else {
if (Settings.settings().WEB.URL.isEmpty()) {
actor.print(Caption.of("fawe.error.setting.disable", "web.url"));
return;
}
url = FaweAPI.upload(target, format);
}
}
if (url == null) {
actor.print(Caption.of("fawe.web.generating.link.failed"));
} else {
String urlText = url.toString();
actor.print(Caption.of("fawe.web.download.link", urlText).clickEvent(ClickEvent.openUrl(urlText)));
}
}
use of com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method scatterSchemBrush.
@Command(name = "populateschematic", aliases = { "populateschem", "popschem", "pschem", "ps" }, desc = "Scatter a schematic on a surface")
@CommandPermissions("worldedit.brush.populateschematic")
public void scatterSchemBrush(Player player, InjectedValueAccess context, @Arg(desc = "Mask") Mask mask, @Arg(name = "clipboard", desc = "Clipboard uri") String clipboardStr, @Arg(desc = "Expression", def = "30") Expression radius, @Arg(desc = "double", def = "50") double density, @Switch(name = 'r', desc = "Apply random rotation") boolean rotate) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
try {
MultiClipboardHolder clipboards = ClipboardFormats.loadAllFromInput(player, clipboardStr, null, true);
if (clipboards == null) {
player.print(Caption.of("fawe.error.schematic.not.found", clipboardStr));
return;
}
List<ClipboardHolder> holders = clipboards.getHolders();
if (holders == null) {
player.print(Caption.of("fawe.error.schematic.not.found", clipboardStr));
return;
}
set(context, new PopulateSchem(mask, holders, (int) density, rotate), "worldedit.brush.populateschematic").setSize(radius);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations