Fix schematic downloading

This commit is contained in:
Jesse Boyd 2016-09-02 13:23:58 +10:00
parent 523f62787b
commit b18e53e79f
12 changed files with 106 additions and 28 deletions

View File

@ -24,6 +24,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -136,6 +137,21 @@ public class BukkitQueue_1_10 extends BukkitQueue_0<Chunk, ChunkSection[], Chunk
if (folder.exists() && !folder.isDirectory()) { if (folder.exists() && !folder.isDirectory()) {
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
} }
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
try {
Field field = CraftServer.class.getDeclaredField("worlds");
field.setAccessible(true);
Map<Object, Object> existing = (Map<Object, Object>) field.get(server);
if (!existing.getClass().getName().contains("SynchronizedMap")) {
field.set(server, Collections.synchronizedMap(existing));
}
} catch (Throwable e) {
e.printStackTrace();
}
}
});
if (generator == null) { if (generator == null) {
generator = server.getGenerator(name); generator = server.getGenerator(name);
} }

View File

@ -21,6 +21,7 @@ import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -564,6 +565,21 @@ public class BukkitQueue17 extends BukkitQueue_0<Chunk, ChunkSection[], ChunkSec
if (folder.exists() && !folder.isDirectory()) { if (folder.exists() && !folder.isDirectory()) {
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
} }
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
try {
Field field = CraftServer.class.getDeclaredField("worlds");
field.setAccessible(true);
Map<Object, Object> existing = (Map<Object, Object>) field.get(server);
if (!existing.getClass().getName().contains("SynchronizedMap")) {
field.set(server, Collections.synchronizedMap(existing));
}
} catch (Throwable e) {
e.printStackTrace();
}
}
});
if (generator == null) { if (generator == null) {
generator = server.getGenerator(name); generator = server.getGenerator(name);
} }

View File

@ -22,6 +22,7 @@ import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -540,6 +541,21 @@ public class BukkitQueue18R3 extends BukkitQueue_0<Chunk, ChunkSection[], ChunkS
if (folder.exists() && !folder.isDirectory()) { if (folder.exists() && !folder.isDirectory()) {
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
} }
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
try {
Field field = CraftServer.class.getDeclaredField("worlds");
field.setAccessible(true);
Map<Object, Object> existing = (Map<Object, Object>) field.get(server);
if (!existing.getClass().getName().contains("SynchronizedMap")) {
field.set(server, Collections.synchronizedMap(existing));
}
} catch (Throwable e) {
e.printStackTrace();
}
}
});
if (generator == null) { if (generator == null) {
generator = server.getGenerator(name); generator = server.getGenerator(name);
} }

View File

@ -23,6 +23,7 @@ import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -186,6 +187,21 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0<Chunk, ChunkSection[], Chu
if (folder.exists() && !folder.isDirectory()) { if (folder.exists() && !folder.isDirectory()) {
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder"); throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
} }
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
try {
Field field = CraftServer.class.getDeclaredField("worlds");
field.setAccessible(true);
Map<Object, Object> existing = (Map<Object, Object>) field.get(server);
if (!existing.getClass().getName().contains("SynchronizedMap")) {
field.set(server, Collections.synchronizedMap(existing));
}
} catch (Throwable e) {
e.printStackTrace();
}
}
});
if (generator == null) { if (generator == null) {
generator = server.getGenerator(name); generator = server.getGenerator(name);
} }

View File

