From f5c202af6dc1479458032b19ff9719ec6da79a03 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 21 Jul 2019 21:39:36 +1000 Subject: [PATCH] BrushCommands --- .../beta/implementation/QueueHandler.java | 7 - .../boydti/fawe/object/brush/LayerBrush.java | 5 +- .../com/sk89q/worldedit/LocalSession.java | 31 +- .../worldedit/command/BrushCommands.java | 1190 +++-------------- .../worldedit/command/GeneralCommands.java | 16 +- .../worldedit/command/HistoryCommands.java | 16 +- ...SchemListFilters.java => ListFilters.java} | 49 +- .../worldedit/command/MethodCommands.java | 58 +- .../worldedit/command/RegionCommands.java | 104 +- .../worldedit/command/UtilityCommands.java | 7 +- .../platform}/Annotations.java | 0 .../platform/PlatformCommandManager.java | 68 +- 12 files changed, 332 insertions(+), 1219 deletions(-) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/{SchemListFilters.java => ListFilters.java} (72%) rename worldedit-core/src/main/java/com/sk89q/worldedit/{util/formatting/component => extension/platform}/Annotations.java (100%) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java index e3f14bc10..0311666d8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java @@ -2,27 +2,20 @@ package com.boydti.fawe.beta.implementation; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; -import com.boydti.fawe.beta.ChunkFilterBlock; -import com.boydti.fawe.beta.Filter; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.Trimable; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.collection.IterableThreadLocal; import com.boydti.fawe.util.MemUtil; -import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.wrappers.WorldWrapper; -import com.sk89q.worldedit.math.BlockVector2; -import com.sk89q.worldedit.math.MutableBlockVector3; -import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.World; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutionException; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java index 0eb12f6d1..488e8ad9e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java @@ -18,6 +18,7 @@ import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -25,11 +26,11 @@ import java.util.Arrays; public class LayerBrush implements Brush { - private final BlockStateHolder[] layers; + private final BlockState[] layers; private RecursiveVisitor visitor; private MutableBlockVector3 mutable = new MutableBlockVector3(); - public LayerBrush(BlockStateHolder[] layers) { + public LayerBrush(BlockState[] layers) { this.layers = layers; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 4f28e1483..f351b686c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -1373,23 +1373,24 @@ public class LocalSession implements TextureHolder { this.fastMode = fastMode; } -// /** -// * Gets the reorder mode of the session. -// * -// * @return The reorder mode -// */ -// public EditSession.ReorderMode getReorderMode() { + /** + * Gets the reorder mode of the session. + * + * @return The reorder mode + */ + public EditSession.ReorderMode getReorderMode() { // return reorderMode; -// } -// -// /** -// * Sets the reorder mode of the session. -// * -// * @param reorderMode The reorder mode -// */ -// public void setReorderMode(EditSession.ReorderMode reorderMode) { + return EditSession.ReorderMode.FAST; + } + + /** + * Sets the reorder mode of the session. + * + * @param reorderMode The reorder mode + */ + public void setReorderMode(EditSession.ReorderMode reorderMode) { // this.reorderMode = reorderMode; -// } + } /** * Get the mask. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index eb5f717fd..494eb131d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.command; -import static com.google.common.base.Preconditions.checkNotNull; - import com.boydti.fawe.Fawe; import com.boydti.fawe.command.FawePrimitiveBinding; import com.boydti.fawe.config.BBC; @@ -57,19 +55,18 @@ import com.boydti.fawe.object.brush.heightmap.ScalableHeightMap; import com.boydti.fawe.object.brush.sweep.SweepBrush; import com.boydti.fawe.object.clipboard.MultiClipboardHolder; import com.boydti.fawe.object.mask.IdMask; -import com.boydti.fawe.util.ColorUtil; import com.boydti.fawe.util.MathMan; +import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.image.ImageUtil; -import org.enginehub.piston.inject.InjectedValueAccess; import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.minecraft.util.commands.Step; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EmptyClipboardException; -import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.BrushTool; +import com.sk89q.worldedit.command.tool.InvalidToolBindException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.command.tool.brush.ButcherBrush; import com.sk89q.worldedit.command.tool.brush.ClipboardBrush; @@ -83,7 +80,6 @@ import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CreatureButcher; import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; @@ -91,21 +87,24 @@ import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.SingleBlockTypeMask; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.internal.annotation.Range; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.util.HandSide; -import com.sk89q.worldedit.util.command.CallableProcessor; -import com.sk89q.worldedit.util.command.CommandCallable; -import com.sk89q.worldedit.util.command.InvalidUsageException; -import com.sk89q.worldedit.util.command.parametric.AParametricCallable; -import com.sk89q.worldedit.util.command.parametric.Optional; -import com.sk89q.worldedit.util.command.parametric.ParameterException; +import com.sk89q.worldedit.world.block.BlockID; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import java.awt.Color; +import org.enginehub.piston.annotation.Command; +import org.enginehub.piston.annotation.CommandContainer; +import org.enginehub.piston.annotation.param.Arg; +import org.enginehub.piston.annotation.param.ArgFlag; +import org.enginehub.piston.annotation.param.Switch; +import org.enginehub.piston.inject.InjectedValueAccess; +import org.enginehub.piston.inject.Key; + import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; @@ -113,19 +112,16 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.ArrayList; import java.util.List; -import org.enginehub.piston.annotation.Command; -import org.enginehub.piston.annotation.CommandContainer; -import org.enginehub.piston.annotation.param.Arg; -import org.enginehub.piston.annotation.param.ArgFlag; -import org.enginehub.piston.annotation.param.Switch; +import java.util.Optional; + +import static com.google.common.base.Preconditions.checkNotNull; /** * Commands to set brush shape. */ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) -public class BrushCommands { +public class BrushCommands extends MethodCommands { private final WorldEdit worldEdit; @@ -149,37 +145,9 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.blendball") public BrushSettings blendBallBrush(Player player, LocalSession session, @Arg(desc = "The radius to sample for blending", def = "5") - double radius, InjectedValueAccess context) throws WorldEditException { + Expression radius, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new BlendBall(); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, new BlendBall()).setSize(radius); } @Command( @@ -189,37 +157,9 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.erode") public BrushSettings erodeBrush(Player player, LocalSession session, @Arg(desc = "The radius for eroding", def = "5") - double radius, InjectedValueAccess context) throws WorldEditException { + Expression radius, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new ErodeBrush(); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, new ErodeBrush()).setSize(radius); } @Command( @@ -229,37 +169,9 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.pull") public BrushSettings pullBrush(Player player, LocalSession session, @Arg(desc = "The radius to sample for blending", def = "5") - double radius, InjectedValueAccess context) throws WorldEditException { + Expression radius, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new RaiseBrush(); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, new RaiseBrush()).setSize(radius); } @Command( @@ -269,37 +181,9 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.sphere") public BrushSettings circleBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(desc = "The radius to sample for blending", def = "5") - double radius, InjectedValueAccess context) throws WorldEditException { + Expression radius, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new CircleBrush(player); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill); + return set(session, context, new CircleBrush(player)).setSize(radius).setFill(fill); } @Command( @@ -313,37 +197,13 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.recursive") public BrushSettings recursiveBrush(Player player, LocalSession session, EditSession editSession, Pattern fill, @Arg(desc = "The radius to sample for blending", def = "5") - double radius, @Switch(name='d', desc = "TODO") boolean depthFirst, InjectedValueAccess context) throws WorldEditException { + Expression radius, @Switch(name='d', desc = "TODO") boolean depthFirst, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new RecurseBrush(depthFirst); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill).setMask(new IdMask(editSession)); + return set(session, context, + new RecurseBrush(depthFirst)) + .setSize(radius) + .setFill(fill) + .setMask(new IdMask(editSession)); } @Command( @@ -356,39 +216,14 @@ public class BrushCommands { "The -f flag creates a flat line" ) @CommandPermissions("worldedit.brush.line") - public BrushSettings lineBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, + public BrushSettings lineBrush(Player player, LocalSession session, Pattern fill, @Arg(desc = "The radius to sample for blending", def = "0") - double radius, @Switch(name='h', desc = "TODO") boolean shell, @Switch(name='s', desc = "TODO") boolean select, @Switch(name='f', desc = "TODO") boolean flat, InjectedValueAccess context) throws WorldEditException { + Expression radius, @Switch(name='h', desc = "TODO") boolean shell, @Switch(name='s', desc = "TODO") boolean select, @Switch(name='f', desc = "TODO") boolean flat, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new LineBrush(shell, select, flat); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill); + return set(session, context, + new LineBrush(shell, select, flat)) + .setSize(radius) + .setFill(fill); } @Command( @@ -404,41 +239,15 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.spline") public BrushSettings splineBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(desc = "The radius to sample for blending", def = "25") - double radius, InjectedValueAccess context) throws WorldEditException { + Expression radius, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); player.print(BBC.BRUSH_SPLINE.f(radius)); - Brush brush = new SplineBrush(player, session); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill); + return set(session, context, + new SplineBrush(player, session)) + .setSize(radius) + .setFill(fill); } - // Adapted from: https://github.com/Rafessor/VaeronTools @Command( name = "sweep", aliases = {"sw", "vaesweep"}, @@ -448,37 +257,9 @@ public class BrushCommands { "Set [copies] to a value > 0 if you want to have your selection pasted a limited amount of times equally spaced on the curve" ) @CommandPermissions("worldedit.brush.sweep") - public BrushSettings sweepBrush(Player player, LocalSession session, EditSession editSession, @Arg(name = "copies", desc = "int", def = "-1") int copies, InjectedValueAccess context) throws WorldEditException { + public BrushSettings sweepBrush(Player player, LocalSession session, @Arg(name = "copies", desc = "int", def = "-1") int copies, InjectedValueAccess context) throws WorldEditException { player.print(BBC.BRUSH_SPLINE.s()); - Brush brush = new SweepBrush(copies); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush); + return set(session, context, new SweepBrush(copies)); } @Command( @@ -492,39 +273,15 @@ public class BrushCommands { "The -d flag sags the catenary toward the facing direction\n" ) @CommandPermissions("worldedit.brush.spline") - public BrushSettings catenaryBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("1.2") @Range(min=1) double lengthFactor, + public BrushSettings catenaryBrush(LocalSession session, Pattern fill, @Arg(def = "1.2", desc = "Length of wire compared to distance between points") @Range(min=1) double lengthFactor, @Arg(desc = "The radius to sample for blending", def = "0") - double radius, @Switch(name='h', desc = "TODO") boolean shell, @Switch(name='s', desc = "TODO") boolean select, @Switch(name='d', desc = "TODO") boolean facingDirection, InjectedValueAccess context) throws WorldEditException { + Expression radius, @Switch(name='h', desc = "TODO") boolean shell, @Switch(name='s', desc = "TODO") boolean select, @Switch(name='d', desc = "TODO") boolean facingDirection, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); Brush brush = new CatenaryBrush(shell, select, facingDirection, lengthFactor); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill); + return set(session, context, + new CatenaryBrush(shell, select, facingDirection, lengthFactor)) + .setSize(radius) + .setFill(fill); } @Command( @@ -535,40 +292,15 @@ public class BrushCommands { "Video: https://www.youtube.com/watch?v=zSN-2jJxXlM" ) @CommandPermissions("worldedit.brush.surfacespline") // 0, 0, 0, 10, 0, - public BrushSettings surfaceSpline(Player player, EditSession editSession, LocalSession session, Pattern fill, + public BrushSettings surfaceSpline(Player player, LocalSession session, Pattern fill, @Arg(desc = "The radius to sample for blending", def = "0") - double radius, @Arg(name = "tension", desc = "double", def = "0") double tension, @Arg(name = "bias", desc = "double", def = "0") double bias, @Arg(name = "continuity", desc = "double", def = "0") double continuity, @Arg(name = "quality", desc = "double", def = "10") double quality, InjectedValueAccess context) throws WorldEditException { + Expression radius, @Arg(name = "tension", desc = "double", def = "0") double tension, @Arg(name = "bias", desc = "double", def = "0") double bias, @Arg(name = "continuity", desc = "double", def = "0") double continuity, @Arg(name = "quality", desc = "double", def = "10") double quality, InjectedValueAccess context) throws WorldEditException { player.print(BBC.BRUSH_SPLINE.f(radius)); worldEdit.checkMaxBrushRadius(radius); - Brush brush = new SurfaceSpline(tension, bias, continuity, quality); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill); + return set(session, context, + new SurfaceSpline(tension, bias, continuity, quality)) + .setSize(radius) + .setFill(fill); } @Command( @@ -577,38 +309,14 @@ public class BrushCommands { desc = "Creates a distorted sphere" ) @CommandPermissions("worldedit.brush.rock") - public BrushSettings blobBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Vector3", def = "10") Vector3 radius, @Arg(name = "sphericity", desc = "double", def = "100") double sphericity, @Arg(name = "frequency", desc = "double", def = "30") double frequency, @Arg(name = "amplitude", desc = "double", def = "50") double amplitude, InjectedValueAccess context) throws WorldEditException { + public BrushSettings blobBrush(LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Vector3", def = "10") Vector3 radius, @Arg(name = "sphericity", desc = "double", def = "100") double sphericity, @Arg(name = "frequency", desc = "double", def = "30") double frequency, @Arg(name = "amplitude", desc = "double", def = "50") double amplitude, InjectedValueAccess context) throws WorldEditException { double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ()); worldEdit.checkMaxBrushRadius(max); Brush brush = new BlobBrush(radius.divide(max), frequency / 100, amplitude / 100, sphericity / 100); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(max).setFill(fill); + return set(session, context, + brush) + .setSize(max) + .setFill(fill); } @Command( @@ -621,7 +329,7 @@ public class BrushCommands { @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Arg(desc = "The radius of the sphere", def = "2") - double radius, + Expression radius, @Switch(name = 'h', desc = "Create hollow spheres instead") boolean hollow, @Switch(name = 'f', desc = "Create falling spheres instead") @@ -631,12 +339,13 @@ public class BrushCommands { if (hollow) { brush = new HollowSphereBrush(); } else { - if (fill instanceof BlockStateHolder) { - BlockType type = ((BlockStateHolder) fill).getBlockType(); - int internalId = type.getInternalId(); - if (type == BlockTypes.SAND || type == BlockTypes.GRAVEL) { - BBC.BRUSH_TRY_OTHER.send(player); - falling = true; + if (pattern instanceof BlockStateHolder) { + BlockType type = ((BlockStateHolder) pattern).getBlockType(); + switch (type.getInternalId()) { + case BlockID.SAND: + case BlockID.GRAVEL: + BBC.BRUSH_TRY_OTHER.send(player); + falling = true; } } if (falling) { @@ -646,34 +355,10 @@ public class BrushCommands { } } - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(pattern); + return set(session, context, + brush) + .setSize(radius) + .setFill(pattern); } @Command( @@ -686,38 +371,14 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.shatter") public BrushSettings shatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(desc = "The radius to sample for blending", def = "10") - double radius, + Expression radius, @Arg(desc = "Lines", def = "10") int count, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new ShatterBrush(count); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill).setMask(new ExistingBlockMask(editSession)); + return set(session, context, + new ShatterBrush(count)) + .setSize(radius) + .setFill(fill) + .setMask(new ExistingBlockMask(editSession)); } @Command( @@ -728,7 +389,14 @@ public class BrushCommands { "The -r flag will apply random rotation" ) @CommandPermissions("worldedit.brush.stencil") - public BrushSettings stencilBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='w', desc = "TODO") boolean onlyWhite, @Switch(name='r', desc = "TODO") boolean randomRotate, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException { + public BrushSettings stencilBrush(Player player, LocalSession session, Pattern fill, + @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, + @Arg(name = "image", desc = "String", def = "") String image, + @Arg(def = "0", desc = "rotation") @Step(90) @Range(min=0, max=360) final int rotation, + @Arg(name = "yscale", desc = "double", def = "1") final double yscale, + @Switch(name='w', desc = "TODO") boolean onlyWhite, + @Switch(name='r', desc = "TODO") boolean randomRotate, + InjectedValueAccess context) throws WorldEditException, FileNotFoundException { worldEdit.checkMaxBrushRadius(radius); InputStream stream = getHeightmapStream(image); HeightBrush brush; @@ -740,34 +408,10 @@ public class BrushCommands { if (randomRotate) { brush.setRandomRotate(true); } - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == ((Brush) brush).getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill); + return set(session, context, + brush) + .setSize(radius) + .setFill(fill); } @Command( @@ -779,7 +423,12 @@ public class BrushCommands { "The -f blends the image with the existing terrain" ) @CommandPermissions("worldedit.brush.stencil") - public BrushSettings imageBrush(Player player, EditSession editSession, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, FawePrimitiveBinding.ImageUri imageUri, @Optional("1") @Range(min=Double.MIN_NORMAL) final double yscale, @Switch(name='a', desc = "TODO") boolean alpha, @Switch(name='f', desc = "TODO") boolean fadeOut, InjectedValueAccess context) throws WorldEditException, IOException, ParameterException { + public BrushSettings imageBrush(LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, + FawePrimitiveBinding.ImageUri imageUri, + @Arg(def = "1", desc = "scale height") @Range(min=Double.MIN_NORMAL) final double yscale, + @Switch(name='a', desc = "TODO") boolean alpha, + @Switch(name='f', desc = "TODO") boolean fadeOut, + InjectedValueAccess context) throws WorldEditException, IOException { BufferedImage image = imageUri.load(); worldEdit.checkMaxBrushRadius(radius); if (yscale != 1) { @@ -791,34 +440,9 @@ public class BrushCommands { alpha = true; } ImageBrush brush = new ImageBrush(image, session, alpha); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == ((Brush) brush).getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, + brush) + .setSize(radius); } @Command( @@ -830,37 +454,9 @@ public class BrushCommands { "The -r flag will apply random rotation" ) @CommandPermissions("worldedit.brush.surface") - public BrushSettings surfaceBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, InjectedValueAccess context) throws WorldEditException { + public BrushSettings surfaceBrush(LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new SurfaceSphereBrush(); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setFill(fill).setSize(radius); + return set(session, context, new SurfaceSphereBrush()).setFill(fill).setSize(radius); } @Command( @@ -871,7 +467,7 @@ public class BrushCommands { "Video: https://youtu.be/RPZIaTbqoZw?t=34s" ) @CommandPermissions("worldedit.brush.scatter") - public BrushSettings scatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "5") double points, @Arg(name = "distance", desc = "double", def = "1") double distance, @Switch(name='o', desc = "TODO") boolean overlay, InjectedValueAccess context) throws WorldEditException { + public BrushSettings scatterBrush(LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "5") double points, @Arg(name = "distance", desc = "double", def = "1") double distance, @Switch(name='o', desc = "TODO") boolean overlay, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); Brush brush; if (overlay) { @@ -879,34 +475,10 @@ public class BrushCommands { } else { brush = new ScatterBrush((int) points, (int) distance); } - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill); + return set(session, context, + brush) + .setSize(radius) + .setFill(fill); } @Command( @@ -917,10 +489,8 @@ public class BrushCommands { "The -r flag will apply random rotation" ) @CommandPermissions("worldedit.brush.populateschematic") - public BrushSettings scatterSchemBrush(Player player, EditSession editSession, LocalSession session, Mask mask, String clipboard, @Arg(name = "radius", desc = "Expression", def = "30") Expression radius, @Arg(name = "density", desc = "double", def = "50") double density, @Switch(name='r', desc = "TODO") boolean rotate, InjectedValueAccess context) throws WorldEditException { + public BrushSettings scatterSchemBrush(Player player, LocalSession session, Mask mask, String clipboard, @Arg(name = "radius", desc = "Expression", def = "30") Expression radius, @Arg(name = "density", desc = "double", def = "50") double density, @Switch(name='r', desc = "TODO") boolean rotate, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - - try { MultiClipboardHolder clipboards = ClipboardFormats.loadAllFromInput(player, clipboard, null, true); if (clipboards == null) { @@ -933,35 +503,9 @@ public class BrushCommands { return null; } - Brush brush = new PopulateSchem(mask, holders, (int) density, rotate); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, + new PopulateSchem(mask, holders, (int) density, rotate)) + .setSize(radius); } catch (IOException e) { throw new RuntimeException(e); } @@ -975,58 +519,11 @@ public class BrushCommands { "Pic: https://i.imgur.com/XV0vYoX.png" ) @CommandPermissions("worldedit.brush.layer") - public BrushSettings surfaceLayer(Player player, EditSession editSession, LocalSession session, Expression radius, InjectedValueAccess args, InjectedValueAccess context) throws WorldEditException, InvalidUsageException { + public BrushSettings surfaceLayer(LocalSession session, Expression radius, List layers, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - ParserContext parserContext = new ParserContext(); - parserContext.setActor(player); - parserContext.setWorld(player.getWorld()); - parserContext.setSession(session); - parserContext.setExtent(editSession); - List blocks = new ArrayList<>(); - if (args.argsLength() < 2) { - throw new InvalidUsageException(getCallable()); - } - try { - Color color = ColorUtil.parseColor(args.getString(1)); - BlockType[] glassLayers = Fawe.get().getTextureUtil().getNearestLayer(color.getRGB()); - for (BlockType layer : glassLayers) { - blocks.add(layer.getDefaultState()); - } - } catch (IllegalArgumentException ignore) { - for (int i = 1; i < args.argsLength(); i++) { - String arg = args.getString(i); - blocks.add(worldEdit.getBlockFactory().parseFromInput(arg, parserContext)); - } - } - Brush brush = new LayerBrush(blocks.toArray(new BlockStateHolder[0])); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args1 = (String) locals.get("arguments"); - if (args1 != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args1.substring(args1.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, + new LayerBrush(layers.toArray(new BlockState[0]))) + .setSize(radius); } @Command( @@ -1038,37 +535,12 @@ public class BrushCommands { "Note: The seeds define how many splotches there are, recursion defines how large, solid defines whether the pattern is applied per seed, else per block." ) @CommandPermissions("worldedit.brush.splatter") - public BrushSettings splatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "1") double points, @Arg(name = "recursion", desc = "double", def = "5") double recursion, @Arg(name = "solid", desc = "boolean", def = "true") boolean solid, InjectedValueAccess context) throws WorldEditException { + public BrushSettings splatterBrush(LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "1") double points, @Arg(name = "recursion", desc = "double", def = "5") double recursion, @Arg(name = "solid", desc = "boolean", def = "true") boolean solid, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new SplatterBrush((int) points, (int) recursion, solid); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius).setFill(fill); + return set(session, context, + new SplatterBrush((int) points, (int) recursion, solid)) + .setSize(radius) + .setFill(fill); } @Command( @@ -1082,37 +554,11 @@ public class BrushCommands { " - Placeholders: {x}, {y}, {z}, {world}, {size}" ) @CommandPermissions("worldedit.brush.scattercommand") - public BrushSettings scatterCommandBrush(Player player, EditSession editSession, LocalSession session, Expression radius, double points, double distance, InjectedValueAccess args, InjectedValueAccess context) throws WorldEditException { + public BrushSettings scatterCommandBrush(Player player, EditSession editSession, LocalSession session, Expression radius, double points, double distance, List command, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - Brush brush = new ScatterCommand((int) points, (int) distance, args.getJoinedStrings(3)); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args1 = (String) locals.get("arguments"); - if (args1 != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args1.substring(args1.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, + new ScatterCommand((int) points, (int) distance, StringMan.join(command, " "))) + .setSize(radius); } @Command( @@ -1125,7 +571,7 @@ public class BrushCommands { @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Arg(desc = "The radius of the cylinder", def = "2") - double radius, + Expression radius, @Arg(desc = "The height of the cylinder", def = "1") int height, @Switch(name = 'h', desc = "Create hollow cylinders instead") @@ -1136,67 +582,12 @@ public class BrushCommands { BrushSettings settings; if (hollow) { - Brush brush = new HollowCylinderBrush(height); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - settings = bs.setBrush(brush); + settings = set(session, context, new HollowCylinderBrush(height)); } else { - Brush brush = new CylinderBrush(height); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - settings = bs.setBrush(brush); + settings = set(session, context, new CylinderBrush(height)); } - settings.setSize(radius).setFill(pattern); + settings.setSize(radius) + .setFill(pattern); return settings; } @@ -1211,7 +602,7 @@ public class BrushCommands { "stood relative to the copied area when you copied it." ) @CommandPermissions("worldedit.brush.clipboard") - public BrushSettings clipboardBrush(Player player, LocalSession session, + public BrushSettings clipboardBrush(LocalSession session, @Switch(name = 'a', desc = "Don't paste air from the clipboard") boolean ignoreAir, @Switch(name = 'o', desc = "Paste starting at the target location, instead of centering on it") @@ -1231,35 +622,7 @@ public class BrushCommands { worldEdit.checkMaxBrushRadius(size.getBlockX()); worldEdit.checkMaxBrushRadius(size.getBlockY()); worldEdit.checkMaxBrushRadius(size.getBlockZ()); - Brush brush = new ClipboardBrush(holder, ignoreAir, usingOrigin, !skipEntities, pasteBiomes, sourceMask); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush); + return set(session, context, new ClipboardBrush(holder, ignoreAir, usingOrigin, !skipEntities, pasteBiomes, sourceMask)); } @Command( @@ -1270,47 +633,20 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.smooth") public BrushSettings smoothBrush(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius to sample for softening", def = "2") - double radius, + Expression radius, @Arg(desc = "The number of iterations to perform", def = "4") int iterations, @Arg(desc = "The mask of blocks to use for the heightmap", def = "") Mask mask, InjectedValueAccess context) throws WorldEditException { - worldEdit.checkMaxBrushRadius(radius); FawePlayer fp = FawePlayer.wrap(player); FaweLimit limit = Settings.IMP.getLimit(fp); iterations = Math.min(limit.MAX_ITERATIONS, iterations); - BrushTool tool = session.getBrushTool(player, false); - Brush brush = new SmoothBrush(iterations, mask); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, + new SmoothBrush(iterations, mask)) + .setSize(radius); } @Command( @@ -1321,41 +657,16 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.ex") public BrushSettings extinguishBrush(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius to extinguish", def = "5") - double radius, + Expression radius, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - BrushTool tool = session.getBrushTool(player, false); Pattern fill = BlockTypes.AIR.getDefaultState(); - Brush brush = new SphereBrush(); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush) - .setSize(radius).setFill(fill).setMask(new SingleBlockTypeMask(editSession, BlockTypes.FIRE)); + return set(session, context, + new SphereBrush()) + .setSize(radius) + .setFill(fill) + .setMask(new SingleBlockTypeMask(editSession, BlockTypes.FIRE)); } @Command( @@ -1366,41 +677,15 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.gravity") public BrushSettings gravityBrush(Player player, LocalSession session, @Arg(desc = "The radius to apply gravity in", def = "5") - double radius, + Expression radius, @Switch(name = 'h', desc = "Affect blocks starting at max Y, rather than the target location Y + radius") boolean fromMaxY, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - BrushTool tool = session.getBrushTool(player, false); - Brush brush = new GravityBrush(fromMaxY); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, + new GravityBrush(fromMaxY)) + .setSize(radius); } @Command( @@ -1415,7 +700,7 @@ public class BrushCommands { "Snow Pic: https://i.imgur.com/Hrzn0I4.png" ) @CommandPermissions("worldedit.brush.height") - public BrushSettings heightBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException { + public BrushSettings heightBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") final String image, @Arg(def = "0", desc = "rotation") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException { return terrainBrush(player, session, radius, image, rotation, yscale, false, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context); } @@ -1429,7 +714,7 @@ public class BrushCommands { " - The `-s` flag disables smoothing" ) @CommandPermissions("worldedit.brush.height") - public BrushSettings cliffBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException { + public BrushSettings cliffBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") String image, @Arg(def = "0", desc = "rotation") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException { return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CYLINDER, context); } @@ -1443,11 +728,11 @@ public class BrushCommands { desc = "This brush raises or lowers land towards the clicked point" ) @CommandPermissions("worldedit.brush.height") - public BrushSettings flattenBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException { + public BrushSettings flattenBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") final String image, @Arg(def = "0", desc = "rotation") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException { return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context); } - private BrushSettings terrainBrush(Player player, LocalSession session, Expression radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException { + private BrushSettings terrainBrush(Player player, LocalSession session, Expression radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape, InjectedValueAccess context) throws WorldEditException, FileNotFoundException { worldEdit.checkMaxBrushRadius(radius); InputStream stream = getHeightmapStream(image); HeightBrush brush; @@ -1467,37 +752,12 @@ public class BrushCommands { if (randomRotate) { brush.setRandomRotate(true); } - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == ((Brush) brush).getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, + brush) + .setSize(radius); } - private InputStream getHeightmapStream(String filename) throws FileNotFoundException, ParameterException { + private InputStream getHeightmapStream(String filename) throws FileNotFoundException { if (filename == null) return null; String filenamePng = (filename.endsWith(".png") ? filename : filename + ".png"); File file = new File(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP + File.separator + filenamePng); @@ -1523,35 +783,9 @@ public class BrushCommands { worldEdit.checkMaxBrushRadius(radius); player.print(BBC.BRUSH_COPY.f(radius)); - Brush brush = new CopyPastaBrush(player, session, randomRotate, autoRotate); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args = (String) locals.get("arguments"); - if (args != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + return set(session, context, + new CopyPastaBrush(player, session, randomRotate, autoRotate)) + .setSize(radius); } @Command( @@ -1563,37 +797,12 @@ public class BrushCommands { " - Placeholders: {x}, {y}, {z}, {world}, {size}" ) @CommandPermissions("worldedit.brush.command") - public BrushSettings command(Player player, LocalSession session, Expression radius, InjectedValueAccess args, InjectedValueAccess context) throws WorldEditException { - String cmd = args.getJoinedStrings(1); - Brush brush = new CommandBrush(cmd); - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool = session.getBrushTool(player, false); - if (tool != null) { - BrushSettings currentContext = tool.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args1 = (String) locals.get("arguments"); - if (args1 != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args1.substring(args1.indexOf(' ') + 1)); - } - return bs.setBrush(brush).setSize(radius); + public BrushSettings command(Player player, LocalSession session, Expression radius, @Arg(desc = "Command to run") List input, InjectedValueAccess context) throws WorldEditException { + worldEdit.checkMaxBrushRadius(radius); + String cmd = StringMan.join(input, " "); + return set(session, context, + new CommandBrush(cmd)) + .setSize(radius); } @Command( @@ -1602,9 +811,9 @@ public class BrushCommands { desc = "Butcher brush, kills mobs within a radius" ) @CommandPermissions("worldedit.brush.butcher") - public BrushSettings butcherBrush(Player player, LocalSession session, InjectedValueAccess args, + public BrushSettings butcherBrush(Player player, LocalSession session, InjectedValueAccess context, @Arg(desc = "Radius to kill mobs in", def = "5") - double radius, + Expression radius, @Switch(name = 'p', desc = "Also kill pets") boolean killPets, @Switch(name = 'n', desc = "Also kill NPCs") @@ -1621,19 +830,7 @@ public class BrushCommands { boolean killFriendly, @Switch(name = 'r', desc = "Also destroy armor stands") boolean killArmorStands) throws WorldEditException { - LocalConfiguration config = worldEdit.getConfiguration(); - - double maxRadius = config.maxBrushRadius; - // hmmmm not horribly worried about this because -1 is still rather efficient, - // the problem arises when butcherMaxRadius is some really high number but not infinite - // - original idea taken from https://github.com/sk89q/worldedit/pull/198#issuecomment-6463108 - if (player.hasPermission("worldedit.butcher")) { - maxRadius = Math.max(config.maxBrushRadius, config.butcherMaxRadius); - } - if (radius > maxRadius) { - BBC.TOOL_RADIUS_ERROR.send(player, maxRadius); - return null; - } + worldEdit.checkMaxBrushRadius(radius); CreatureButcher flags = new CreatureButcher(player); flags.or(CreatureButcher.Flags.FRIENDLY , killFriendly); // No permission check here. Flags will instead be filtered by the subsequent calls. @@ -1645,42 +842,11 @@ public class BrushCommands { flags.or(CreatureButcher.Flags.TAGGED , killWithName, "worldedit.butcher.tagged"); flags.or(CreatureButcher.Flags.ARMOR_STAND , killArmorStands, "worldedit.butcher.armorstands"); - BrushTool tool = session.getBrushTool(player); - tool.setSize(radius); - ButcherBrush brush = new ButcherBrush(flags); - tool.setBrush(brush, "worldedit.brush.butcher"); - - CommandLocals locals = context.getLocals(); - BrushSettings bs = new BrushSettings(); - - BrushTool tool1 = session.getBrushTool(player, false); - if (tool1 != null) { - BrushSettings currentContext = tool1.getContext(); - if (currentContext != null) { - Brush currentBrush = currentContext.getBrush(); - if (currentBrush != null && currentBrush.getClass() == ((Brush) brush).getClass()) { - bs = currentContext; - } - } - } - - CommandCallable callable = locals.get(CommandCallable.class); - String[] perms; - if (callable instanceof AParametricCallable) { - perms = ((AParametricCallable) callable).getPermissions(); - } else { - perms = getPermissions(); - } - bs.addPermissions(perms); - - String args1 = (String) locals.get("arguments"); - if (args1 != null) { - bs.addSetting(BrushSettings.SettingType.BRUSH, args1.substring(args1.indexOf(' ') + 1)); - } - return bs.setBrush(brush); + return set(session, context, + new ButcherBrush(flags)) + .setSize(radius); } - @Override public BrushSettings process(CommandLocals locals, BrushSettings settings) throws WorldEditException { Actor actor = locals.get(Actor.class); LocalSession session = worldEdit.getSessionManager().get(actor); @@ -1694,4 +860,24 @@ public class BrushCommands { return null; } + public BrushSettings set(LocalSession session, InjectedValueAccess context, Brush brush) throws InvalidToolBindException { + Player plr = context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player")); + BrushSettings bs = new BrushSettings(); + BrushTool tool = session.getBrushTool(plr, false); + if (tool != null) { + BrushSettings currentContext = tool.getContext(); + if (currentContext != null) { + Brush currentBrush = currentContext.getBrush(); + if (currentBrush != null && currentBrush.getClass() == brush.getClass()) { + bs = currentContext; + } + } + } + String[] perms = getPermissions(context); + bs.addPermissions(perms); + String args = getArguments(context); + bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1)); + return bs.setBrush(brush); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java index e8787cefb..11578aec8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java @@ -43,7 +43,6 @@ import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.Mask; -import com.sk89q.worldedit.util.command.parametric.ParameterException; import com.sk89q.worldedit.util.formatting.component.PaginationBox; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.block.BaseBlock; @@ -69,7 +68,7 @@ import static com.google.common.base.Preconditions.checkNotNull; * General WorldEdit commands. */ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) -@Command(aliases = {}, desc = "Player toggles, settings and item info") +//@Command(aliases = {}, desc = "Player toggles, settings and item info") public class GeneralCommands { private final WorldEdit worldEdit; @@ -373,18 +372,11 @@ public class GeneralCommands { desc = "Set the global transform" ) @CommandPermissions({"worldedit.global-transform", "worldedit.transform.global"}) - public void gtransform(Player player, EditSession editSession, LocalSession session, @Arg(name = "context", desc = "InjectedValueAccess", def = "") InjectedValueAccess context) throws WorldEditException { - if (context == null || context.argsLength() == 0) { - session.setTransform(null); + public void gtransform(Player player, EditSession editSession, LocalSession session, ResettableExtent transform) throws WorldEditException { + session.setTransform(transform); + if (transform == null) { BBC.TRANSFORM_DISABLED.send(player); } else { - ParserContext parserContext = new ParserContext(); - parserContext.setActor(player); - parserContext.setWorld(player.getWorld()); - parserContext.setSession(session); - parserContext.setExtent(editSession); - ResettableExtent transform = Fawe.get().getTransformParser().parseFromInput(context.getJoinedStrings(0), parserContext); - session.setTransform(transform); BBC.TRANSFORM.send(player); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index 4dc9bb410..87408bc44 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -46,7 +46,6 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.internal.annotation.Range; import org.enginehub.piston.annotation.param.Switch; -import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.world.World; import java.io.File; import java.util.UUID; @@ -55,20 +54,25 @@ import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Commands to undo, redo, and clear history. */ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) -@Command(aliases = {}, desc = "Commands to undo, redo, and clear history: [More Info](http://wiki.sk89q.com/wiki/WorldEdit/Features#History)") +//@Command(aliases = {}, desc = "Commands to undo, redo, and clear history: [More Info](http://wiki.sk89q.com/wiki/WorldEdit/Features#History)") public class HistoryCommands extends MethodCommands { + private final WorldEdit worldEdit; + /** * Create a new instance. * * @param worldEdit reference to WorldEdit */ public HistoryCommands(WorldEdit worldEdit) { - super(worldEdit); + checkNotNull(worldEdit); + this.worldEdit = worldEdit; } @Command( @@ -79,7 +83,7 @@ public class HistoryCommands extends MethodCommands { " - Import from disk: /frb #import" ) @CommandPermissions("worldedit.history.rollback") - public void faweRollback(final Player player, LocalSession session, final String user, @Optional("0") @Range(min = 0) int radius, @Arg(name = "time", desc = "String", def = "0") String time, @Switch(name='r', desc = "TODO") boolean restore) throws WorldEditException { + public void faweRollback(final Player player, LocalSession session, final String user, @Arg(def = "0", desc = "radius") @Range(min = 0) int radius, @Arg(name = "time", desc = "String", def = "0") String time, @Switch(name='r', desc = "TODO") boolean restore) throws WorldEditException { if (!Settings.IMP.HISTORY.USE_DATABASE) { BBC.SETTING_DISABLE.send(player, "history.use-database (Import with /frb #import )"); return; @@ -205,7 +209,7 @@ public class HistoryCommands extends MethodCommands { " - Import from disk: /frb #import" ) @CommandPermissions("worldedit.history.rollback") - public void restore(final Player player, LocalSession session, final String user, @Optional("0") @Range(min = 0) int radius, @Arg(name = "time", desc = "String", def = "0") String time) throws WorldEditException { + public void restore(final Player player, LocalSession session, final String user, @Arg(def = "0", desc = "radius") @Range(min = 0) int radius, @Arg(name = "time", desc = "String", def = "0") String time) throws WorldEditException { faweRollback(player, session, user, radius, time, true); } @@ -226,7 +230,7 @@ public class HistoryCommands extends MethodCommands { return; } LocalSession undoSession; - if (context.argsLength() == 2) { + if (playerName != null && !playerName.isEmpty()) { player.checkPermission("worldedit.history.undo.other"); undoSession = worldEdit.getSessionManager().findByName(playerName); if (undoSession == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchemListFilters.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ListFilters.java similarity index 72% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/SchemListFilters.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/ListFilters.java index 52010bed0..fee888e32 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchemListFilters.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ListFilters.java @@ -6,9 +6,11 @@ import com.boydti.fawe.util.StringMan; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.util.formatting.text.TextComponent; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; +import org.enginehub.piston.exception.StopExecutionException; import java.io.File; import java.io.IOException; @@ -18,7 +20,7 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @CommandContainer -public class SchemListFilters { +public class ListFilters { public class Filter { public boolean listPrivate() { return true; @@ -29,7 +31,7 @@ public class SchemListFilters { } public File getPath(File root) { - return root; + return null; } public boolean applies(File file) { @@ -82,13 +84,27 @@ public class SchemListFilters { name = "", desc = "wildcard" ) - public Filter wildcard(Actor actor, String arg) { + public Filter wildcard(Actor actor, File root, String arg) { arg = arg.replace("/", File.separator); String argLower = arg.toLowerCase(Locale.ROOT); - if (arg.endsWith("/") || arg.endsWith(File.separator)) { - if (arg.length() > 3 && arg.length() <= 16) { - // possible player name - } + if (arg.endsWith(File.separator)) { + String finalArg = arg; + return new Filter() { + @Override + public File getPath(File root) { + File newRoot = new File(root, finalArg); + if (newRoot.exists()) return newRoot; + String firstArg = finalArg.substring(0, finalArg.length() - File.separator.length()); + if (firstArg.length() > 3 && firstArg.length() <= 16) { + UUID fromName = Fawe.imp().getUUID(finalArg); + if (fromName != null) { + newRoot = new File(root, finalArg); + if (newRoot.exists()) return newRoot; + } + } + throw new StopExecutionException(TextComponent.of("Cannot find path: " + finalArg)); + } + }; } else { if (StringMan.containsAny(arg, "\\^$.|?+(){}<>~$!%^&*+-/")) { Pattern pattern; @@ -113,24 +129,5 @@ public class SchemListFilters { } }; } - if (arg.endsWith("/") || arg.endsWith(File.separator)) { - arg = arg.replace("/", File.separator); - String newDirFilter = dirFilter + arg; - boolean exists = new File(dir, newDirFilter).exists() || playerFolder && MainUtil.resolveRelative(new File(dir, actor.getUniqueId() + newDirFilter)).exists(); - if (!exists) { - arg = arg.substring(0, arg.length() - File.separator.length()); - if (arg.length() > 3 && arg.length() <= 16) { - UUID fromName = Fawe.imp().getUUID(arg); - if (fromName != null) { - newDirFilter = dirFilter + fromName + File.separator; - listGlobal = true; - } - } - } - dirFilter = newDirFilter; - } - else { - filters.add(arg); - } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/MethodCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/MethodCommands.java index 048ea7a5a..8b3d4979d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/MethodCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/MethodCommands.java @@ -1,58 +1,20 @@ package com.sk89q.worldedit.command; import com.boydti.fawe.config.Commands; +import com.sk89q.worldedit.command.argument.Arguments; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.inject.InjectedValueAccess; -import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.util.command.CommandCallable; -import com.sk89q.worldedit.util.command.Dispatcher; +import org.enginehub.piston.inject.Key; + import java.lang.reflect.Method; -import java.util.concurrent.ConcurrentHashMap; +import java.util.Optional; import static com.google.common.base.Preconditions.checkNotNull; public class MethodCommands { - public final WorldEdit worldEdit; - private ConcurrentHashMap callables; - private Dispatcher dispatcher; - - public MethodCommands(WorldEdit worldEdit) { - checkNotNull(worldEdit); - this.worldEdit = worldEdit; - callables = new ConcurrentHashMap<>(); - } - - @Deprecated - public MethodCommands() { - this(WorldEdit.getInstance()); - } - - public void register(Method method, CommandCallable callable, Dispatcher dispatcher) { - this.dispatcher = dispatcher; - this.callables.put(method, callable); - } - - public CommandCallable getCallable() { - try { - StackTraceElement[] stack = new Exception().getStackTrace(); - for (StackTraceElement elem : stack) { - Class clazz = Class.forName(elem.getClassName()); - for (Method method : clazz.getMethods()) { - if (method.getName().equals(elem.getMethodName())) { - Command command = method.getAnnotation(Command.class); - if (command != null) return callables.get(method); - } - } - } - } catch (Throwable e) { - e.printStackTrace(); - } - return dispatcher; - } - public Command getCommand() { try { StackTraceElement[] stack = new Exception().getStackTrace(); @@ -73,14 +35,18 @@ public class MethodCommands { public String getArguments(InjectedValueAccess context) { if (context == null) return null; - CommandLocals locals = context.getLocals(); - if (locals != null) { - return (String) locals.get("arguments"); + Optional arguments = context.injectedValue(Key.of(Arguments.class)); + if (arguments.isPresent()) { + return arguments.get().get(); } return null; } - public String[] getPermissions() { + public String[] getPermissions(InjectedValueAccess context) { + CommandPermissions cmdPerms = context.injectedValue(Key.of(CommandPermissions.class)).orElse(null); + if (cmdPerms != null) { + return cmdPerms.value(); + } try { StackTraceElement[] stack = new Exception().getStackTrace(); for (StackTraceElement elem : stack) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 2e4f02782..b2459f409 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -20,8 +20,7 @@ package com.sk89q.worldedit.command; import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.ALL; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; +import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL; 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.internal.command.CommandUtil.checkCommandArgument; @@ -30,12 +29,12 @@ import static com.sk89q.worldedit.regions.Regions.maximumBlockY; import static com.sk89q.worldedit.regions.Regions.minimumBlockY; +import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweAPI; import com.boydti.fawe.beta.filters.SetFilter; import com.boydti.fawe.beta.implementation.QueueHandler; import com.boydti.fawe.beta.filters.DistrFilter; import com.boydti.fawe.config.BBC; -import com.boydti.fawe.example.NMSMappedIQueueExtent; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.beta.IQueueExtent; @@ -99,9 +98,9 @@ import org.enginehub.piston.annotation.param.Switch; /** * Commands that operate on regions. */ -@Command(aliases = {}, desc = "Commands that operate on regions: [More Info](http://wiki.sk89q.com/wiki/WorldEdit/Region_operations)") +//@Command(aliases = {}, desc = "Commands that operate on regions: [More Info](http://wiki.sk89q.com/wiki/WorldEdit/Region_operations)") @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) -public class RegionCommands { +public class RegionCommands extends MethodCommands { private final WorldEdit worldEdit; @@ -115,43 +114,6 @@ public class RegionCommands { this.worldEdit = worldEdit; } - - @Command( - aliases = {"debugtest"}, - usage = "", - desc = "debugtest", - help = "debugtest" - ) - @CommandPermissions("fawe.admin.debug") - public void debugtest(Player player, @Selection Region region) throws WorldEditException { - QueueHandler queueHandler = Fawe.get().getQueueHandler(); - World world = player.getWorld(); - DistrFilter filter = new DistrFilter(); - long start = System.currentTimeMillis(); - queueHandler.apply(world, region, filter); - long diff = System.currentTimeMillis() - start; - System.out.println(diff); - } - - @Command( - aliases = {"db2"}, - usage = "", - desc = "db2", - help = "db2" - ) - @CommandPermissions("fawe.admin.debug") - public void db2(Player player, @Selection Region region, String blockStr) throws WorldEditException { - QueueHandler queueHandler = Fawe.get().getQueueHandler(); - World world = player.getWorld(); - BlockState block = BlockState.get(blockStr); - SetFilter filter = new SetFilter(block); - long start = System.currentTimeMillis(); - queueHandler.apply(world, region, filter); - long diff = System.currentTimeMillis() - start; - System.out.println(diff); - } - - @Command( name = "/fixlighting", desc = "Get the light at a position" @@ -166,7 +128,7 @@ public class RegionCommands { final int cz = loc.getBlockZ() >> 4; selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16)); } - int count = FaweAPI.fixLighting(player.getWorld(), selection,null, IQueueExtent.RelightMode.ALL); + int count = FaweAPI.fixLighting(player.getWorld(), selection,null); BBC.LIGHTING_PROPOGATE_SELECTION.send(fp, count); } @@ -175,11 +137,12 @@ public class RegionCommands { desc = "Get the light at a position" ) @CommandPermissions("worldedit.light.fix") - public void getlighting(Player player) throws WorldEditException { + public void getlighting(Player player, EditSession editSession) throws WorldEditException { FawePlayer fp = FawePlayer.wrap(player); final Location loc = player.getLocation(); - IQueueExtent queue = fp.getIQueueExtent(false); - fp.sendMessage("Light: " + queue.getEmmittedLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()) + " | " + queue.getSkyLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + int block = editSession.getBlockLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + int sky = editSession.getSkyLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + fp.sendMessage("Light: " + block + " | " + sky); } @Command( @@ -195,7 +158,7 @@ public class RegionCommands { final int cz = player.getLocation().getBlockZ() >> 4; selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16)); } - int count = FaweAPI.fixLighting(player.getWorld(), selection, null, IQueueExtent.RelightMode.NONE); + int count = FaweAPI.fixLighting(player.getWorld(), selection, null); BBC.UPDATED_LIGHTING_SELECTION.send(fp, count); } @@ -223,18 +186,8 @@ public class RegionCommands { desc = "Set block lighting in a selection" ) @CommandPermissions("worldedit.light.set") - public void setlighting(Player player, @Selection Region region, @Range(min = 0, max = 15) int value) { - FawePlayer fp = FawePlayer.wrap(player); - final NMSMappedIQueueExtent queue = (NMSMappedIQueueExtent) fp.getIQueueExtent(false); - for (BlockVector3 pt : region) { - queue.setBlockLight(pt.getX(), pt.getY(), pt.getZ(), value); - } - int count = 0; - for (BlockVector2 chunk : region.getChunks()) { - queue.sendChunk(queue.getFaweChunk(chunk.getBlockX(), chunk.getBlockZ())); - count++; - } - BBC.UPDATED_LIGHTING_SELECTION.send(fp, count); + public void setlighting(Player player, EditSession editSession, @Selection Region region, @Range(min = 0, max = 15) int value) { + // TODO NOT IMPLEMENTED } @Command( @@ -243,17 +196,7 @@ public class RegionCommands { ) @CommandPermissions("worldedit.light.set") public void setskylighting(Player player, @Selection Region region, @Range(min = 0, max = 15) int value) { - FawePlayer fp = FawePlayer.wrap(player); - final NMSMappedIQueueExtent queue = (NMSMappedIQueueExtent) fp.getIQueueExtent(false); - for (BlockVector3 pt : region) { - queue.setSkyLight(pt.getX(), pt.getY(), pt.getZ(), value); - } - int count = 0; - for (BlockVector2 chunk : region.getChunks()) { - queue.sendChunk(queue.getFaweChunk(chunk.getBlockX(), chunk.getBlockZ())); - count++; - } - BBC.UPDATED_LIGHTING_SELECTION.send(fp, count); + // TODO NOT IMPLEMENTED } @Command( @@ -338,7 +281,8 @@ public class RegionCommands { } @Command( - aliases = { "/set", "/s" }, + name = "/set", + aliases = { "/s" }, desc = "Set all blocks within selection" ) @CommandPermissions("worldedit.region.set") @@ -628,7 +572,7 @@ public class RegionCommands { ) @CommandPermissions("worldedit.region.deform") @Logging(ALL) - public void deform(FawePlayer fp, Player player, LocalSession session, EditSession editSession, + public void deform(FawePlayer fp, Player player, LocalSession session, EditSession editSession, InjectedValueAccess context, @Selection Region region, @Arg(desc = "The expression to use", variable = true) List expression, @@ -660,7 +604,7 @@ public class RegionCommands { final Vector3 unit1 = unit; fp.checkConfirmationRegion(() -> { try { - final int affected = editSession.deformRegion(region, zero, unit1, expression); + final int affected = editSession.deformRegion(region, zero, unit1, String.join(" ", expression), session.getTimeout()); player.findFreePosition(); BBC.VISITOR_BLOCK.send(fp, affected); } catch (ExpressionException e) { @@ -679,18 +623,14 @@ public class RegionCommands { ) @CommandPermissions("worldedit.regen") @Logging(REGION) - public void regenerateChunk(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, InjectedValueAccess context) throws WorldEditException { + public void regenerateChunk(FawePlayer 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); - BiomeType biome = null; - if (context.argsLength() >= 1) { - BiomeRegistry biomeRegistry = worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); - Collection knownBiomes = BiomeTypes.values(); - biome = Biomes.findBiomeByName(knownBiomes, context.getString(0), biomeRegistry); - } - Long seed = context.argsLength() != 2 || !MathMan.isInteger(context.getString(1)) ? null : Long.parseLong(context.getString(1)); editSession.regenerate(region, biome, seed); session.setMask(mask); session.setSourceMask(mask); @@ -726,7 +666,7 @@ public class RegionCommands { int thickness, @Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air") Pattern pattern, - + @Switch(name='m', desc = "Mask to hollow with") Mask mask, InjectedValueAccess context) throws WorldEditException { Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask; player.checkConfirmationRegion(() -> { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 28b0251ee..ac5ded535 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -704,7 +704,6 @@ public class UtilityCommands { } public static void list(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, RunnableVal3 eachMsg) { - AtomicInteger pageInt = new AtomicInteger(page); List fileList = new ArrayList<>(); if (perPage == -1) perPage = actor instanceof Player ? 12 : 20; // More pages for console page = getFiles(dir, actor, args, page, perPage, formatName, playerFolder, fileList::add); @@ -770,6 +769,11 @@ public class UtilityCommands { m.send(actor); } + public static int getFiles(File root, Actor actor, InjectedValueAccess args, int page, int perPage, String formatName, boolean playerFolder, Consumer forEachFile, ListFilters... filters) { + // TODO NOT IMPLEMENTED replace getFiles + return page; + } + public static int getFiles(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, Consumer forEachFile) { Consumer rootFunction = forEachFile; //schem list all @@ -890,7 +894,6 @@ public class UtilityCommands { } private static List filter(List fileList, List filters) { - String[] normalizedNames = new String[fileList.size()]; for (int i = 0; i < fileList.size(); i++) { String normalized = fileList.get(i).getName().toLowerCase(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Annotations.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Annotations.java similarity index 100% rename from worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Annotations.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Annotations.java diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 183025874..7040ba4a5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -85,6 +85,7 @@ import com.sk89q.worldedit.command.argument.RegistryConverter; import com.sk89q.worldedit.command.argument.VectorConverter; import com.sk89q.worldedit.command.argument.ZonedDateTimeConverter; import com.sk89q.worldedit.command.tool.brush.Brush; +import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandQueued; import com.sk89q.worldedit.command.util.CommandQueuedCondition; import com.sk89q.worldedit.command.util.PermissionCondition; @@ -114,6 +115,7 @@ import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.world.World; import java.io.File; import java.io.IOException; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -545,13 +547,48 @@ public final class PlatformCommandManager { return def; } + private Actor wrapActor(Actor actor, InjectedValueStore context) { + if (actor instanceof Player) { + final Set failedPermissions = new LinkedHashSet<>(); + Player player = (Player) actor; + Player unwrapped = LocationMaskedPlayerWrapper.unwrap(player); + actor = new LocationMaskedPlayerWrapper(unwrapped, player.getLocation(), true) { + @Override + public boolean hasPermission(String permission) { + if (!super.hasPermission(permission)) { + failedPermissions.add(permission); + return false; + } + return true; + } + @Override + public void checkPermission(String permission) throws AuthorizationException { + try { + super.checkPermission(permission); + } catch (AuthorizationException e) { + failedPermissions.add(permission); + throw e; + } + } + }; + context.injectValue(Key.of(CommandPermissions.class), i -> Optional.of(new CommandPermissions() { + @Override + public Class annotationType() { + return CommandPermissions.class; + } + @Override + public String[] value() { + return failedPermissions.toArray(new String[0]); + } + })); + } + return actor; + } + @Subscribe public void handleCommand(CommandEvent event) { Request.reset(); Actor actor = event.getActor(); - if (actor instanceof Player) { - actor = LocationMaskedPlayerWrapper.wrap((Player) actor); - } String args = event.getArguments(); CommandEvent finalEvent = new CommandEvent(actor, args); final FawePlayer fp = FawePlayer.wrap(actor); @@ -595,22 +632,14 @@ public final class PlatformCommandManager { } MemoizingValueAccess context = initializeInjectedValues(event::getArguments, actor); - final FawePlayer fp = FawePlayer.wrap(actor); - if (fp == null) { - throw new IllegalArgumentException("FAWE doesn't support: " + actor); - } - ThrowableSupplier task = () -> commandManager.execute(context,Lists.newArrayList(split)); - handleCommandTask(task, context, actor, session, event); + handleCommandTask(task, context, session, event); } - public Object handleCommandTask(ThrowableSupplier task, InjectedValueAccess context, @NotNull Actor actor, @Nullable LocalSession session, CommandEvent event) { - String[] split = parseArgs(event.getArguments()) - .map(Substring::getSubstring) - .toArray(String[]::new); - + public Object handleCommandTask(ThrowableSupplier task, InjectedValueAccess context, @Nullable LocalSession session, CommandEvent event) { + Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("No player")); Request.reset(); long start = System.currentTimeMillis(); @@ -689,9 +718,10 @@ public final class PlatformCommandManager { private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor) { InjectedValueStore store = MapBackedValueStore.create(); - store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor)); - if (actor instanceof Player) { - store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor)); + Actor finalActor = wrapActor(actor, store); + store.injectValue(Key.of(Actor.class), ValueProvider.constant(finalActor)); + if (finalActor instanceof Player) { + store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) finalActor)); } else { store.injectValue(Key.of(Player.class), context -> { throw new CommandException(TextComponent.of("This command must be used with a player."), ImmutableList.of()); @@ -700,8 +730,8 @@ public final class PlatformCommandManager { store.injectValue(Key.of(Arguments.class), ValueProvider.constant(arguments)); store.injectValue(Key.of(LocalSession.class), context -> { - LocalSession localSession = worldEdit.getSessionManager().get(actor); - localSession.tellVersion(actor); + LocalSession localSession = worldEdit.getSessionManager().get(finalActor); + localSession.tellVersion(finalActor); return Optional.of(localSession); });