Assets
This commit is contained in:
parent
5ead47ba2f
commit
8c592d1506
@ -141,20 +141,7 @@ public class FaweAPI {
|
||||
* @return The download URL or null
|
||||
*/
|
||||
public static URL upload(final Clipboard clipboard, final ClipboardFormat format) {
|
||||
return MainUtil.upload(null, "clipboard", format.getExtension(), new RunnableVal<OutputStream>() {
|
||||
@Override
|
||||
public void run(OutputStream value) {
|
||||
try {
|
||||
try (PGZIPOutputStream gzip = new PGZIPOutputStream(value)) {
|
||||
try (ClipboardWriter writer = format.getWriter(gzip)) {
|
||||
writer.write(clipboard, null);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
return format.uploadAnonymous(clipboard);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,8 +272,19 @@ public class Settings extends Config {
|
||||
}
|
||||
|
||||
public static class WEB {
|
||||
@Comment("I am already hosting a web interface for you here")
|
||||
@Comment({
|
||||
"The web interface for clipboards",
|
||||
" - All schematics are anonymous and private",
|
||||
" - Downloads can be deleted by the user",
|
||||
" - Supports clipboard uploads, downloads and saves",
|
||||
})
|
||||
public String URL = "http://empcraft.com/fawe/";
|
||||
@Comment({
|
||||
"The web interface for assets",
|
||||
" - All schematics are organized and public",
|
||||
" - Assets can be searched, selected and downloaded",
|
||||
})
|
||||
public String ASSETS = "http://empcraft.com/assetpack/";
|
||||
}
|
||||
|
||||
public static class EXTENT {
|
||||
|
@ -322,23 +322,26 @@ public class MainUtil {
|
||||
}
|
||||
|
||||
public static URL upload(UUID uuid, String file, String extension, final RunnableVal<OutputStream> writeTask) {
|
||||
return upload(Settings.IMP.WEB.URL, uuid != null, uuid != null ? uuid.toString() : (String) null, file, extension, writeTask);
|
||||
}
|
||||
|
||||
public static URL upload(String urlStr, boolean save, String uuid, String file, String extension, final RunnableVal<OutputStream> writeTask) {
|
||||
if (writeTask == null) {
|
||||
Fawe.debug("&cWrite task cannot be null");
|
||||
return null;
|
||||
}
|
||||
final String filename;
|
||||
String filename = (file == null ? "plot" : file) + (extension != null ? "." + extension : "");
|
||||
uuid = uuid == null ? UUID.randomUUID().toString() : uuid;
|
||||
final String website;
|
||||
if (uuid == null) {
|
||||
uuid = UUID.randomUUID();
|
||||
website = Settings.IMP.WEB.URL + "upload.php?" + uuid;
|
||||
filename = "plot." + extension;
|
||||
if (!save) {
|
||||
website = urlStr + "upload.php?" + uuid;
|
||||
|
||||
} else {
|
||||
website = Settings.IMP.WEB.URL + "save.php?" + uuid;
|
||||
filename = file + '.' + extension;
|
||||
website = urlStr + "save.php?" + uuid;
|
||||
}
|
||||
final URL url;
|
||||
try {
|
||||
url = new URL(Settings.IMP.WEB.URL + "?key=" + uuid + "&type=" + extension);
|
||||
url = new URL(urlStr + "?key=" + uuid + "&type=" + "" + extension);
|
||||
String boundary = Long.toHexString(System.currentTimeMillis());
|
||||
URLConnection con = new URL(website).openConnection();
|
||||
con.setDoOutput(true);
|
||||
@ -366,6 +369,10 @@ public class MainUtil {
|
||||
writer.append("--" + boundary + "--").append(CRLF).flush();
|
||||
}
|
||||
int responseCode = ((HttpURLConnection) con).getResponseCode();
|
||||
java.util.Scanner scanner = new java.util.Scanner(con.getInputStream()).useDelimiter("\\A");
|
||||
String content = scanner.next().trim();
|
||||
scanner.close();
|
||||
Fawe.debug(content);
|
||||
if (responseCode == 200) {
|
||||
return url;
|
||||
}
|
||||
|
@ -312,6 +312,43 @@ public class ClipboardCommands {
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "asset", "createasset", "makeasset" },
|
||||
usage = "[category]",
|
||||
desc = "Create an asset",
|
||||
help = "Saves your clipboard to the asset web interface",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions({ "worldedit.clipboard.asset"})
|
||||
public void asset(final Player player, final LocalSession session, String category) throws CommandException, WorldEditException {
|
||||
final ClipboardFormat format = ClipboardFormat.SCHEMATIC;
|
||||
ClipboardHolder holder = session.getClipboard();
|
||||
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, holder.getWorldData());
|
||||
target = new BlockArrayClipboard(result.getTransformedRegion(), player.getUniqueId());
|
||||
target.setOrigin(clipboard.getOrigin());
|
||||
Operations.completeLegacy(result.copyTo(target));
|
||||
} else {
|
||||
target = clipboard;
|
||||
}
|
||||
BBC.GENERATING_LINK.send(player, format.name());
|
||||
if (Settings.IMP.WEB.ASSETS.isEmpty()) {
|
||||
BBC.SETTING_DISABLE.send(player, "web.assets");
|
||||
return;
|
||||
}
|
||||
URL url = format.uploadPublic(target, category.replaceAll("[/|\\\\]", "."), player.getName());
|
||||
if (url == null) {
|
||||
BBC.GENERATING_LINK_FAILED.send(player);
|
||||
} else {
|
||||
BBC.DOWNLOAD_LINK.send(player, Settings.IMP.WEB.ASSETS);
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "/paste" },
|
||||
usage = "",
|
||||
|
@ -19,9 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.extent.clipboard.io;
|
||||
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.jnbt.NBTStreamer;
|
||||
import com.boydti.fawe.object.FaweOutputStream;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.clipboard.AbstractClipboardFormat;
|
||||
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
|
||||
import com.boydti.fawe.object.clipboard.FaweClipboard;
|
||||
import com.boydti.fawe.object.clipboard.IClipboardFormat;
|
||||
import com.boydti.fawe.object.io.PGZIPOutputStream;
|
||||
import com.boydti.fawe.object.io.ResettableFileInputStream;
|
||||
@ -31,11 +35,24 @@ import com.boydti.fawe.object.schematic.Schematic;
|
||||
import com.boydti.fawe.object.schematic.StructureFormat;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.sk89q.jnbt.NBTConstants;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.NBTOutputStream;
|
||||
import java.io.*;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -244,6 +261,63 @@ public enum ClipboardFormat {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public URL uploadPublic(final Clipboard clipboard, String category, String user) {
|
||||
// summary
|
||||
// blocks
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
Vector dimensions = clipboard.getDimensions();
|
||||
map.put("width", dimensions.getX());
|
||||
map.put("height", dimensions.getY());
|
||||
map.put("length", dimensions.getZ());
|
||||
map.put("creator", user);
|
||||
if (clipboard instanceof BlockArrayClipboard) {
|
||||
FaweClipboard fc = ((BlockArrayClipboard) clipboard).IMP;
|
||||
final int[] ids = new int[4096];
|
||||
fc.streamIds(new NBTStreamer.ByteReader() {
|
||||
@Override
|
||||
public void run(int index, int byteValue) {
|
||||
ids[byteValue]++;
|
||||
}
|
||||
});
|
||||
Map<Integer, Integer> blocks = new HashMap<Integer, Integer>();
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
if (ids[i] != 0) {
|
||||
blocks.put(i, ids[i]);
|
||||
}
|
||||
}
|
||||
map.put("blocks", blocks);
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(map);
|
||||
return MainUtil.upload(Settings.IMP.WEB.ASSETS, false, json, category, null, new RunnableVal<OutputStream>() {
|
||||
@Override
|
||||
public void run(OutputStream value) {
|
||||
write(value, clipboard);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void write(OutputStream value, Clipboard clipboard) {
|
||||
try {
|
||||
try (PGZIPOutputStream gzip = new PGZIPOutputStream(value)) {
|
||||
try (ClipboardWriter writer = format.getWriter(gzip)) {
|
||||
writer.write(clipboard, null);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public URL uploadAnonymous(final Clipboard clipboard) {
|
||||
return MainUtil.upload(null, null, format.getExtension(), new RunnableVal<OutputStream>() {
|
||||
@Override
|
||||
public void run(OutputStream value) {
|
||||
write(value, clipboard);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public IClipboardFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
@ -62,7 +63,7 @@ public class SimpleDispatcher implements Dispatcher {
|
||||
for (String a : alias) {
|
||||
String lower = a.toLowerCase();
|
||||
if (commands.containsKey(lower)) {
|
||||
System.out.println("Replacing commands is currently undefined behavior: " + StringMan.getString(alias));
|
||||
Fawe.debug("Replacing commands is currently undefined behavior: " + StringMan.getString(alias));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user