Refactor confirmation

This commit is contained in:
Jesse Boyd
2019-11-21 06:50:37 +00:00
parent 444aa0dda7
commit 52a502a1c6
22 changed files with 782 additions and 575 deletions

View File

@ -30,7 +30,6 @@ import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.clipboard.MultiClipboardHolder;
import com.boydti.fawe.object.clipboard.ReadOnlyClipboard;
import com.boydti.fawe.object.clipboard.URIClipboardHolder;
import com.boydti.fawe.object.clipboard.WorldCutClipboard;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.util.ImgurUtility;
@ -44,10 +43,10 @@ import com.sk89q.worldedit.WorldEditException;
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.command.util.annotation.Confirm;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.PasteEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
@ -74,7 +73,6 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
@ -92,7 +90,6 @@ import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
@ -113,6 +110,7 @@ public class ClipboardCommands {
desc = "Copy the selection to the clipboard"
)
@CommandPermissions("worldedit.clipboard.copy")
@Confirm(Confirm.Processor.REGION)
public void copy(Actor actor, LocalSession session, EditSession editSession,
@Selection Region region,
@Switch(name = 'e', desc = "Skip copy entities")
@ -120,7 +118,7 @@ public class ClipboardCommands {
@Switch(name = 'b', desc = "Also copy biomes")
boolean copyBiomes,
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
Mask mask, InjectedValueAccess context) throws WorldEditException {
Mask mask) throws WorldEditException {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
@ -130,33 +128,31 @@ public class ClipboardCommands {
if (volume >= limit.MAX_CHECKS) {
throw FaweCache.MAX_CHECKS;
}
actor.checkConfirmationRegion(() -> {
session.setClipboard(null);
session.setClipboard(null);
Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
session.setClipboard(new ClipboardHolder(clipboard));
session.setClipboard(new ClipboardHolder(clipboard));
clipboard.setOrigin(session.getPlacementPosition(actor));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setCopyingEntities(!skipEntities);
copy.setCopyingBiomes(copyBiomes);
clipboard.setOrigin(session.getPlacementPosition(actor));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setCopyingEntities(!skipEntities);
copy.setCopyingBiomes(copyBiomes);
Mask sourceMask = editSession.getSourceMask();
if (sourceMask != null) {
new MaskTraverser(sourceMask).reset(editSession);
copy.setSourceMask(sourceMask);
editSession.setSourceMask(null);
}
if (mask != null && mask != Masks.alwaysTrue()) {
copy.setSourceMask(mask);
}
Operations.completeLegacy(copy);
BBC.COMMAND_COPY.send(actor, region.getArea());
if (!actor.hasPermission("fawe.tips")) {
BBC.TIP_PASTE.or(BBC.TIP_DOWNLOAD, BBC.TIP_ROTATE, BBC.TIP_COPYPASTE, BBC.TIP_REPLACE_MARKER, BBC.TIP_COPY_PATTERN).send(actor);
}
}, "/copy", region, context);
Mask sourceMask = editSession.getSourceMask();
if (sourceMask != null) {
new MaskTraverser(sourceMask).reset(editSession);
copy.setSourceMask(sourceMask);
editSession.setSourceMask(null);
}
if (mask != null && mask != Masks.alwaysTrue()) {
copy.setSourceMask(mask);
}
Operations.completeLegacy(copy);
BBC.COMMAND_COPY.send(actor, region.getArea());
if (!actor.hasPermission("fawe.tips")) {
BBC.TIP_PASTE.or(BBC.TIP_DOWNLOAD, BBC.TIP_ROTATE, BBC.TIP_COPYPASTE, BBC.TIP_REPLACE_MARKER, BBC.TIP_COPY_PATTERN).send(actor);
}
}
@Command(
@ -229,6 +225,7 @@ public class ClipboardCommands {
)
@CommandPermissions("worldedit.clipboard.cut")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void cut(Actor actor, LocalSession session, EditSession editSession,
@Selection Region region,
@Arg(desc = "Pattern to leave in place of the selection", def = "air")
@ -238,8 +235,7 @@ public class ClipboardCommands {
@Switch(name = 'b', desc = "Also copy biomes, source biomes are unaffected")
boolean copyBiomes,
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
Mask mask,
InjectedValueAccess context) throws WorldEditException {
Mask mask) throws WorldEditException {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
@ -251,35 +247,32 @@ public class ClipboardCommands {
if (volume >= limit.MAX_CHANGES) {
throw FaweCache.MAX_CHANGES;
}
actor.checkConfirmationRegion(() -> {
session.setClipboard(null);
session.setClipboard(null);
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
clipboard.setOrigin(session.getPlacementPosition(actor));
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
clipboard.setOrigin(session.getPlacementPosition(actor));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
copy.setCopyingEntities(!skipEntities);
copy.setRemovingEntities(true);
copy.setCopyingBiomes(copyBiomes);
Mask sourceMask = editSession.getSourceMask();
if (sourceMask != null) {
new MaskTraverser(sourceMask).reset(editSession);
copy.setSourceMask(sourceMask);
editSession.setSourceMask(null);
}
if (mask != null) {
copy.setSourceMask(mask);
}
Operations.completeLegacy(copy);
session.setClipboard(new ClipboardHolder(clipboard));
BBC.COMMAND_CUT_SLOW.send(actor, region.getArea());
if (!actor.hasPermission("fawe.tips")) {
BBC.TIP_LAZYCUT.send(actor);
}
}, "cut", region, context);
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
copy.setCopyingEntities(!skipEntities);
copy.setRemovingEntities(true);
copy.setCopyingBiomes(copyBiomes);
Mask sourceMask = editSession.getSourceMask();
if (sourceMask != null) {
new MaskTraverser(sourceMask).reset(editSession);
copy.setSourceMask(sourceMask);
editSession.setSourceMask(null);
}
if (mask != null) {
copy.setSourceMask(mask);
}
Operations.completeLegacy(copy);
session.setClipboard(new ClipboardHolder(clipboard));
BBC.COMMAND_CUT_SLOW.send(actor, region.getArea());
if (!actor.hasPermission("fawe.tips")) {
BBC.TIP_LAZYCUT.send(actor);
}
}
@Command(

View File

@ -37,6 +37,7 @@ import com.sk89q.worldedit.WorldEditException;
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.command.util.annotation.Confirm;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.generator.CavesGen;
@ -46,9 +47,7 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.internal.annotation.Radii;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
@ -95,6 +94,7 @@ public class GenerationCommands {
)
@CommandPermissions("worldedit.generation.caves")
@Logging(PLACEMENT)
@Confirm(Confirm.Processor.REGION)
public void caves(Actor actor, LocalSession session, EditSession editSession, @Selection Region region,
@Arg(name = "size", desc = "TODO", def = "8") int sizeOpt,
@Arg(name = "frequency", desc = "TODO", def = "40") int frequencyOpt,
@ -105,12 +105,10 @@ public class GenerationCommands {
@Arg(name = "individualRarity", desc = "TODO", def = "25") int individualRarityOpt,
@Arg(name = "pocketChance", desc = "TODO", def = "0") int pocketChanceOpt,
@Arg(name = "pocketMin", desc = "TODO", def = "0") int pocketMinOpt,
@Arg(name = "pocketMax", desc = "TODO", def = "3") int pocketMaxOpt, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
CavesGen gen = new CavesGen(sizeOpt, frequencyOpt, rarityOpt, minYOpt, maxYOpt, systemFrequencyOpt, individualRarityOpt, pocketChanceOpt, pocketMinOpt, pocketMaxOpt);
editSession.generate(region, gen);
BBC.VISITOR_BLOCK.send(actor, editSession.getBlockChangeCount());
}, "/caves", region, context);
@Arg(name = "pocketMax", desc = "TODO", def = "3") int pocketMaxOpt) throws WorldEditException {
CavesGen gen = new CavesGen(sizeOpt, frequencyOpt, rarityOpt, minYOpt, maxYOpt, systemFrequencyOpt, individualRarityOpt, pocketChanceOpt, pocketMinOpt, pocketMaxOpt);
editSession.generate(region, gen);
BBC.VISITOR_BLOCK.send(actor, editSession.getBlockChangeCount());
}
@ -120,11 +118,10 @@ public class GenerationCommands {
)
@CommandPermissions("worldedit.generation.ore")
@Logging(PLACEMENT)
public void ores(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "Mask") Mask mask, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
editSession.addOres(region, mask);
BBC.VISITOR_BLOCK.send(actor, editSession.getBlockChangeCount());
}, "/ores", region, context);
@Confirm(Confirm.Processor.REGION)
public void ores(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "Mask") Mask mask) throws WorldEditException {
editSession.addOres(region, mask);
BBC.VISITOR_BLOCK.send(actor, editSession.getBlockChangeCount());
}
@Command(
@ -174,11 +171,10 @@ public class GenerationCommands {
)
@CommandPermissions("worldedit.generation.ore")
@Logging(PLACEMENT)
public void ore(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "Mask") Mask mask, @Arg(desc = "Pattern") Pattern material, @Arg(desc="Ore vein size") @Range(from = 0, to=Integer.MAX_VALUE) int size, int freq, @Range(from=0, to=100) int rarity, @Range(from=0, to=255) int minY, @Range(from=0, to=255) int maxY, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
editSession.addOre(region, mask, material, size, freq, rarity, minY, maxY);
BBC.VISITOR_BLOCK.send(actor, editSession.getBlockChangeCount());
}, "/ore", region, context);
@Confirm(Confirm.Processor.REGION)
public void ore(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "Mask") Mask mask, @Arg(desc = "Pattern") Pattern material, @Arg(desc="Ore vein size") @Range(from = 0, to=Integer.MAX_VALUE) int size, int freq, @Range(from=0, to=100) int rarity, @Range(from=0, to=255) int minY, @Range(from=0, to=255) int maxY) throws WorldEditException {
editSession.addOre(region, mask, material, size, freq, rarity, minY, maxY);
BBC.VISITOR_BLOCK.send(actor, editSession.getBlockChangeCount());
}
@Command(
@ -187,14 +183,14 @@ public class GenerationCommands {
)
@CommandPermissions("worldedit.generation.cylinder")
@Logging(PLACEMENT)
public void hcyl(Actor actor, LocalSession session, EditSession editSession, InjectedValueAccess context,
public void hcyl(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The pattern of blocks to generate")
Pattern pattern,
@Arg(desc = "The radii of the cylinder. 1st is N/S, 2nd is E/W")
@Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The radii of the cylinder. 1st is N/S, 2nd is E/W")
BlockVector2 radii,
@Arg(desc = "The height of the cylinder", def = "1")
int height) throws WorldEditException {
cyl(actor, session, editSession, pattern, radii, height, true, context);
cyl(actor, session, editSession, pattern, radii, height, true);
}
@Command(
@ -206,18 +202,16 @@ public class GenerationCommands {
public void cyl(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The pattern of blocks to generate")
Pattern pattern,
@Arg(desc = "The radii of the cylinder. Order is N/S, E/W") BlockVector2 radius,
@Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The radii of the cylinder. Order is N/S, E/W") BlockVector2 radius,
@Arg(desc = "The height of the cylinder", def = "1")
int height,
@Switch(name = 'h', desc = "Make a hollow cylinder")
boolean hollow, InjectedValueAccess context) throws WorldEditException {
boolean hollow) throws WorldEditException {
double max = Math.max(radius.getBlockX(), radius.getBlockZ());
worldEdit.checkMaxRadius(max);
BlockVector3 pos = session.getPlacementPosition(actor);
actor.checkConfirmationRadius(() -> {
int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow);
BBC.VISITOR_BLOCK.send(actor, affected);
}, "/cyl", (int) max, context);
int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow);
BBC.VISITOR_BLOCK.send(actor, affected);
}
@Command(
@ -229,11 +223,10 @@ public class GenerationCommands {
public void hsphere(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The pattern of blocks to generate")
Pattern pattern,
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") BlockVector3 radii,
@Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") BlockVector3 radii,
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
boolean raised,
InjectedValueAccess context) throws WorldEditException {
sphere(actor, session, editSession, pattern, radii, raised, true, context);
boolean raised) throws WorldEditException {
sphere(actor, session, editSession, pattern, radii, raised, true);
}
@Command(
@ -245,23 +238,21 @@ public class GenerationCommands {
public void sphere(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The pattern of blocks to generate")
Pattern pattern,
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W")
@Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W")
BlockVector3 radii,
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
boolean raised,
@Switch(name = 'h', desc = "Make a hollow sphere")
boolean hollow, InjectedValueAccess context) throws WorldEditException {
boolean hollow) throws WorldEditException {
double max = MathMan.max(radii.getBlockX(), radii.getBlockY(), radii.getBlockZ());
worldEdit.checkMaxRadius(max);
BlockVector3 pos = session.getPlacementPosition(actor);
BlockVector3 finalPos = raised ? pos.add(0, radii.getY(), 0) : pos;
actor.checkConfirmationRadius(() -> {
int affected = editSession.makeSphere(finalPos, pattern, radii.getX(), radii.getY(), radii.getZ(), !hollow);
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
BBC.VISITOR_BLOCK.send(actor, affected);
}, "sphere", (int) max, context);
int affected = editSession.makeSphere(finalPos, pattern, radii.getX(), radii.getY(), radii.getZ(), !hollow);
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
BBC.VISITOR_BLOCK.send(actor, affected);
}
@Command(
@ -312,9 +303,9 @@ public class GenerationCommands {
public void hollowPyramid(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern,
@Arg(desc = "The size of the pyramid")
int size, InjectedValueAccess context) throws WorldEditException {
pyramid(actor, session, editSession, pattern, size, true, context);
@Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The size of the pyramid")
int size) throws WorldEditException {
pyramid(actor, session, editSession, pattern, size, true);
}
@Command(
@ -326,20 +317,17 @@ public class GenerationCommands {
public void pyramid(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern,
@Arg(desc = "The size of the pyramid")
@Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The size of the pyramid")
int size,
@Switch(name = 'h', desc = "Make a hollow pyramid")
boolean hollow,
InjectedValueAccess context) throws WorldEditException {
boolean hollow) throws WorldEditException {
BlockVector3 pos = session.getPlacementPosition(actor);
worldEdit.checkMaxRadius(size);
actor.checkConfirmationRadius(() -> {
int affected = editSession.makePyramid(pos, pattern, size, !hollow);
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
BBC.VISITOR_BLOCK.send(actor, affected);
}, getArguments(context), size, context);
int affected = editSession.makePyramid(pos, pattern, size, !hollow);
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
BBC.VISITOR_BLOCK.send(actor, affected);
}
@Command(
@ -350,6 +338,7 @@ public class GenerationCommands {
)
@CommandPermissions("worldedit.generation.shape")
@Logging(ALL)
@Confirm(Confirm.Processor.REGION)
public void generate(Actor actor, LocalSession session, EditSession editSession,
@Selection Region region,
@Arg(desc = "The pattern of blocks to set")
@ -363,8 +352,7 @@ public class GenerationCommands {
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
boolean offset,
@Switch(name = 'c', desc = "Use the selection's center as origin")
boolean offsetCenter,
InjectedValueAccess context) throws WorldEditException {
boolean offsetCenter) throws WorldEditException {
final Vector3 zero;
Vector3 unit;
@ -395,17 +383,15 @@ public class GenerationCommands {
final Vector3 unit1 = unit;
actor.checkConfirmationRegion(() -> {
try {
final int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout());
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
BBC.VISITOR_BLOCK.send(actor, affected);
} catch (ExpressionException e) {
actor.printError(e.getMessage());
try {
final int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout());
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
}, "/generate", region, context);
BBC.VISITOR_BLOCK.send(actor, affected);
} catch (ExpressionException e) {
actor.printError(e.getMessage());
}
}
@Command(
@ -418,6 +404,7 @@ public class GenerationCommands {
)
@CommandPermissions("worldedit.generation.shape.biome")
@Logging(ALL)
@Confirm(Confirm.Processor.REGION)
public void generateBiome(Actor actor, LocalSession session, EditSession editSession,
@Selection Region region,
@Arg(desc = "The biome type to set")
@ -431,8 +418,7 @@ public class GenerationCommands {
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
boolean offset,
@Switch(name = 'c', desc = "Use the selection's center as origin")
boolean offsetCenter,
InjectedValueAccess context) throws WorldEditException {
boolean offsetCenter) throws WorldEditException {
final Vector3 zero;
Vector3 unit;
@ -461,14 +447,12 @@ public class GenerationCommands {
}
final Vector3 unit1 = unit;
actor.checkConfirmationRegion(() -> {
try {
final int affected = editSession.makeBiomeShape(region, zero, unit1, target, String.join(" ", expression), hollow, session.getTimeout());
BBC.VISITOR_FLAT.send(actor, affected);
} catch (ExpressionException e) {
actor.printError(e.getMessage());
}
}, "/generatebiome", region, context);
try {
final int affected = editSession.makeBiomeShape(region, zero, unit1, target, String.join(" ", expression), hollow, session.getTimeout());
BBC.VISITOR_FLAT.send(actor, affected);
} catch (ExpressionException e) {
actor.printError(e.getMessage());
}
}
}

View File

@ -38,6 +38,7 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.annotation.Confirm;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.math.BlockVector3;
@ -225,11 +226,10 @@ public class HistoryCommands {
)
@CommandPermissions({"worldedit.history.undo", "worldedit.history.undo.self"})
public void undo(Player player, LocalSession session,
@Arg(desc = "Number of undoes to perform", def = "1")
@Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of undoes to perform", def = "1")
int times,
@Arg(name = "player", desc = "Undo this player's operations", def = "")
String playerName,
InjectedValueAccess context) throws WorldEditException {
String playerName) throws WorldEditException {
times = Math.max(1, times);
LocalSession undoSession;
if (session.hasFastMode()) {
@ -247,22 +247,20 @@ public class HistoryCommands {
undoSession = session;
}
int finalTimes = times;
player.checkConfirmation(() -> {
EditSession undone = null;
int i = 0;
for (; i < finalTimes; ++i) {
undone = undoSession.undo(undoSession.getBlockBag(player), player);
if (undone == null) break;
worldEdit.flushBlockBag(player, undone);
}
if (undone == null) i--;
if (i > 0) {
BBC.COMMAND_UNDO_SUCCESS.send(player, i == 1 ? "" : " x" + i);
}
if (undone == null) {
player.printError(BBC.COMMAND_UNDO_ERROR.s());
}
}, "undo", times, 50, context);
EditSession undone = null;
int i = 0;
for (; i < finalTimes; ++i) {
undone = undoSession.undo(undoSession.getBlockBag(player), player);
if (undone == null) break;
worldEdit.flushBlockBag(player, undone);
}
if (undone == null) i--;
if (i > 0) {
BBC.COMMAND_UNDO_SUCCESS.send(player, i == 1 ? "" : " x" + i);
}
if (undone == null) {
player.printError(BBC.COMMAND_UNDO_ERROR.s());
}
}
@Command(
@ -272,7 +270,7 @@ public class HistoryCommands {
)
@CommandPermissions({"worldedit.history.redo", "worldedit.history.redo.self"})
public void redo(Player player, LocalSession session,
@Arg(desc = "Number of redoes to perform", def = "1")
@Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of redoes to perform", def = "1")
int times,
@Arg(name = "player", desc = "Redo this player's operations", def = "")
String playerName) throws WorldEditException {

View File

@ -19,39 +19,29 @@
package com.sk89q.worldedit.command;
import com.google.common.base.Joiner;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.implementation.processors.ChunkSendProcessor;
import com.boydti.fawe.beta.implementation.processors.NullProcessor;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweLimit;
import com.google.common.collect.Lists;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.block.BlockReplace;
import com.sk89q.worldedit.command.util.annotation.Confirm;
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.FlatRegionFunction;
import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.biome.BiomeReplace;
import com.sk89q.worldedit.function.generator.FloraGenerator;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.NoiseFilter2D;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.visitor.FlatRegionVisitor;
import com.sk89q.worldedit.function.visitor.LayerVisitor;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.Selection;
@ -85,13 +75,13 @@ import org.enginehub.piston.inject.InjectedValueAccess;
import org.jetbrains.annotations.Range;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
import static com.sk89q.worldedit.command.MethodCommands.getArguments;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ORIENTATION_REGION;
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
import static com.sk89q.worldedit.command.util.annotation.Confirm.Processor.ALWAYS;
import static com.sk89q.worldedit.command.util.annotation.Confirm.Processor.RADIUS;
import static com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument;
import static com.sk89q.worldedit.regions.Regions.asFlatRegion;
import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
@ -116,19 +106,17 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.set")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public int set(Actor actor, EditSession editSession,
@Selection Region region,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern,
InjectedValueAccess context) {
actor.checkConfirmationRegion(() -> {
int affected = editSession.setBlocks(region, pattern);
if (affected != 0) {
BBC.OPERATION.send(actor, affected);
if (!actor.hasPermission("fawe.tips"))
BBC.TIP_FAST.or(BBC.TIP_CANCEL, BBC.TIP_MASK, BBC.TIP_MASK_ANGLE, BBC.TIP_SET_LINEAR, BBC.TIP_SURFACE_SPREAD, BBC.TIP_SET_HAND).send(actor);
}
}, getArguments(context), region, context);
Pattern pattern) {
int affected = editSession.setBlocks(region, pattern);
if (affected != 0) {
BBC.OPERATION.send(actor, affected);
if (!actor.hasPermission("fawe.tips"))
BBC.TIP_FAST.or(BBC.TIP_CANCEL, BBC.TIP_MASK, BBC.TIP_MASK_ANGLE, BBC.TIP_SET_LINEAR, BBC.TIP_SURFACE_SPREAD, BBC.TIP_SET_HAND).send(actor);
}
return 0;
}
@ -139,10 +127,8 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.set")
@Logging(REGION)
public void air(Actor actor, EditSession editSession,
@Selection Region region,
InjectedValueAccess context) throws WorldEditException {
set(actor, editSession, region, BlockTypes.AIR, context);
public void air(Actor actor, EditSession editSession, @Selection Region region) throws WorldEditException {
set(actor, editSession, region, BlockTypes.AIR);
}
@Command(
@ -151,12 +137,13 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.test")
@Logging(REGION)
public void test(Player player, EditSession editSession, @Selection Region region, @Arg(desc = "hello there") BiomeType biome) throws WorldEditException {
editSession.addProcessor(new ChunkSendProcessor(editSession.getWorld(), () -> Collections.singleton(player)));
editSession.addProcessor(NullProcessor.INSTANCE);
FlatRegionFunction replace = new BiomeReplace(editSession, biome);
FlatRegionVisitor visitor = new FlatRegionVisitor(Regions.asFlatRegion(region), replace);
Operations.completeLegacy(visitor);
public void test(Player player, EditSession editSession, @Arg(desc = "test") @Confirm(RADIUS) BlockVector3 radius) throws WorldEditException {
player.print("Run test " + radius);
// editSession.addProcessor(new ChunkSendProcessor(editSession.getWorld(), () -> Collections.singleton(player)));
// editSession.addProcessor(NullProcessor.INSTANCE);
// FlatRegionFunction replace = new BiomeReplace(editSession, biome);
// FlatRegionVisitor visitor = new FlatRegionVisitor(Regions.asFlatRegion(region), replace);
// Operations.completeLegacy(visitor);
}
@Command(
@ -279,6 +266,7 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.curve")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void curve(Actor actor, EditSession editSession,
@Selection Region region,
@Arg(desc = "The pattern of blocks to place")
@ -286,21 +274,19 @@ public class RegionCommands {
@Arg(desc = "The thickness of the curve", def = "0")
int thickness,
@Switch(name = 'h', desc = "Generate only a shell")
boolean shell, InjectedValueAccess context) throws WorldEditException {
boolean shell) throws WorldEditException {
if (!(region instanceof ConvexPolyhedralRegion)) {
actor.printError("//curve only works with convex polyhedral selections");
return;
}
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
actor.checkConfirmationRegion(() -> {
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
List<BlockVector3> vectors = new ArrayList<>(cpregion.getVertices());
int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell);
actor.print(blocksChanged + " block(s) have been changed.");
}, getArguments(context), region, context);
}
@Command(
@ -310,19 +296,18 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.replace")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void replace(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The mask representing blocks to replace", def = "")
Mask from,
@Arg(desc = "The pattern of blocks to replace with")
Pattern to, InjectedValueAccess context) throws WorldEditException {
Pattern to) throws WorldEditException {
if (from == null) {
from = new ExistingBlockMask(editSession);
}
Mask finalFrom = from;
actor.checkConfirmationRegion(() -> {
int affected = editSession.replaceBlocks(region, finalFrom, to);
actor.print(affected + " block(s) have been replaced.");
}, getArguments(context), region, context);
}
@Command(
@ -331,13 +316,12 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.overlay")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void overlay(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to overlay")
Pattern pattern, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
Pattern pattern) throws WorldEditException {
int affected = editSession.overlayCuboidBlocks(region, pattern);
actor.print(affected + " block(s) have been overlaid.");
}, getArguments(context), region, context);
}
@Command(
@ -346,24 +330,23 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.overlay")
@Logging(REGION)
public void lay(Player player, EditSession editSession, @Selection Region region, @Arg(name = "pattern", desc = "The pattern of blocks to lay") Pattern patternArg, InjectedValueAccess context) throws WorldEditException {
player.checkConfirmationRegion(() -> {
BlockVector3 max = region.getMaximumPoint();
int maxY = max.getBlockY();
Iterable<BlockVector2> flat = Regions.asFlatRegion(region).asFlatRegion();
Iterator<BlockVector2> iter = flat.iterator();
int y = 0;
int affected = 0;
while (iter.hasNext()) {
BlockVector2 pos = iter.next();
int x = pos.getBlockX();
int z = pos.getBlockZ();
y = editSession.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
editSession.setBlock(x, y, z, patternArg);
affected++;
}
BBC.VISITOR_BLOCK.send(player, affected);
}, getArguments(context), region, context);
@Confirm(Confirm.Processor.REGION)
public void lay(Player player, EditSession editSession, @Selection Region region, @Arg(name = "pattern", desc = "The pattern of blocks to lay") Pattern patternArg) throws WorldEditException {
BlockVector3 max = region.getMaximumPoint();
int maxY = max.getBlockY();
Iterable<BlockVector2> flat = Regions.asFlatRegion(region).asFlatRegion();
Iterator<BlockVector2> iter = flat.iterator();
int y = 0;
int affected = 0;
while (iter.hasNext()) {
BlockVector2 pos = iter.next();
int x = pos.getBlockX();
int z = pos.getBlockZ();
y = editSession.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
editSession.setBlock(x, y, z, patternArg);
affected++;
}
BBC.VISITOR_BLOCK.send(player, affected);
}
@Command(
@ -387,11 +370,10 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.naturalize")
@Logging(REGION)
public void naturalize(Actor actor, EditSession editSession, @Selection Region region, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
int affected = editSession.naturalizeCuboidBlocks(region);
actor.print(affected + " block(s) have been made to look more natural.");
}, getArguments(context), region, context);
@Confirm(Confirm.Processor.REGION)
public void naturalize(Actor actor, EditSession editSession, @Selection Region region) throws WorldEditException {
int affected = editSession.naturalizeCuboidBlocks(region);
actor.print(affected + " block(s) have been made to look more natural.");
}
@Command(
@ -400,13 +382,12 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.walls")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void walls(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
int affected = editSession.makeWalls(region, pattern);
actor.print(affected + " block(s) have been changed.");
}, getArguments(context), region, context);
Pattern pattern) throws WorldEditException {
int affected = editSession.makeWalls(region, pattern);
actor.print(affected + " block(s) have been changed.");
}
@Command(
@ -416,13 +397,12 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.faces")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void faces(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern, InjectedValueAccess context) throws WorldEditException {
actor.checkConfirmationRegion(() -> {
int affected = editSession.makeCuboidFaces(region, pattern);
actor.print(affected + " block(s) have been changed.");
}, getArguments(context), region, context);
Pattern pattern) throws WorldEditException {
int affected = editSession.makeCuboidFaces(region, pattern);
actor.print(affected + " block(s) have been changed.");
}
@Command(
@ -432,12 +412,13 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.smooth")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void smooth(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "# of iterations to perform", def = "1")
int iterations,
@Arg(desc = "The mask of blocks to use as the height map", def = "")
Mask mask,
@Switch(name = 's', desc = "TODO") boolean snow, InjectedValueAccess context) throws WorldEditException {
@Switch(name = 's', desc = "TODO") boolean snow) throws WorldEditException {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
@ -445,16 +426,14 @@ public class RegionCommands {
if (volume >= limit.MAX_CHECKS) {
throw FaweCache.MAX_CHECKS;
}
actor.checkConfirmationRegion(() -> {
try {
HeightMap heightMap = new HeightMap(editSession, region, mask, snow);
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
int affected = heightMap.applyFilter(filter, iterations);
actor.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
} catch (Throwable e) {
throw new RuntimeException(e);
}
}, getArguments(context), region, context);
try {
HeightMap heightMap = new HeightMap(editSession, region, mask, snow);
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
int affected = heightMap.applyFilter(filter, iterations);
actor.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
@Command(
@ -497,6 +476,7 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.move")
@Logging(ORIENTATION_REGION)
@Confirm(Confirm.Processor.REGION)
public void move(Actor actor, World world, EditSession editSession, LocalSession session,
@Selection Region region,
@Arg(desc = "# of blocks to move", def = "1")
@ -515,8 +495,7 @@ public class RegionCommands {
@Switch(name = 'b', desc = "Also copy biomes")
boolean copyBiomes,
@ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air", def = "")
Mask mask,
InjectedValueAccess context) throws WorldEditException {
Mask mask) throws WorldEditException {
checkCommandArgument(count >= 1, "Count must be >= 1");
Mask combinedMask;
@ -530,22 +509,20 @@ public class RegionCommands {
combinedMask = mask;
}
actor.checkConfirmationRegion(() -> {
int affected = editSession.moveRegion(region, direction, count, !skipEntities, copyBiomes, combinedMask, replace);
int affected = editSession.moveRegion(region, direction, count, !skipEntities, copyBiomes, combinedMask, replace);
if (moveSelection) {
try {
region.shift(direction.multiply(count));
if (moveSelection) {
try {
region.shift(direction.multiply(count));
session.getRegionSelector(world).learnChanges();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
} catch (RegionOperationException e) {
actor.printError(e.getMessage());
}
session.getRegionSelector(world).learnChanges();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
} catch (RegionOperationException e) {
actor.printError(e.getMessage());
}
}
BBC.VISITOR_BLOCK.send(actor, affected);
}, getArguments(context), region, context);
BBC.VISITOR_BLOCK.send(actor, affected);
}
@Command(
@ -556,15 +533,13 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.fall")
@Logging(ORIENTATION_REGION)
@Confirm(Confirm.Processor.REGION)
public void fall(Player player, EditSession editSession, LocalSession session,
@Selection Region region,
@Arg(desc = "BlockStateHolder", def = "air") BlockStateHolder replace,
@Switch(name = 'm', desc = "TODO") boolean notFullHeight,
InjectedValueAccess context) throws WorldEditException {
player.checkConfirmationRegion(() -> {
int affected = editSession.fall(region, !notFullHeight, replace);
BBC.VISITOR_BLOCK.send(player, affected);
}, getArguments(context), region, context);
@Switch(name = 'm', desc = "TODO") boolean notFullHeight) throws WorldEditException {
int affected = editSession.fall(region, !notFullHeight, replace);
BBC.VISITOR_BLOCK.send(player, affected);
}
@Command(
@ -576,7 +551,7 @@ public class RegionCommands {
public void stack(Actor actor, World world, EditSession editSession, LocalSession session,
@Selection Region region,
@Arg(desc = "# of copies to stack", def = "1")
int count,
@Confirm(Confirm.Processor.REGION) int count,
@Arg(desc = "The direction to stack", def = Direction.AIM)
@Direction(includeDiagonals = true)
BlockVector3 direction,
@ -589,8 +564,7 @@ public class RegionCommands {
@Switch(name = 'b', desc = "Also copy biomes")
boolean copyBiomes,
@ArgFlag(name = 'm', desc = "Source mask", def="")
Mask mask,
InjectedValueAccess context) throws WorldEditException {
Mask mask) throws WorldEditException {
Mask combinedMask;
if (ignoreAirBlocks) {
@ -603,25 +577,23 @@ public class RegionCommands {
combinedMask = mask;
}
actor.checkConfirmationStack(() -> {
int affected = editSession.stackCuboidRegion(region, direction, count, !skipEntities, copyBiomes, combinedMask);
int affected = editSession.stackCuboidRegion(region, direction, count, !skipEntities, copyBiomes, combinedMask);
if (moveSelection) {
try {
final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
if (moveSelection) {
try {
final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
final BlockVector3 shiftVector = direction.multiply(size).multiply(count);
region.shift(shiftVector);
final BlockVector3 shiftVector = direction.multiply(size).multiply(count);
region.shift(shiftVector);
session.getRegionSelector(world).learnChanges();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
} catch (RegionOperationException e) {
actor.printError(e.getMessage());
}
session.getRegionSelector(world).learnChanges();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
} catch (RegionOperationException e) {
actor.printError(e.getMessage());
}
}
BBC.VISITOR_BLOCK.send(actor, affected);
}, getArguments(context), region, count, context);
BBC.VISITOR_BLOCK.send(actor, affected);
}
@Command(
@ -633,7 +605,8 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.deform")
@Logging(ALL)
public void deform(Actor actor, LocalSession session, EditSession editSession, InjectedValueAccess context,
@Confirm(Confirm.Processor.REGION)
public void deform(Actor actor, LocalSession session, EditSession editSession,
@Selection Region region,
@Arg(desc = "The expression to use", variable = true)
List<String> expression,
@ -663,17 +636,15 @@ public class RegionCommands {
}
final Vector3 unit1 = unit;
actor.checkConfirmationRegion(() -> {
try {
final int affected = editSession.deformRegion(region, zero, unit1, String.join(" ", expression), session.getTimeout());
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
actor.print(affected + " block(s) have been deformed.");
} catch (ExpressionException e) {
actor.printError(e.getMessage());
try {
final int affected = editSession.deformRegion(region, zero, unit1, String.join(" ", expression), session.getTimeout());
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
}, getArguments(context), region, context);
actor.print(affected + " block(s) have been deformed.");
} catch (ExpressionException e) {
actor.printError(e.getMessage());
}
}
@Command(
@ -686,31 +657,27 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.regen")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void regenerateChunk(Player player, LocalSession session, EditSession editSession, @Selection Region region,
@Arg(def = "", desc = "Regenerate with biome") BiomeType biome,
@Arg(def = "", desc = "Regenerate with seed") Long seed,
InjectedValueAccess context) throws WorldEditException {
player.checkConfirmationRegion(() -> {
Mask mask = session.getMask();
session.setMask((Mask) null);
session.setSourceMask((Mask) null);
editSession.regenerate(region, biome, seed);
session.setMask(mask);
session.setSourceMask(mask);
if (!player.hasPermission("fawe.tips")) {
player.print(BBC.COMMAND_REGEN_2.s());
} else if (biome == null) {
BBC.COMMAND_REGEN_0.send(player);
if (!player.hasPermission("fawe.tips")) player.print(BBC.TIP_REGEN_0.s());
} else if (seed == null) {
player.print(BBC.COMMAND_REGEN_1.s());
if (!player.hasPermission("fawe.tips")) BBC.TIP_REGEN_1.send(player);
} else {
player.print(BBC.COMMAND_REGEN_2.s());
}
}, getArguments(context), region, context);
@Arg(def = "", desc = "Regenerate with seed") Long seed) throws WorldEditException {
Mask mask = session.getMask();
session.setMask((Mask) null);
session.setSourceMask((Mask) null);
editSession.regenerate(region, biome, seed);
session.setMask(mask);
session.setSourceMask(mask);
if (!player.hasPermission("fawe.tips")) {
player.print(BBC.COMMAND_REGEN_2.s());
} else if (biome == null) {
BBC.COMMAND_REGEN_0.send(player);
if (!player.hasPermission("fawe.tips")) player.print(BBC.TIP_REGEN_0.s());
} else if (seed == null) {
player.print(BBC.COMMAND_REGEN_1.s());
if (!player.hasPermission("fawe.tips")) BBC.TIP_REGEN_1.send(player);
} else {
player.print(BBC.COMMAND_REGEN_2.s());
}
}
@Command(
@ -723,20 +690,18 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.hollow")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void hollow(Actor actor, EditSession editSession,
@Selection Region region,
@Range(from=0, to=Integer.MAX_VALUE) @Arg(desc = "Thickness of the shell to leave", def = "0")
int thickness,
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
Pattern pattern,
@ArgFlag(name = 'm', desc = "Mask to hollow with") Mask mask,
InjectedValueAccess context) throws WorldEditException {
@ArgFlag(name = 'm', desc = "Mask to hollow with") Mask mask) throws WorldEditException {
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask;
actor.checkConfirmationRegion(() -> {
int affected = editSession.hollowOutRegion(region, thickness, pattern, finalMask);
actor.print(affected + " block(s) have been changed.");
}, getArguments(context), region, context);
int affected = editSession.hollowOutRegion(region, thickness, pattern, finalMask);
actor.print(affected + " block(s) have been changed.");
}
@Command(
@ -745,6 +710,7 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.forest")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public int forest(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The type of tree to place", def = "tree")
TreeType type,
@ -762,20 +728,19 @@ public class RegionCommands {
)
@CommandPermissions("worldedit.region.flora")
@Logging(REGION)
@Confirm(Confirm.Processor.REGION)
public void flora(Actor actor, EditSession editSession, @Selection Region region,
@Arg(desc = "The density of the forest", def = "5")
double density, InjectedValueAccess context) throws WorldEditException {
double density) throws WorldEditException {
checkCommandArgument(0 <= density && density <= 100, "Density must be in [0, 100]");
actor.checkConfirmationRegion(() -> {
FloraGenerator generator = new FloraGenerator(editSession);
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density / 100));
Operations.completeLegacy(visitor);
FloraGenerator generator = new FloraGenerator(editSession);
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density / 100));
Operations.completeLegacy(visitor);
int affected = ground.getAffected();
actor.print(affected + " flora created.");
}, "/flora", region, context);
int affected = ground.getAffected();
actor.print(affected + " flora created.");
}
}

View File

@ -39,11 +39,12 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator;
import com.sk89q.worldedit.command.util.CreatureButcher;
import com.sk89q.worldedit.command.util.EntityRemover;
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.command.util.PrintCommandHelp;
import com.sk89q.worldedit.command.util.SkipQueue;
import com.sk89q.worldedit.command.util.annotation.SkipQueue;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
@ -102,7 +103,7 @@ import org.jetbrains.annotations.Range;
/**
* Utility commands.
*/
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
@CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class, CommandQueuedConditionGenerator.Registration.class})
public class UtilityCommands {
private final WorldEdit we;
@ -700,6 +701,7 @@ public class UtilityCommands {
name = "/confirm",
desc = "Confirm a command"
)
@SkipQueue
@CommandPermissions("fawe.confirm")
public void confirm(Player fp) throws WorldEditException {
if (!fp.confirm()) {

View File

@ -29,7 +29,7 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.SkipQueue;
import com.sk89q.worldedit.command.util.annotation.SkipQueue;
import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator;
import com.sk89q.worldedit.command.util.PrintCommandHelp;
import com.sk89q.worldedit.entity.Player;

View File

@ -1,5 +1,6 @@
package com.sk89q.worldedit.command.util;
import com.sk89q.worldedit.command.util.annotation.SkipQueue;
import org.enginehub.piston.Command;
import org.enginehub.piston.gen.CommandConditionGenerator;
import org.enginehub.piston.util.NonnullByDefault;

View File

@ -0,0 +1,136 @@
package com.sk89q.worldedit.command.util.annotation;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.util.task.InterruptableCondition;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.event.Event;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.command.CommandArgParser;
import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.exception.StopExecutionException;
import org.enginehub.piston.inject.InjectAnnotation;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Stream;
/**
* Indicates how the affected blocks should be hinted at in the log.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD})
@InjectAnnotation
public @interface Confirm {
Processor value() default Processor.ALWAYS;
enum Processor {
REGION {
@Override
public boolean passes(Actor actor, InjectedValueAccess context, double value) {
Region region = context.injectedValue(Key.of(Region.class, Selection.class)).orElseThrow(IncompleteRegionException::new);
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
long area = (max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1) * (int) value;
if (area > 2 << 18) {
BBC.WORLDEDIT_CANCEL_REASON_CONFIRM_REGION.send(actor, min, max, getArgs(context));
return confirm(actor, context);
}
return true;
}
},
RADIUS {
@Override
public boolean passes(Actor actor, InjectedValueAccess context, double value) {
int max = WorldEdit.getInstance().getConfiguration().maxRadius;
if (value > max) {
BBC.WORLDEDIT_CANCEL_REASON_CONFIRM_REGION.send(actor, value, max, getArgs(context));
return Processor.confirm(actor, context);
}
return true;
}
},
LIMIT {
@Override
public boolean passes(Actor actor, InjectedValueAccess context, double value) {
int max = 50;// TODO configurable, get Key.of(Method.class) @Limit
if (value > max) {
BBC.WORLDEDIT_CANCEL_REASON_CONFIRM_REGION.send(actor, value, max, getArgs(context));
return Processor.confirm(actor, context);
}
return true;
}
},
ALWAYS {
@Override
public boolean passes(Actor actor, InjectedValueAccess context, double value) {
BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.send(actor);
return confirm(actor, context);
}
}
;
public boolean passes(Actor actor, InjectedValueAccess context, double value){return true;}
public <T extends Number> T check(Actor actor, InjectedValueAccess context, T value) {
if (!passes(actor, context, value.doubleValue())) {
throw new StopExecutionException(TextComponent.empty());
}
return value;
}
private static String getArgs(InjectedValueAccess context) {
return context.injectedValue(Key.of(Arguments.class)).map(Arguments::get).get();
}
private static String getArg(InjectedValueAccess context, String def) {
Stream<Substring> split = CommandArgParser.forArgString(getArgs(context)).parseArgs();
Substring first = split.findFirst().orElse(null);
if (first == null && def == null) {
throw new StopExecutionException(TextComponent.of("No arguments"));
}
return first != null ? first.getSubstring() : def;
}
private static int getInt(InjectedValueAccess context, String def) {
return Integer.parseInt(getArg(context, def));
}
private static boolean confirm(Actor actor, InjectedValueAccess context) {
Event event = context.injectedValue(Key.of(Event.class)).orElse(null);
if (!(event instanceof CommandEvent)) {
return true;
}
ReentrantLock lock = new ReentrantLock();
Condition condition = lock.newCondition();
InterruptableCondition wait = new InterruptableCondition(lock, condition, Thread.currentThread());
try {
lock.lock();
actor.setMeta("cmdConfirm", wait);
if (condition.await(15, TimeUnit.SECONDS)) {
return true;
}
} catch (InterruptedException e) {}
finally {
if (actor.getMeta("cmdConfirm") == wait) {
actor.deleteMeta("cmdConfirm");
}
}
return false;
}
}
}

View File

@ -1,5 +1,6 @@
package com.sk89q.worldedit.command.util;
package com.sk89q.worldedit.command.util.annotation;
import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator;
import org.enginehub.piston.annotation.CommandCondition;
import java.lang.annotation.Retention;