@ -32,7 +32,6 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
@ -54,8 +53,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/** /**
* The FaweAPI class offers a few useful functions.<br> * The FaweAPI class offers a few useful functions.<br>
@ -137,10 +136,11 @@ public class FaweAPI {
@Override @Override
public void run(OutputStream value) { public void run(OutputStream value) {
try { try {
GZIPOutputStream gzip = new GZIPOutputStream(value, true); value.write(new String("test").getBytes());
ClipboardWriter writer = format.getWriter(gzip); // GZIPOutputStream gzip = new GZIPOutputStream(value, true);
writer.write(clipboard, null); // ClipboardWriter writer = format.getWriter(gzip);
gzip.flush(); // writer.write(clipboard, null);
// gzip.flush();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -390,6 +390,10 @@ public class FaweAPI {
* @return * @return
*/ */
public static int fixLighting(String world, Region selection, final FaweQueue.RelightMode mode) { public static int fixLighting(String world, Region selection, final FaweQueue.RelightMode mode) {
return fixLighting(world, selection, null, mode);
}
public static int fixLighting(String world, Region selection, @Nullable FaweQueue queue, final FaweQueue.RelightMode mode) {
final Vector bot = selection.getMinimumPoint(); final Vector bot = selection.getMinimumPoint();
final Vector top = selection.getMaximumPoint(); final Vector top = selection.getMaximumPoint();
@ -400,7 +404,9 @@ public class FaweAPI {
final int maxZ = top.getBlockZ() >> 4; final int maxZ = top.getBlockZ() >> 4;
int count = 0; int count = 0;
final FaweQueue queue = SetQueue.IMP.getNewQueue(world, true, false); if (queue == null) {
queue = SetQueue.IMP.getNewQueue(world, true, false);
}
// Remove existing lighting first // Remove existing lighting first
if (queue instanceof NMSMappedFaweQueue) { if (queue instanceof NMSMappedFaweQueue) {
final NMSMappedFaweQueue nmsQueue = (NMSMappedFaweQueue) queue; final NMSMappedFaweQueue nmsQueue = (NMSMappedFaweQueue) queue;

View File

@ -31,7 +31,6 @@ public class Commands {
public static Command translate(final Command command) { public static Command translate(final Command command) {
if (cmdConfig == null || command instanceof TranslatedCommand) { if (cmdConfig == null || command instanceof TranslatedCommand) {
System.out.println("NO TRANSLATION FOR " + command.aliases()[0]);
return command; return command;
} }
return new TranslatedCommand(command); return new TranslatedCommand(command);

View File

@ -269,8 +269,7 @@ public class MainUtil {
URLConnection con = new URL(website).openConnection(); URLConnection con = new URL(website).openConnection();
con.setDoOutput(true); con.setDoOutput(true);
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
try (OutputStream output = con.getOutputStream(); try (OutputStream output = con.getOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) {
String CRLF = "\r\n"; String CRLF = "\r\n";
writer.append("--" + boundary).append(CRLF); writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF); writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);

View File

@ -43,15 +43,6 @@ public class MathMan {
253, 254, 254, 255 253, 254, 254, 255
}; };
public static void main(String[] args) {
double val;
val = 10.2;
System.out.println(inverseRound(10.2) + " " + 11);
System.out.println(inverseRound(10.8) + " " + 10);
System.out.println(inverseRound(-10.2) + " " + -11);
System.out.println(inverseRound(-10.8) + " " + -10);
}
public static long inverseRound(double val) { public static long inverseRound(double val) {
long round = Math.round(val); long round = Math.round(val);
return (long) (round + Math.signum(val - round)); return (long) (round + Math.signum(val - round));

View File

@ -298,6 +298,14 @@ public final class NBTOutputStream implements Closeable {
os.close(); os.close();
} }
/**
* Flush output.
* @throws IOException
*/
public void flush() throws IOException {
this.os.flush();
}
public static Class<?> inject() { public static Class<?> inject() {
return NBTOutputStream.class; return NBTOutputStream.class;
} }

View File

@ -53,6 +53,7 @@ import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
@ -223,6 +224,17 @@ public class ClipboardCommands {
} }
ClipboardHolder holder = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.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, formatName); BBC.GENERATING_LINK.send(player, formatName);
URL url; URL url;
switch (format) { switch (format) {
@ -230,7 +242,7 @@ public class ClipboardCommands {
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(clipboard, null); writer.write(target, null);
baos.flush(); baos.flush();
url = ImgurUtility.uploadImage(baos.toByteArray()); url = ImgurUtility.uploadImage(baos.toByteArray());
} catch (IOException e) { } catch (IOException e) {
@ -239,7 +251,7 @@ public class ClipboardCommands {
} }
break; break;
case SCHEMATIC: case SCHEMATIC:
url = FaweAPI.upload(clipboard, format); url = FaweAPI.upload(target, format);
break; break;
default: default:
url = null; url = null;

View File

@ -103,11 +103,10 @@ public class RegionCommands {
public void fixlighting(Player player, EditSession editSession) throws WorldEditException { public void fixlighting(Player player, EditSession editSession) throws WorldEditException {
FawePlayer fp = FawePlayer.wrap(player); FawePlayer fp = FawePlayer.wrap(player);
final FaweLocation loc = fp.getLocation(); final FaweLocation loc = fp.getLocation();
final int cx = loc.x >> 4;
final int cz = loc.z >> 4;
Region selection = fp.getSelection(); Region selection = fp.getSelection();
if (selection == null) { if (selection == null) {
final int cx = loc.x >> 4;
final int cz = loc.z >> 4;
selection = new CuboidRegion(new Vector(cx - 8, 0, cz - 8).multiply(16), new Vector(cx + 8, 0, cz + 8).multiply(16)); selection = new CuboidRegion(new Vector(cx - 8, 0, cz - 8).multiply(16), new Vector(cx + 8, 0, cz + 8).multiply(16));
} }
int count = FaweAPI.fixLighting(loc.world, selection, FaweQueue.RelightMode.ALL); int count = FaweAPI.fixLighting(loc.world, selection, FaweQueue.RelightMode.ALL);
@ -124,11 +123,10 @@ public class RegionCommands {
public void removelighting(Player player, EditSession editSession) { public void removelighting(Player player, EditSession editSession) {
FawePlayer fp = FawePlayer.wrap(player); FawePlayer fp = FawePlayer.wrap(player);
final FaweLocation loc = fp.getLocation(); final FaweLocation loc = fp.getLocation();
final int cx = loc.x >> 4;
final int cz = loc.z >> 4;
Region selection = fp.getSelection(); Region selection = fp.getSelection();
if (selection == null) { if (selection == null) {
final int cx = loc.x >> 4;
final int cz = loc.z >> 4;
selection = new CuboidRegion(new Vector(cx - 8, 0, cz - 8).multiply(16), new Vector(cx + 8, 0, cz + 8).multiply(16)); selection = new CuboidRegion(new Vector(cx - 8, 0, cz - 8).multiply(16), new Vector(cx + 8, 0, cz + 8).multiply(16));
} }
int count = FaweAPI.fixLighting(loc.world, selection, FaweQueue.RelightMode.NONE); int count = FaweAPI.fixLighting(loc.world, selection, FaweQueue.RelightMode.NONE);
@ -238,7 +236,7 @@ public class RegionCommands {
@Optional("0") @Range(min = 0) int thickness, @Optional("0") @Range(min = 0) int thickness,
@Switch('h') boolean shell) throws WorldEditException { @Switch('h') boolean shell) throws WorldEditException {
if (!(region instanceof ConvexPolyhedralRegion)) { if (!(region instanceof ConvexPolyhedralRegion)) {
player.printError("//line only works with convex polyhedral selections"); player.printError("//curve only works with convex polyhedral selections");
return; return;
} }

View File

@ -108,6 +108,7 @@ public class SchematicWriter implements ClipboardWriter {
@Override @Override
public void write(Clipboard clipboard, WorldData data) throws IOException { public void write(Clipboard clipboard, WorldData data) throws IOException {
outputStream.writeNamedTag("Schematic", writeTag(clipboard)); outputStream.writeNamedTag("Schematic", writeTag(clipboard));
outputStream.flush();
} }
public static CompoundTag writeTag(Clipboard clipboard) { public static CompoundTag writeTag(Clipboard clipboard) {