From b18e53e79f94d7574446c22588dc381215f4bd66 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 2 Sep 2016 13:23:58 +1000 Subject: [PATCH] Fix schematic downloading --- .../fawe/bukkit/v1_10/BukkitQueue_1_10.java | 16 +++++++++++++++ .../fawe/bukkit/v1_7/BukkitQueue17.java | 16 +++++++++++++++ .../fawe/bukkit/v1_8/BukkitQueue18R3.java | 16 +++++++++++++++ .../fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java | 16 +++++++++++++++ .../main/java/com/boydti/fawe/FaweAPI.java | 20 ++++++++++++------- .../java/com/boydti/fawe/config/Commands.java | 1 - .../java/com/boydti/fawe/util/MainUtil.java | 3 +-- .../java/com/boydti/fawe/util/MathMan.java | 9 --------- .../java/com/sk89q/jnbt/NBTOutputStream.java | 8 ++++++++ .../worldedit/command/ClipboardCommands.java | 16 +++++++++++++-- .../worldedit/command/RegionCommands.java | 12 +++++------ .../extent/clipboard/io/SchematicWriter.java | 1 + 12 files changed, 106 insertions(+), 28 deletions(-) diff --git a/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitQueue_1_10.java b/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitQueue_1_10.java index 932ffbc5..943f85d9 100644 --- a/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitQueue_1_10.java +++ b/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitQueue_1_10.java @@ -24,6 +24,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -136,6 +137,21 @@ public class BukkitQueue_1_10 extends BukkitQueue_0() { + @Override + public void run(Object value) { + try { + Field field = CraftServer.class.getDeclaredField("worlds"); + field.setAccessible(true); + Map existing = (Map) field.get(server); + if (!existing.getClass().getName().contains("SynchronizedMap")) { + field.set(server, Collections.synchronizedMap(existing)); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + }); if (generator == null) { generator = server.getGenerator(name); } diff --git a/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitQueue17.java b/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitQueue17.java index 6e52d2e1..36db07f0 100644 --- a/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitQueue17.java +++ b/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitQueue17.java @@ -21,6 +21,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -564,6 +565,21 @@ public class BukkitQueue17 extends BukkitQueue_0() { + @Override + public void run(Object value) { + try { + Field field = CraftServer.class.getDeclaredField("worlds"); + field.setAccessible(true); + Map existing = (Map) field.get(server); + if (!existing.getClass().getName().contains("SynchronizedMap")) { + field.set(server, Collections.synchronizedMap(existing)); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + }); if (generator == null) { generator = server.getGenerator(name); } diff --git a/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java b/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java index 8a1cbf89..0f3c1432 100644 --- a/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java +++ b/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java @@ -22,6 +22,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -540,6 +541,21 @@ public class BukkitQueue18R3 extends BukkitQueue_0() { + @Override + public void run(Object value) { + try { + Field field = CraftServer.class.getDeclaredField("worlds"); + field.setAccessible(true); + Map existing = (Map) field.get(server); + if (!existing.getClass().getName().contains("SynchronizedMap")) { + field.set(server, Collections.synchronizedMap(existing)); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + }); if (generator == null) { generator = server.getGenerator(name); } diff --git a/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java b/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java index ef91363b..9a33db82 100644 --- a/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java +++ b/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java @@ -23,6 +23,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -186,6 +187,21 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0() { + @Override + public void run(Object value) { + try { + Field field = CraftServer.class.getDeclaredField("worlds"); + field.setAccessible(true); + Map existing = (Map) field.get(server); + if (!existing.getClass().getName().contains("SynchronizedMap")) { + field.set(server, Collections.synchronizedMap(existing)); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + }); if (generator == null) { generator = server.getGenerator(name); } diff --git a/core/src/main/java/com/boydti/fawe/FaweAPI.java b/core/src/main/java/com/boydti/fawe/FaweAPI.java index 2842b099..e01ed734 100644 --- a/core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -32,7 +32,6 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; 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.world.AbstractWorld; import com.sk89q.worldedit.world.World; @@ -54,8 +53,8 @@ import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; import javax.annotation.Nonnull; +import javax.annotation.Nullable; /** * The FaweAPI class offers a few useful functions.
@@ -137,10 +136,11 @@ public class FaweAPI { @Override public void run(OutputStream value) { try { - GZIPOutputStream gzip = new GZIPOutputStream(value, true); - ClipboardWriter writer = format.getWriter(gzip); - writer.write(clipboard, null); - gzip.flush(); + value.write(new String("test").getBytes()); +// GZIPOutputStream gzip = new GZIPOutputStream(value, true); +// ClipboardWriter writer = format.getWriter(gzip); +// writer.write(clipboard, null); +// gzip.flush(); } catch (IOException e) { e.printStackTrace(); } @@ -390,6 +390,10 @@ public class FaweAPI { * @return */ 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 top = selection.getMaximumPoint(); @@ -400,7 +404,9 @@ public class FaweAPI { final int maxZ = top.getBlockZ() >> 4; 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 if (queue instanceof NMSMappedFaweQueue) { final NMSMappedFaweQueue nmsQueue = (NMSMappedFaweQueue) queue; diff --git a/core/src/main/java/com/boydti/fawe/config/Commands.java b/core/src/main/java/com/boydti/fawe/config/Commands.java index 0c98a0a8..cd178c68 100644 --- a/core/src/main/java/com/boydti/fawe/config/Commands.java +++ b/core/src/main/java/com/boydti/fawe/config/Commands.java @@ -31,7 +31,6 @@ public class Commands { public static Command translate(final Command command) { if (cmdConfig == null || command instanceof TranslatedCommand) { - System.out.println("NO TRANSLATION FOR " + command.aliases()[0]); return command; } return new TranslatedCommand(command); diff --git a/core/src/main/java/com/boydti/fawe/util/MainUtil.java b/core/src/main/java/com/boydti/fawe/util/MainUtil.java index 2e111720..7ffdf973 100644 --- a/core/src/main/java/com/boydti/fawe/util/MainUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MainUtil.java @@ -269,8 +269,7 @@ public class MainUtil { URLConnection con = new URL(website).openConnection(); con.setDoOutput(true); con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); - try (OutputStream output = con.getOutputStream(); - PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) { + try (OutputStream output = con.getOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) { String CRLF = "\r\n"; writer.append("--" + boundary).append(CRLF); writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF); diff --git a/core/src/main/java/com/boydti/fawe/util/MathMan.java b/core/src/main/java/com/boydti/fawe/util/MathMan.java index 3d0e98ea..36f47ac3 100644 --- a/core/src/main/java/com/boydti/fawe/util/MathMan.java +++ b/core/src/main/java/com/boydti/fawe/util/MathMan.java @@ -43,15 +43,6 @@ public class MathMan { 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) { long round = Math.round(val); return (long) (round + Math.signum(val - round)); diff --git a/core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java b/core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java index 6d94b718..03425dfe 100644 --- a/core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java +++ b/core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java @@ -298,6 +298,14 @@ public final class NBTOutputStream implements Closeable { os.close(); } + /** + * Flush output. + * @throws IOException + */ + public void flush() throws IOException { + this.os.flush(); + } + public static Class inject() { return NBTOutputStream.class; } diff --git a/core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 502ef0b8..524cfbd9 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -53,6 +53,7 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Selection; 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.Region; import com.sk89q.worldedit.regions.RegionSelector; @@ -223,6 +224,17 @@ public class ClipboardCommands { } 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, formatName); URL url; switch (format) { @@ -230,7 +242,7 @@ public class ClipboardCommands { try { FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE); ClipboardWriter writer = format.getWriter(baos); - writer.write(clipboard, null); + writer.write(target, null); baos.flush(); url = ImgurUtility.uploadImage(baos.toByteArray()); } catch (IOException e) { @@ -239,7 +251,7 @@ public class ClipboardCommands { } break; case SCHEMATIC: - url = FaweAPI.upload(clipboard, format); + url = FaweAPI.upload(target, format); break; default: url = null; diff --git a/core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 91a4191c..7b75cc4c 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -103,11 +103,10 @@ public class RegionCommands { public void fixlighting(Player player, EditSession editSession) throws WorldEditException { FawePlayer fp = FawePlayer.wrap(player); final FaweLocation loc = fp.getLocation(); - final int cx = loc.x >> 4; - final int cz = loc.z >> 4; - Region selection = fp.getSelection(); 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)); } int count = FaweAPI.fixLighting(loc.world, selection, FaweQueue.RelightMode.ALL); @@ -124,11 +123,10 @@ public class RegionCommands { public void removelighting(Player player, EditSession editSession) { FawePlayer fp = FawePlayer.wrap(player); final FaweLocation loc = fp.getLocation(); - final int cx = loc.x >> 4; - final int cz = loc.z >> 4; - Region selection = fp.getSelection(); 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)); } int count = FaweAPI.fixLighting(loc.world, selection, FaweQueue.RelightMode.NONE); @@ -238,7 +236,7 @@ public class RegionCommands { @Optional("0") @Range(min = 0) int thickness, @Switch('h') boolean shell) throws WorldEditException { if (!(region instanceof ConvexPolyhedralRegion)) { - player.printError("//line only works with convex polyhedral selections"); + player.printError("//curve only works with convex polyhedral selections"); return; } diff --git a/core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java b/core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java index e6f146f1..b5edc8c7 100644 --- a/core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java +++ b/core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java @@ -108,6 +108,7 @@ public class SchematicWriter implements ClipboardWriter { @Override public void write(Clipboard clipboard, WorldData data) throws IOException { outputStream.writeNamedTag("Schematic", writeTag(clipboard)); + outputStream.flush(); } public static CompoundTag writeTag(Clipboard clipboard) {