3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-08 04:20:06 +01:00

Reformat paste in ClipboardCommands because it was ugly

Dieser Commit ist enthalten in:
dordsor21 2020-04-23 17:01:17 +01:00
Ursprung 8bde932354
Commit c714e26f68

Datei anzeigen

@ -19,12 +19,9 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.boydti.fawe.config.Caption;
import com.google.common.collect.Lists;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.boydti.fawe.config.Caption;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
@ -36,6 +33,7 @@ import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.util.ImgurUtility; import com.boydti.fawe.util.ImgurUtility;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MaskTraverser; import com.boydti.fawe.util.MaskTraverser;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -55,10 +53,7 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.function.block.BlockReplace; import com.sk89q.worldedit.function.block.BlockReplace;
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.Operations;
@ -75,8 +70,9 @@ import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
@ -91,12 +87,13 @@ import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
import java.util.List; import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
/** /**
@ -374,34 +371,25 @@ public class ClipboardCommands {
} }
} }
@Command( @Command(name = "/paste", aliases = {"/p", "/pa"}, desc = "Paste the clipboard's contents"
name = "/paste",
aliases = { "/p", "/pa" },
desc = "Paste the clipboard's contents"
) )
@CommandPermissions("worldedit.clipboard.paste") @CommandPermissions("worldedit.clipboard.paste")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void paste(Actor actor, World world, LocalSession session, EditSession editSession, public void paste(Actor actor, World world, LocalSession session, EditSession editSession,
@Switch(name = 'a', desc = "Skip air blocks") @Switch(name = 'a', desc = "Skip air blocks") boolean ignoreAirBlocks,
boolean ignoreAirBlocks, @Switch(name = 'o', desc = "Paste at the original position") boolean atOrigin,
@Switch(name = 'o', desc = "Paste at the original position") @Switch(name = 's', desc = "Select the region after pasting") boolean selectPasted,
boolean atOrigin, @Switch(name = 'n', desc = "No paste, select only. (Implies -s)") boolean onlySelect,
@Switch(name = 's', desc = "Select the region after pasting") @Switch(name = 'e', desc = "Paste entities if available") boolean pasteEntities,
boolean selectPasted, @Switch(name = 'b', desc = "Paste biomes if available") boolean pasteBiomes,
@Switch(name = 'n', desc = "No paste, select only. (Implies -s)") @ArgFlag(name = 'm', desc = "Only paste blocks matching this mask", def = "") @ClipboardMask
boolean onlySelect,
@Switch(name = 'e', desc = "Paste entities if available")
boolean pasteEntities,
@Switch(name = 'b', desc = "Paste biomes if available")
boolean pasteBiomes,
@ArgFlag(name = 'm', desc = "Only paste blocks matching this mask", def = "")
@ClipboardMask
Mask sourceMask) throws WorldEditException { Mask sourceMask) throws WorldEditException {
ClipboardHolder holder = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
if (holder.getTransform().isIdentity() && editSession.getSourceMask() == null) { if (holder.getTransform().isIdentity() && editSession.getSourceMask() == null) {
place(actor, world, session, editSession, ignoreAirBlocks, atOrigin, selectPasted, pasteEntities, pasteBiomes); place(actor, world, session, editSession, ignoreAirBlocks, atOrigin, selectPasted,
pasteEntities, pasteBiomes);
return; return;
} }
Clipboard clipboard = holder.getClipboard(); Clipboard clipboard = holder.getClipboard();
@ -412,23 +400,23 @@ public class ClipboardCommands {
checkPaste(actor, editSession, to, holder, clipboard); checkPaste(actor, editSession, to, holder, clipboard);
if (!onlySelect) { if (!onlySelect) {
Operation operation = holder Operation operation =
.createPaste(editSession) holder.createPaste(editSession).to(to).ignoreAirBlocks(ignoreAirBlocks)
.to(to) .copyBiomes(pasteBiomes).copyEntities(pasteEntities).maskSource(sourceMask)
.ignoreAirBlocks(ignoreAirBlocks)
.copyBiomes(pasteBiomes)
.copyEntities(pasteEntities)
.maskSource(sourceMask)
.build(); .build();
Operations.completeLegacy(operation); Operations.completeLegacy(operation);
messages.addAll(Lists.newArrayList(operation.getStatusMessages())); messages.addAll(Lists.newArrayList(operation.getStatusMessages()));
} }
if (selectPasted || onlySelect) { if (selectPasted || onlySelect) {
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); BlockVector3 clipboardOffset =
Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3())); clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
Vector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3())); Vector3 realTo =
RegionSelector selector = new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint()); to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3()));
Vector3 max = realTo.add(holder.getTransform()
.apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()));
RegionSelector selector =
new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
session.setRegionSelector(world, selector); session.setRegionSelector(world, selector);
selector.learnChanges(); selector.learnChanges();
selector.explainRegionAdjust(actor, session); selector.explainRegionAdjust(actor, session);
@ -436,7 +424,8 @@ public class ClipboardCommands {
if (onlySelect) { if (onlySelect) {
actor.printInfo(TranslatableComponent.of("worldedit.paste.selected")); actor.printInfo(TranslatableComponent.of("worldedit.paste.selected"));
} else { } else {
actor.printInfo(TranslatableComponent.of("worldedit.paste.pasted", TextComponent.of(to.toString()))); actor.printInfo(TranslatableComponent
.of("worldedit.paste.pasted", TextComponent.of(to.toString())));
} }
messages.forEach(actor::print); messages.forEach(actor::print);
} }