Skip to content

Commit

Permalink
Added flags to copy biomes and entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Jun 13, 2019
1 parent 9af897b commit 3c90038
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -42,7 +42,7 @@ public AreaCommands(CraftBookPlugin plugin) {

private CraftBookPlugin plugin = CraftBookPlugin.inst();

@Command(aliases = {"save"}, desc = "Saves the selected area", usage = "[-n namespace ] <id>", flags = "n:", min = 1)
@Command(aliases = {"save"}, desc = "Saves the selected area", usage = "[-n namespace ] <id> [-e] [-b]", flags = "ebn:", min = 1)
public void saveArea(CommandContext context, CommandSender sender) throws CommandException {

if (!(sender instanceof Player)) return;
Expand All @@ -52,6 +52,9 @@ public void saveArea(CommandContext context, CommandSender sender) throws Comman
String namespace = player.getCraftBookId();
boolean personal = true;

boolean copyEntities = context.hasFlag('e');
boolean copyBiomes = context.hasFlag('b');

if (context.hasFlag('n')) {
if (!player.hasPermission("craftbook.mech.area.save." + context.getFlag('n')))
throw new CommandException("You do not have permission to use this namespace.");
Expand Down Expand Up @@ -105,7 +108,7 @@ public void saveArea(CommandContext context, CommandSender sender) throws Comman
}

// Copy
BlockArrayClipboard copy = CopyManager.getInstance().copy(sel);
BlockArrayClipboard copy = CopyManager.getInstance().copy(sel, copyEntities, copyBiomes);

plugin.getServer().getLogger().info(player.getName() + " saving toggle area with folder '" + namespace +
"' and ID '" + id + "'.");
Expand Down
Expand Up @@ -220,13 +220,25 @@ public void save(String namespace, String id, BlockArrayClipboard clipboard) thr
* @throws WorldEditException If something went wrong.
*/
public BlockArrayClipboard copy(Region region) throws WorldEditException {
return copy(region, false, false);
}

/**
* Copies a region into the BlockArrayClipboard.
*
* @param region The region
* @return The BlockArrayClipboard
* @throws WorldEditException If something went wrong.
*/
public BlockArrayClipboard copy(Region region, boolean copyEntities, boolean copyBiomes) throws WorldEditException {
BlockArrayClipboard copy = new BlockArrayClipboard(region);
// copy.setOrigin(origin);

EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(region.getWorld(), -1);

ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, region, copy, region.getMinimumPoint());
forwardExtentCopy.setCopyingEntities(true);
forwardExtentCopy.setCopyingEntities(copyEntities);
forwardExtentCopy.setCopyingBiomes(copyBiomes);
Operations.complete(forwardExtentCopy);

return copy;
Expand All @@ -244,6 +256,8 @@ public void paste(BlockArrayClipboard clipboard) throws WorldEditException {
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(clipboard.getOrigin())
.copyBiomes(true)
.copyEntities(true)
.ignoreAirBlocks(false)
.build();

Expand Down

0 comments on commit 3c90038

Please sign in to comment.