diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index 075f4b5f2..4b23247d2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -264,6 +264,7 @@ public class SchematicCmd extends SubCommand { @Override public void run() { MainUtil.sendMessage(plr, "&aFinished export"); + SchematicCmd.this.running = false; } }); if (!result) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 16d39e517..a485cbd5c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -61,7 +61,6 @@ public abstract class SchematicHandler { Iterator i = plots.iterator(); final Plot plot = i.next(); i.remove(); - final CompoundTag sch = SchematicHandler.manager.getCompoundTag(plot.world, plot.id); String o = UUIDHandler.getName(plot.owner); if (o == null) { o = "unknown"; @@ -80,21 +79,27 @@ public abstract class SchematicHandler { else { directory = outputDir.getPath(); } - if (sch == null) { - MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id); - } else { - TaskManager.runTaskAsync(new Runnable() { - @Override - public void run() { - MainUtil.sendMessage(null, "&6ID: " + plot.id); - final boolean result = SchematicHandler.manager.save(sch, directory + File.separator + name + ".schematic"); - if (!result) { - MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id); - } else { - MainUtil.sendMessage(null, "&7 - &a success: " + plot.id); + if (PlotSquared.worldEdit != null) { + new WorldEditSchematic().saveSchematic(directory + File.separator + name + ".schematic", plot.world, plot.id); + } + else { + final CompoundTag sch = SchematicHandler.manager.getCompoundTag(plot.world, plot.id); + if (sch == null) { + MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id); + } else { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(null, "&6ID: " + plot.id); + final boolean result = SchematicHandler.manager.save(sch, directory + File.separator + name + ".schematic"); + if (!result) { + MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id); + } else { + MainUtil.sendMessage(null, "&7 - &a success: " + plot.id); + } } - } - }); + }); + } } } }, 20); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/WorldEditSchematic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/WorldEditSchematic.java new file mode 100644 index 000000000..c23f6549c --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/WorldEditSchematic.java @@ -0,0 +1,42 @@ +package com.intellectualcrafters.plot.util; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.Bukkit; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.PlotId; +import com.sk89q.worldedit.CuboidClipboard; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.data.DataException; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.schematic.MCEditSchematicFormat; +import com.sk89q.worldedit.schematic.SchematicFormat; + +public class WorldEditSchematic { + public void saveSchematic(String file, final String world, final PlotId id) { + System.out.print("SAVCING SCHSAKJHDJKAS HDKAS"); + Location bot = MainUtil.getPlotBottomLoc(world, id).add(1, 0, 1); + Location top = MainUtil.getPlotTopLoc(world, id); + Vector size = new Vector(top.getX() - bot.getX() + 1, top.getY() - bot.getY() - 1, top.getZ() - bot.getZ() + 1); + Vector origin = new Vector(bot.getX(), bot.getY(), bot.getZ()); + CuboidClipboard clipboard = new CuboidClipboard(size, origin); + Vector pos1 = new Vector(bot.getX(), bot.getY(), bot.getZ()); + Vector pos2 = new Vector(top.getX(), top.getY(), top.getZ()); + CuboidRegion region = new CuboidRegion(pos1, pos2); + EditSession session = PlotSquared.worldEdit.getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorld(world)), 999999999); + clipboard.copy(session); + try { + clipboard.saveSchematic(new File(file)); + MainUtil.sendMessage(null, "&7 - &a success: " + id); + } catch (Exception e) { + e.printStackTrace(); + MainUtil.sendMessage(null, "&7 - Failed to save &c" + id); + } + } +}