Skip to content
Permalink
Browse files

Allow a majority of commands to be performed by the console.

  • Loading branch information...
me4502 committed Jul 21, 2019
1 parent ce1055b commit 4ec513f26c8a2e9e5524372f2f96ca0bb4df5c56
@@ -28,6 +28,7 @@
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.anvil.ChunkDeleter;
import com.sk89q.worldedit.internal.anvil.ChunkDeletionInfo;
import com.sk89q.worldedit.math.BlockVector2;
@@ -39,6 +40,7 @@
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.LegacyChunkStore;
import com.sk89q.worldedit.world.storage.McRegionChunkStore;
import org.enginehub.piston.annotation.Command;
@@ -93,13 +95,13 @@ public void chunkInfo(Player player) {
desc = "List chunks that your selection includes"
)
@CommandPermissions("worldedit.listchunks")
public void listChunks(Player player, LocalSession session,
public void listChunks(Actor actor, World world, LocalSession session,
@ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) throws WorldEditException {
final Region region = session.getSelection(player.getWorld());
final Region region = session.getSelection(world);

WorldEditAsyncCommandBuilder.createAndSendMessage(player,
WorldEditAsyncCommandBuilder.createAndSendMessage(actor,
() -> new ChunkListPaginationBox(region).create(page),
"Listing chunks for " + player.getName());
"Listing chunks for " + actor.getName());
}

@Command(
@@ -108,10 +110,10 @@ public void listChunks(Player player, LocalSession session,
)
@CommandPermissions("worldedit.delchunks")
@Logging(REGION)
public void deleteChunks(Player player, LocalSession session,
public void deleteChunks(Actor actor, World world, LocalSession session,
@ArgFlag(name = 'o', desc = "Only delete chunks older than the specified time.", def = "")
ZonedDateTime beforeTime) throws WorldEditException {
Path worldDir = player.getWorld().getStoragePath();
Path worldDir = world.getStoragePath();
if (worldDir == null) {
throw new StopExecutionException(TextComponent.of("Couldn't find world folder for this world."));
}
@@ -134,7 +136,7 @@ public void deleteChunks(Player player, LocalSession session,
ChunkDeletionInfo.ChunkBatch newBatch = new ChunkDeletionInfo.ChunkBatch();
newBatch.worldPath = worldDir.toAbsolutePath().normalize().toString();
newBatch.backup = true;
final Region selection = session.getSelection(player.getWorld());
final Region selection = session.getSelection(world);
if (selection instanceof CuboidRegion) {
newBatch.minChunk = selection.getMinimumPoint().shr(4).toBlockVector2();
newBatch.maxChunk = selection.getMaximumPoint().shr(4).toBlockVector2();
@@ -159,13 +161,13 @@ public void deleteChunks(Player player, LocalSession session,
throw new StopExecutionException(TextComponent.of("Failed to write chunk list: " + e.getMessage()));
}

player.print(String.format("%d chunk(s) have been marked for deletion the next time the server starts.",
actor.print(String.format("%d chunk(s) have been marked for deletion the next time the server starts.",
newBatch.getChunkCount()));
if (currentInfo.batches.size() > 1) {
player.printDebug(String.format("%d chunks total marked for deletion. (May have overlaps).",
actor.printDebug(String.format("%d chunks total marked for deletion. (May have overlaps).",
currentInfo.batches.stream().mapToInt(ChunkDeletionInfo.ChunkBatch::getChunkCount).sum()));
}
player.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", TextColor.LIGHT_PURPLE)
actor.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", TextColor.LIGHT_PURPLE)
.append(TextComponent.of("/stop", TextColor.AQUA)
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop"))));
}
@@ -26,7 +26,7 @@
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.block.BlockReplace;
@@ -44,6 +44,7 @@
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
@@ -66,7 +67,7 @@
desc = "Copy the selection to the clipboard"
)
@CommandPermissions("worldedit.clipboard.copy")
public void copy(Player player, LocalSession session, EditSession editSession,
public void copy(Actor actor, LocalSession session, EditSession editSession,
@Selection Region region,
@Switch(name = 'e', desc = "Also copy entities")
boolean copyEntities,
@@ -75,7 +76,7 @@ public void copy(Player player, LocalSession session, EditSession editSession,
@ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air", def = "")
Mask mask) throws WorldEditException {
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
clipboard.setOrigin(session.getPlacementPosition(player));
clipboard.setOrigin(session.getPlacementPosition(actor));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setCopyingEntities(copyEntities);
copy.setCopyingBiomes(copyBiomes);
@@ -87,7 +88,7 @@ public void copy(Player player, LocalSession session, EditSession editSession,

List<String> messages = Lists.newArrayList();
copy.addStatusMessages(messages);
messages.forEach(player::print);
messages.forEach(actor::print);
}

@Command(
@@ -96,7 +97,7 @@ public void copy(Player player, LocalSession session, EditSession editSession,
)
@CommandPermissions("worldedit.clipboard.cut")
@Logging(REGION)
public void cut(Player player, LocalSession session, EditSession editSession,
public void cut(Actor actor, LocalSession session, EditSession editSession,
@Selection Region region,
@Arg(desc = "Pattern to leave in place of the selection", def = "air")
Pattern leavePattern,
@@ -108,7 +109,7 @@ public void cut(Player player, LocalSession session, EditSession editSession,
Mask mask) throws WorldEditException {

BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
clipboard.setOrigin(session.getPlacementPosition(player));
clipboard.setOrigin(session.getPlacementPosition(actor));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
copy.setCopyingEntities(copyEntities);
@@ -122,7 +123,7 @@ public void cut(Player player, LocalSession session, EditSession editSession,

List<String> messages = Lists.newArrayList();
copy.addStatusMessages(messages);
messages.forEach(player::print);
messages.forEach(actor::print);
}

@Command(
@@ -131,7 +132,7 @@ public void cut(Player player, LocalSession session, EditSession editSession,
)
@CommandPermissions("worldedit.clipboard.paste")
@Logging(PLACEMENT)
public void paste(Player player, LocalSession session, EditSession editSession,
public void paste(Actor actor, World world, LocalSession session, EditSession editSession,
@Switch(name = 'a', desc = "Skip air blocks")
boolean ignoreAirBlocks,
@Switch(name = 'o', desc = "Paste at the original position")
@@ -149,7 +150,7 @@ public void paste(Player player, LocalSession session, EditSession editSession,
Clipboard clipboard = holder.getClipboard();
Region region = clipboard.getRegion();

BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player);
BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(actor);
Operation operation = holder
.createPaste(editSession)
.to(to)
@@ -164,16 +165,16 @@ public void paste(Player player, LocalSession session, EditSession editSession,
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
Vector3 realTo = 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(player.getWorld(), realTo.toBlockPoint(), max.toBlockPoint());
session.setRegionSelector(player.getWorld(), selector);
RegionSelector selector = new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
session.setRegionSelector(world, selector);
selector.learnChanges();
selector.explainRegionAdjust(player, session);
selector.explainRegionAdjust(actor, session);
}

player.print("The clipboard has been pasted at " + to);
actor.print("The clipboard has been pasted at " + to);
List<String> messages = Lists.newArrayList();
operation.addStatusMessages(messages);
messages.forEach(player::print);
messages.forEach(actor::print);
}

@Command(
@@ -184,7 +185,7 @@ public void paste(Player player, LocalSession session, EditSession editSession,
"Multiple rotations can be stacked. Interpolation is not performed so angles should be a multiple of 90 degrees.\n"
)
@CommandPermissions("worldedit.clipboard.rotate")
public void rotate(Player player, LocalSession session,
public void rotate(Actor actor, LocalSession session,
@Arg(desc = "Amount to rotate on the y-axis")
double yRotate,
@Arg(desc = "Amount to rotate on the x-axis", def = "0")
@@ -194,7 +195,7 @@ public void rotate(Player player, LocalSession session,
if (Math.abs(yRotate % 90) > 0.001 ||
Math.abs(xRotate % 90) > 0.001 ||
Math.abs(zRotate % 90) > 0.001) {
player.printDebug("Note: Interpolation is not yet supported, so angles that are multiples of 90 is recommended.");
actor.printDebug("Note: Interpolation is not yet supported, so angles that are multiples of 90 is recommended.");
}

ClipboardHolder holder = session.getClipboard();
@@ -203,31 +204,31 @@ public void rotate(Player player, LocalSession session,
transform = transform.rotateX(-xRotate);
transform = transform.rotateZ(-zRotate);
holder.setTransform(holder.getTransform().combine(transform));
player.print("The clipboard copy has been rotated.");
actor.print("The clipboard copy has been rotated.");
}

@Command(
name = "/flip",
desc = "Flip the contents of the clipboard across the origin"
)
@CommandPermissions("worldedit.clipboard.flip")
public void flip(Player player, LocalSession session,
public void flip(Actor actor, LocalSession session,
@Arg(desc = "The direction to flip, defaults to look direction.", def = Direction.AIM)
@Direction BlockVector3 direction) throws WorldEditException {
ClipboardHolder holder = session.getClipboard();
AffineTransform transform = new AffineTransform();
transform = transform.scale(direction.abs().multiply(-2).add(1, 1, 1).toVector3());
holder.setTransform(holder.getTransform().combine(transform));
player.print("The clipboard copy has been flipped.");
actor.print("The clipboard copy has been flipped.");
}

@Command(
name = "clearclipboard",
desc = "Clear your clipboard"
)
@CommandPermissions("worldedit.clipboard.clear")
public void clearClipboard(Player player, LocalSession session) throws WorldEditException {
public void clearClipboard(Actor actor, LocalSession session) throws WorldEditException {
session.setClipboard(null);
player.print("Clipboard cleared.");
actor.print("Clipboard cleared.");
}
}
@@ -26,6 +26,7 @@
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.MultiDirection;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
@@ -34,6 +35,7 @@
import com.sk89q.worldedit.regions.RegionOperationException;
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.Command;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.CommandManagerService;
@@ -120,15 +122,15 @@ private static void expandVert(LocalSession session, Player player) throws Incom
desc = "Expand the selection area"
)
@Logging(REGION)
public void expand(Player player, LocalSession session,
public void expand(Actor actor, World world, LocalSession session,
@Arg(desc = "Amount to expand the selection by, can be `vert` to expand to the whole vertical column")
int amount,
@Arg(desc = "Amount to expand the selection by in the other direction", def = "0")
int reverseAmount,
@Arg(desc = "Direction to expand", def = Direction.AIM)
@MultiDirection
List<BlockVector3> direction) throws WorldEditException {
Region region = session.getSelection(player.getWorld());
Region region = session.getSelection(world);
int oldSize = region.getArea();

if (reverseAmount == 0) {
@@ -141,12 +143,12 @@ public void expand(Player player, LocalSession session,
}
}

session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(world).learnChanges();
int newSize = region.getArea();

session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
session.getRegionSelector(world).explainRegionAdjust(actor, session);

player.print("Region expanded " + (newSize - oldSize) + " block(s).");
actor.print("Region expanded " + (newSize - oldSize) + " block(s).");
}

}

0 comments on commit 4ec513f

Please sign in to comment.
You can’t perform that action at this time.