diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 0a01fb42..3b236d57 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.utils; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.EditSessionFactory; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitWorld; @@ -190,25 +191,36 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } @Override - public boolean backup(Point minPoint, Point maxPoint, File file) { + public Clipboard copy(Point minPoint, Point maxPoint, Point copyPoint) { BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0)); CuboidRegion region = new CuboidRegion(bukkitWorld, toBlockVector3(minPoint), toBlockVector3(maxPoint)); - BlockArrayClipboard clipboard = new BlockArrayClipboard(region); + Clipboard clipboard = new BlockArrayClipboard(region); try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(bukkitWorld, -1)) { ForwardExtentCopy copy = new ForwardExtentCopy( - e, region, clipboard, region.getMinimumPoint() + e, region, toBlockVector3(copyPoint), clipboard, toBlockVector3(copyPoint) ); copy.setCopyingEntities(false); copy.setCopyingBiomes(false); Operations.complete(copy); + return clipboard; + } catch (WorldEditException e) { + Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e); + return null; + } + } - try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) { - writer.write(clipboard); - } + @Override + public boolean backup(Point minPoint, Point maxPoint, File file) { + Clipboard clipboard = copy(minPoint, maxPoint, minPoint); + if (clipboard == null) { + return false; + } + try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) { + writer.write(clipboard); return true; - } catch (WorldEditException | IOException e) { + } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e); return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCopyCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCopyCommand.java new file mode 100644 index 00000000..19e1f843 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCopyCommand.java @@ -0,0 +1,62 @@ +package de.steamwar.bausystem.features.region; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.session.ClipboardHolder; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.util.SelectCommand; +import de.steamwar.bausystem.region.Point; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.shared.Pair; +import de.steamwar.bausystem.utils.FlatteningWrapper; +import de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.command.SWCommand; +import de.steamwar.core.WorldEditWrapper; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; +import de.steamwar.sql.NoClipboardException; +import org.bukkit.Location; +import org.bukkit.entity.Player; + + +// Command +@Linked // Annotation, zur compile time, erzeugt Instance des RegionCopy commands +public class RegionCopyCommand extends SWCommand { + @LinkedInstance + public SelectCommand selectCommand; + public RegionCopyCommand() { + super("rgc"); + } + + // Entry Point + @Register + public void genericCommand(Player executer) { + Region region = Region.getRegion(executer.getLocation()); + + if (region.isGlobal()) { + BauSystem.MESSAGE.send("SELECT_GLOBAL_REGION", executer); + return; + } + + if (!region.hasType(RegionType.BUILD)) { + BauSystem.MESSAGE.send("SELECT_NO_TYPE", executer, BauSystem.MESSAGE.parse(RegionType.BUILD.getChatValue(), executer)); + return; + } + Clipboard clipboard = FlatteningWrapper.impl.copy(region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL), region.getMaxPoint(RegionType.BUILD, RegionExtensionType.NORMAL), region.getCopyPoint()); + if (clipboard == null) { + throw new NoClipboardException(); + } + // actor = jmd der was ausführt + Actor actor = WorldEditWrapper.getWorldEditPlugin().wrapCommandSender(executer); + // Setze das Spielerclipboard zum aktuell kopierten clipboard + WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard)); + } +} + + +// rgc -aso +// rgp -aso +// tbc -aso \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java index aef0b302..3cd96295 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java @@ -46,6 +46,7 @@ public interface FlatteningWrapper { Clipboard loadSchematic(File file); EditSession paste(PasteBuilder pasteBuilder); + Clipboard copy(Point minPoint, Point maxPoint, Point copyPoint); boolean backup(Point minPoint, Point maxPoint, File file); boolean inWater(World world, Vector tntPosition);