From fdfc3cdb33a576410ddf4cac4bd404cb50735ba3 Mon Sep 17 00:00:00 2001 From: Albert Pham Date: Thu, 29 Oct 2015 13:05:04 -0700 Subject: [PATCH] Reorganize and further unify the new commands. --- .../{ItemArg.java => ItemParser.java} | 14 +-- .../{ItemUserArg.java => ItemUseParser.java} | 17 ++- .../{NumberArg.java => NumberParser.java} | 6 +- .../{PatternArg.java => PatternParser.java} | 10 +- ...ctoryArg.java => RegionFactoryParser.java} | 2 +- ...atorArg.java => RegionFunctionParser.java} | 16 +-- .../command/argument/RegionReplaceArg.java | 59 --------- .../command/argument/ReplaceParser.java | 75 ++++++++++++ .../{StringArg.java => StringParser.java} | 6 +- ...ratorArg.java => TreeGeneratorParser.java} | 14 +-- .../command/composition/ApplyCommand.java | 36 ++++-- .../DeformCommand.java} | 12 +- ...{ScatterCommand.java => PaintCommand.java} | 33 +++-- .../composition/ReplaceBrushCommand.java | 75 ------------ .../command/composition/SelectionCommand.java | 114 ++++++++++++++++++ .../composition/ShapedBrushCommand.java | 21 ++-- .../worldedit/command/tool/BrushTool.java | 20 +-- .../command/tool/brush/CylinderBrush.java | 6 + .../tool/brush/HollowCylinderBrush.java | 6 + .../command/tool/brush/HollowSphereBrush.java | 6 + .../tool/brush/OperationFactoryBrush.java | 8 +- .../command/tool/brush/SphereBrush.java | 6 + .../extension/platform/CommandManager.java | 16 ++- .../extent/reorder/MultiStageReorder.java | 4 + .../extent/world/FastModeExtent.java | 5 + .../OperationFactory.java => Contextual.java} | 9 +- .../sk89q/worldedit/function/EditContext.java | 23 ++-- .../factory/{RegionApply.java => Apply.java} | 28 +++-- .../worldedit/function/factory/Deform.java | 60 +++++++-- .../factory/{Scatter.java => Paint.java} | 39 ++++-- .../function/factory/RegionReplace.java | 40 ------ .../operation/BlockMapEntryPlacer.java | 6 + .../function/operation/ChangeSetExecutor.java | 5 + .../function/operation/DelegateOperation.java | 8 ++ .../function/operation/ForwardExtentCopy.java | 4 + .../function/operation/Operation.java | 10 ++ .../function/operation/OperationQueue.java | 11 ++ .../function/visitor/BreadthFirstSearch.java | 7 +- .../function/visitor/EntityVisitor.java | 6 + .../function/visitor/FlatRegionVisitor.java | 7 ++ .../function/visitor/LayerVisitor.java | 7 ++ .../function/visitor/RegionVisitor.java | 7 ++ 42 files changed, 543 insertions(+), 321 deletions(-) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/{ItemArg.java => ItemParser.java} (86%) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/{ItemUserArg.java => ItemUseParser.java} (81%) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/{NumberArg.java => NumberParser.java} (92%) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/{PatternArg.java => PatternParser.java} (90%) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/{RegionFactoryArg.java => RegionFactoryParser.java} (97%) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/{PointGeneratorArg.java => RegionFunctionParser.java} (70%) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionReplaceArg.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ReplaceParser.java rename worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/{StringArg.java => StringParser.java} (92%) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/{TreeGeneratorArg.java => TreeGeneratorParser.java} (86%) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/{argument/DeformArg.java => composition/DeformCommand.java} (84%) rename worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/{ScatterCommand.java => PaintCommand.java} (56%) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ReplaceBrushCommand.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java rename worldedit-core/src/main/java/com/sk89q/worldedit/function/{factory/OperationFactory.java => Contextual.java} (77%) rename worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/{RegionApply.java => Apply.java} (57%) rename worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/{Scatter.java => Paint.java} (57%) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/RegionReplace.java diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemParser.java similarity index 86% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemParser.java index e6eb8d1ed..3f548fb06 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemParser.java @@ -34,21 +34,21 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.world.World; -public class ItemArg extends SimpleCommand { +public class ItemParser extends SimpleCommand { - private final StringArg stringArg; + private final StringParser stringParser; - public ItemArg(String name) { - stringArg = addParameter(new StringArg(name, "The item name", null)); + public ItemParser(String name) { + stringParser = addParameter(new StringParser(name, "The item name", null)); } - public ItemArg(String name, String defaultSuggestion) { - stringArg = addParameter(new StringArg(name, "The item name", defaultSuggestion)); + public ItemParser(String name, String defaultSuggestion) { + stringParser = addParameter(new StringParser(name, "The item name", defaultSuggestion)); } @Override public BaseItem call(CommandArgs args, CommandLocals locals) throws CommandException { - String itemString = stringArg.call(args, locals); + String itemString = stringParser.call(args, locals); Actor actor = locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUserArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java similarity index 81% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUserArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java index 252838b91..94e30e1b0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUserArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java @@ -19,13 +19,13 @@ package com.sk89q.worldedit.command.argument; -import com.google.common.base.Function; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItem; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.util.Direction; @@ -33,15 +33,13 @@ import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.util.command.composition.SimpleCommand; import com.sk89q.worldedit.world.World; -import javax.annotation.Nullable; +public class ItemUseParser extends SimpleCommand> { -public class ItemUserArg extends SimpleCommand> { - - private final ItemArg itemArg = addParameter(new ItemArg("item", "minecraft:dye:15")); + private final ItemParser itemParser = addParameter(new ItemParser("item", "minecraft:dye:15")); @Override - public Function call(CommandArgs args, CommandLocals locals) throws CommandException { - BaseItem item = itemArg.call(args, locals); + public Contextual call(CommandArgs args, CommandLocals locals) throws CommandException { + BaseItem item = itemParser.call(args, locals); return new ItemUseFactory(item); } @@ -55,16 +53,15 @@ public class ItemUserArg extends SimpleCommand { + private static final class ItemUseFactory implements Contextual { private final BaseItem item; private ItemUseFactory(BaseItem item) { this.item = item; } - @Nullable @Override - public RegionFunction apply(EditContext input) { + public RegionFunction createFromContext(EditContext input) { World world = ((EditSession) input.getDestination()).getWorld(); return new ItemUseFunction(world, item); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberParser.java similarity index 92% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberParser.java index 54ccb7bc5..9c7f2fed2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/NumberParser.java @@ -29,17 +29,17 @@ import com.sk89q.worldedit.util.command.composition.CommandExecutor; import java.util.Collections; import java.util.List; -public class NumberArg implements CommandExecutor { +public class NumberParser implements CommandExecutor { private final String name; private final String description; private final String defaultSuggestion; - public NumberArg(String name, String description) { + public NumberParser(String name, String description) { this(name, description, null); } - public NumberArg(String name, String description, String defaultSuggestion) { + public NumberParser(String name, String description, String defaultSuggestion) { this.name = name; this.description = description; this.defaultSuggestion = defaultSuggestion; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternParser.java similarity index 90% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternParser.java index ac4f57d79..7a5f9a928 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternParser.java @@ -34,17 +34,17 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.world.World; -public class PatternArg extends SimpleCommand { +public class PatternParser extends SimpleCommand { - private final StringArg stringArg; + private final StringParser stringParser; - public PatternArg(String name) { - stringArg = addParameter(new StringArg(name, "The pattern")); + public PatternParser(String name) { + stringParser = addParameter(new StringParser(name, "The pattern")); } @Override public Pattern call(CommandArgs args, CommandLocals locals) throws CommandException { - String patternString = stringArg.call(args, locals); + String patternString = stringParser.call(args, locals); Actor actor = locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryParser.java similarity index 97% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryParser.java index 3b73142cf..25493f363 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryParser.java @@ -33,7 +33,7 @@ import com.sk89q.worldedit.util.command.composition.CommandExecutor; import java.util.List; -public class RegionFactoryArg implements CommandExecutor { +public class RegionFactoryParser implements CommandExecutor { @Override public RegionFactory call(CommandArgs args, CommandLocals locals) throws CommandException { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PointGeneratorArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFunctionParser.java similarity index 70% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PointGeneratorArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFunctionParser.java index f7057595b..be96b19bb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PointGeneratorArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFunctionParser.java @@ -19,22 +19,22 @@ package com.sk89q.worldedit.command.argument; -import com.google.common.base.Function; -import com.sk89q.worldedit.function.EditContext; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.util.command.composition.BranchingCommand; -public class PointGeneratorArg extends BranchingCommand> { +public class RegionFunctionParser extends BranchingCommand> { - public PointGeneratorArg() { - super("generatorType"); - putOption(new TreeGeneratorArg("treeType"), "tree", "forest"); - putOption(new ItemUserArg(), "item", "itemstack", "use"); + public RegionFunctionParser() { + super("functionTpe"); + putOption(new TreeGeneratorParser("treeType"), "forest"); + putOption(new ItemUseParser(), "item"); + putOption(new ReplaceParser(), "set"); } @Override public String getDescription() { - return "Choose a point generator function"; + return "Choose a block function"; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionReplaceArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionReplaceArg.java deleted file mode 100644 index 793e0d8ba..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionReplaceArg.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.command.argument; - -import com.sk89q.minecraft.util.commands.CommandException; -import com.sk89q.minecraft.util.commands.CommandLocals; -import com.sk89q.worldedit.function.factory.RegionReplace; -import com.sk89q.worldedit.util.command.argument.MissingArgumentException; -import com.sk89q.worldedit.util.command.composition.CommandExecutor; -import com.sk89q.worldedit.util.command.argument.CommandArgs; - -import java.util.Collections; -import java.util.List; - -public class RegionReplaceArg implements CommandExecutor { - - @Override - public RegionReplace call(CommandArgs args, CommandLocals locals) throws CommandException { - return new RegionReplace(); - } - - @Override - public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException { - return Collections.emptyList(); - } - - @Override - public String getUsage() { - return ""; - } - - @Override - public String getDescription() { - return "Replaces a region"; - } - - @Override - public boolean testPermission(CommandLocals locals) { - return true; - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ReplaceParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ReplaceParser.java new file mode 100644 index 000000000..b6834945d --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ReplaceParser.java @@ -0,0 +1,75 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.command.argument; + +import com.sk89q.minecraft.util.commands.CommandException; +import com.sk89q.minecraft.util.commands.CommandLocals; +import com.sk89q.worldedit.extent.NullExtent; +import com.sk89q.worldedit.function.Contextual; +import com.sk89q.worldedit.function.EditContext; +import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.function.block.BlockReplace; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.util.command.argument.CommandArgs; +import com.sk89q.worldedit.util.command.composition.SimpleCommand; + +import static com.google.common.base.MoreObjects.firstNonNull; + +public class ReplaceParser extends SimpleCommand> { + + private final PatternParser fillArg = addParameter(new PatternParser("fillPattern")); + + @Override + public Contextual call(CommandArgs args, CommandLocals locals) throws CommandException { + Pattern fill = fillArg.call(args, locals); + return new ReplaceFactory(fill); + } + + @Override + public String getDescription() { + return "Replaces blocks"; + } + + @Override + protected boolean testPermission0(CommandLocals locals) { + return true; + } + + private static class ReplaceFactory implements Contextual { + private final Pattern fill; + + private ReplaceFactory(Pattern fill) { + this.fill = fill; + } + + @Override + public RegionFunction createFromContext(EditContext context) { + return new BlockReplace( + firstNonNull(context.getDestination(), new NullExtent()), + firstNonNull(context.getFill(), fill)); + } + + @Override + public String toString() { + return "replace blocks"; + } + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringParser.java similarity index 92% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringParser.java index 5f76f5bb2..518024cd3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/StringParser.java @@ -29,17 +29,17 @@ import com.sk89q.worldedit.util.command.composition.CommandExecutor; import java.util.Collections; import java.util.List; -public class StringArg implements CommandExecutor { +public class StringParser implements CommandExecutor { private final String name; private final String description; private final String defaultSuggestion; - public StringArg(String name, String description) { + public StringParser(String name, String description) { this(name, description, null); } - public StringArg(String name, String description, String defaultSuggestion) { + public StringParser(String name, String description, String defaultSuggestion) { this.name = name; this.description = description; this.defaultSuggestion = defaultSuggestion; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorParser.java similarity index 86% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorParser.java index 091364d0a..34b782af7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/TreeGeneratorParser.java @@ -19,12 +19,12 @@ package com.sk89q.worldedit.command.argument; -import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.collect.Lists; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.generator.ForestGenerator; import com.sk89q.worldedit.util.TreeGenerator; @@ -34,15 +34,14 @@ import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.util.command.argument.MissingArgumentException; import com.sk89q.worldedit.util.command.composition.CommandExecutor; -import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; -public class TreeGeneratorArg implements CommandExecutor> { +public class TreeGeneratorParser implements CommandExecutor> { private final String name; - public TreeGeneratorArg(String name) { + public TreeGeneratorParser(String name) { this.name = name; } @@ -51,7 +50,7 @@ public class TreeGeneratorArg implements CommandExecutor call(CommandArgs args, CommandLocals locals) throws CommandException { + public Contextual call(CommandArgs args, CommandLocals locals) throws CommandException { try { String input = args.next(); TreeType type = TreeGenerator.lookup(input); @@ -86,16 +85,15 @@ public class TreeGeneratorArg implements CommandExecutor { + private static final class GeneratorFactory implements Contextual { private final TreeType type; private GeneratorFactory(TreeType type) { this.type = type; } - @Nullable @Override - public ForestGenerator apply(EditContext input) { + public ForestGenerator createFromContext(EditContext input) { return new ForestGenerator((EditSession) input.getDestination(), new TreeGenerator(type)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ApplyCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ApplyCommand.java index 905c3e0d6..50c0710ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ApplyCommand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ApplyCommand.java @@ -19,29 +19,45 @@ package com.sk89q.worldedit.command.composition; -import com.google.common.base.Function; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; -import com.sk89q.worldedit.command.argument.PointGeneratorArg; -import com.sk89q.worldedit.function.EditContext; +import com.sk89q.worldedit.command.argument.RegionFunctionParser; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.RegionFunction; -import com.sk89q.worldedit.function.factory.RegionApply; +import com.sk89q.worldedit.function.factory.Apply; +import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.util.command.argument.CommandArgs; +import com.sk89q.worldedit.util.command.composition.CommandExecutor; import com.sk89q.worldedit.util.command.composition.SimpleCommand; -public class ApplyCommand extends SimpleCommand { +import static com.google.common.base.Preconditions.checkNotNull; - private final PointGeneratorArg pointGeneratorArg = addParameter(new PointGeneratorArg()); +public class ApplyCommand extends SimpleCommand> { + + private final CommandExecutor> functionParser; + private final String description; + + public ApplyCommand() { + this(new RegionFunctionParser(), "Applies a function to every block"); + } + + public ApplyCommand(CommandExecutor> functionParser, String description) { + checkNotNull(functionParser, "functionParser"); + checkNotNull(description, "description"); + this.functionParser = functionParser; + this.description = description; + addParameter(functionParser); + } @Override - public RegionApply call(CommandArgs args, CommandLocals locals) throws CommandException { - Function function = pointGeneratorArg.call(args, locals); - return new RegionApply(function); + public Apply call(CommandArgs args, CommandLocals locals) throws CommandException { + Contextual function = functionParser.call(args, locals); + return new Apply(function); } @Override public String getDescription() { - return "Applies a point generator to an area"; + return description; } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/DeformArg.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java similarity index 84% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/DeformArg.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java index e6b7c7cdf..3bcb8a063 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/DeformArg.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.command.argument; +package com.sk89q.worldedit.command.composition; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; @@ -25,20 +25,24 @@ import com.sk89q.minecraft.util.commands.WrappedCommandException; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.command.argument.BooleanFlag; +import com.sk89q.worldedit.command.argument.StringParser; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.factory.Deform; import com.sk89q.worldedit.function.factory.Deform.Mode; +import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.util.command.composition.FlagParser.Flag; import com.sk89q.worldedit.util.command.composition.FlagParser.FlagData; import com.sk89q.worldedit.util.command.composition.SimpleCommand; -public class DeformArg extends SimpleCommand { +public class DeformCommand extends SimpleCommand> { private final Flag rawCoordsFlag = addFlag('r', new BooleanFlag("Raw coords mode")); private final Flag offsetFlag = addFlag('o', new BooleanFlag("Offset mode")); - private final StringArg expressionParser = addParameter(new StringArg("expression", "Expression to apply", "y-=0.2")); + private final StringParser expressionParser = addParameter(new StringParser("expression", "Expression to apply", "y-=0.2")); @Override public Deform call(CommandArgs args, CommandLocals locals) throws CommandException { @@ -69,7 +73,7 @@ public class DeformArg extends SimpleCommand { @Override public String getDescription() { - return "Deforms an area by applying a math expression"; + return "Apply math expression to area"; } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ScatterCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PaintCommand.java similarity index 56% rename from worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ScatterCommand.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PaintCommand.java index a5667fe07..8ce3e004c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ScatterCommand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/PaintCommand.java @@ -19,32 +19,41 @@ package com.sk89q.worldedit.command.composition; -import com.google.common.base.Function; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; -import com.sk89q.worldedit.command.argument.NumberArg; -import com.sk89q.worldedit.command.argument.PointGeneratorArg; -import com.sk89q.worldedit.function.EditContext; +import com.sk89q.worldedit.command.argument.NumberParser; +import com.sk89q.worldedit.command.argument.RegionFunctionParser; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.RegionFunction; -import com.sk89q.worldedit.function.factory.Scatter; +import com.sk89q.worldedit.function.factory.Paint; import com.sk89q.worldedit.util.command.argument.CommandArgs; +import com.sk89q.worldedit.util.command.composition.CommandExecutor; import com.sk89q.worldedit.util.command.composition.SimpleCommand; -public class ScatterCommand extends SimpleCommand { +public class PaintCommand extends SimpleCommand { - private final NumberArg densityCommand = addParameter(new NumberArg("density", "0-100", "20")); - private final PointGeneratorArg pointGeneratorArg = addParameter(new PointGeneratorArg()); + private final NumberParser densityCommand = addParameter(new NumberParser("density", "0-100", "20")); + private final CommandExecutor> functionParser; + + public PaintCommand() { + this(new RegionFunctionParser()); + } + + public PaintCommand(CommandExecutor> functionParser) { + this.functionParser = functionParser; + addParameter(functionParser); + } @Override - public Scatter call(CommandArgs args, CommandLocals locals) throws CommandException { + public Paint call(CommandArgs args, CommandLocals locals) throws CommandException { double density = densityCommand.call(args, locals).doubleValue() / 100.0; - Function function = pointGeneratorArg.call(args, locals); - return new Scatter(function, density); + Contextual function = functionParser.call(args, locals); + return new Paint(function, density); } @Override public String getDescription() { - return "Scatters a function over an area"; + return "Applies a function to surfaces"; } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ReplaceBrushCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ReplaceBrushCommand.java deleted file mode 100644 index 7a583da0a..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ReplaceBrushCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.command.composition; - -import com.sk89q.minecraft.util.commands.CommandException; -import com.sk89q.minecraft.util.commands.CommandLocals; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.command.argument.PatternArg; -import com.sk89q.worldedit.command.tool.BrushTool; -import com.sk89q.worldedit.command.tool.InvalidToolBindException; -import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.function.pattern.Pattern; -import com.sk89q.worldedit.util.command.composition.CommandExecutor; -import com.sk89q.worldedit.util.command.argument.CommandArgs; -import com.sk89q.worldedit.util.command.composition.SimpleCommand; - -import static com.google.common.base.Preconditions.checkNotNull; - -public class ReplaceBrushCommand extends SimpleCommand { - - private final PatternArg patternArg = addParameter(new PatternArg("fillPattern")); - private final CommandExecutor delegate; - - public ReplaceBrushCommand(CommandExecutor delegate) { - checkNotNull(delegate, "delegate"); - this.delegate = addParameter(delegate); - } - - @Override - public T call(CommandArgs args, CommandLocals locals) throws CommandException { - Pattern pattern = patternArg.call(args, locals); - - Player player = (Player) locals.get(Actor.class); - LocalSession session = WorldEdit.getInstance().getSessionManager().get(player); - - try { - BrushTool tool = session.getBrushTool(player.getItemInHand()); - tool.setFill(pattern); - } catch (InvalidToolBindException e) { - WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e); - } - - return delegate.call(args, locals); - } - - @Override - public String getDescription() { - return "Replaces an area with a pattern"; - } - - @Override - protected boolean testPermission0(CommandLocals locals) { - return true; - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java new file mode 100644 index 000000000..4206d6947 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java @@ -0,0 +1,114 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.command.composition; + +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; +import com.sk89q.minecraft.util.commands.CommandException; +import com.sk89q.minecraft.util.commands.CommandLocals; +import com.sk89q.minecraft.util.commands.CommandPermissionsException; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.function.Contextual; +import com.sk89q.worldedit.function.EditContext; +import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.util.command.argument.CommandArgs; +import com.sk89q.worldedit.util.command.composition.CommandExecutor; +import com.sk89q.worldedit.util.command.composition.SimpleCommand; + +import java.util.List; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class SelectionCommand extends SimpleCommand { + + private final CommandExecutor> delegate; + private final String permission; + + public SelectionCommand(CommandExecutor> delegate, String permission) { + checkNotNull(delegate, "delegate"); + checkNotNull(permission, "permission"); + this.delegate = delegate; + this.permission = permission; + addParameter(delegate); + } + + @Override + public Operation call(CommandArgs args, CommandLocals locals) throws CommandException { + if (!testPermission(locals)) { + throw new CommandPermissionsException(); + } + + Contextual operationFactory = delegate.call(args, locals); + + Actor actor = locals.get(Actor.class); + if (actor instanceof Player) { + try { + Player player = (Player) actor; + LocalSession session = WorldEdit.getInstance().getSessionManager().get(player); + Region selection = session.getSelection(player.getWorld()); + + EditSession editSession = session.createEditSession(player); + editSession.enableQueue(); + locals.put(EditSession.class, editSession); + session.tellVersion(player); + + EditContext editContext = new EditContext(); + editContext.setDestination(locals.get(EditSession.class)); + editContext.setRegion(selection); + + Operation operation = operationFactory.createFromContext(editContext); + Operations.completeBlindly(operation); + + List messages = Lists.newArrayList(); + operation.addStatusMessages(messages); + if (messages.isEmpty()) { + actor.print("Operation completed."); + } else { + actor.print("Operation completed (" + Joiner.on(", ").join(messages) + ")."); + } + + return operation; + } catch (IncompleteRegionException e) { + WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e); + return null; + } + } else { + throw new CommandException("This command can only be used by players."); + } + } + + @Override + public String getDescription() { + return delegate.getDescription(); + } + + @Override + protected boolean testPermission0(CommandLocals locals) { + return locals.get(Actor.class).hasPermission(permission); + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java index f99e4e543..faeb30928 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java @@ -25,30 +25,31 @@ import com.sk89q.minecraft.util.commands.CommandPermissionsException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxBrushRadiusException; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.command.argument.NumberArg; -import com.sk89q.worldedit.command.argument.RegionFactoryArg; +import com.sk89q.worldedit.command.argument.NumberParser; +import com.sk89q.worldedit.command.argument.RegionFactoryParser; import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.InvalidToolBindException; import com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.function.factory.OperationFactory; +import com.sk89q.worldedit.function.Contextual; +import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.regions.factory.RegionFactory; -import com.sk89q.worldedit.util.command.composition.CommandExecutor; import com.sk89q.worldedit.util.command.argument.CommandArgs; +import com.sk89q.worldedit.util.command.composition.CommandExecutor; import com.sk89q.worldedit.util.command.composition.SimpleCommand; import static com.google.common.base.Preconditions.checkNotNull; public class ShapedBrushCommand extends SimpleCommand { - private final CommandExecutor delegate; + private final CommandExecutor> delegate; private final String permission; - private final RegionFactoryArg regionFactoryArg = addParameter(new RegionFactoryArg()); - private final NumberArg radiusCommand = addParameter(new NumberArg("size", "The size of the brush", "5")); + private final RegionFactoryParser regionFactoryParser = addParameter(new RegionFactoryParser()); + private final NumberParser radiusCommand = addParameter(new NumberParser("size", "The size of the brush", "5")); - public ShapedBrushCommand(CommandExecutor delegate, String permission) { + public ShapedBrushCommand(CommandExecutor> delegate, String permission) { checkNotNull(delegate, "delegate"); this.permission = permission; this.delegate = delegate; @@ -61,9 +62,9 @@ public class ShapedBrushCommand extends SimpleCommand { throw new CommandPermissionsException(); } - RegionFactory regionFactory = regionFactoryArg.call(args, locals); + RegionFactory regionFactory = regionFactoryParser.call(args, locals); int radius = radiusCommand.call(args, locals).intValue(); - OperationFactory factory = delegate.call(args, locals); + Contextual factory = delegate.call(args, locals); Player player = (Player) locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(player); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java index 8bc61b488..2e7fbc24a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java @@ -19,9 +19,11 @@ package com.sk89q.worldedit.command.tool; -import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.command.tool.brush.SphereBrush; import com.sk89q.worldedit.entity.Player; @@ -30,10 +32,11 @@ import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.MaskIntersection; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.session.request.Request; +import javax.annotation.Nullable; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -45,7 +48,8 @@ public class BrushTool implements TraceTool { protected int range = -1; private Mask mask = null; private Brush brush = new SphereBrush(); - private Pattern material = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE)); + @Nullable + private Pattern material; private double size = 1; private String permission; @@ -107,16 +111,16 @@ public class BrushTool implements TraceTool { * * @param material the material */ - public void setFill(Pattern material) { + public void setFill(@Nullable Pattern material) { this.material = material; } /** * Get the material. - * + * * @return the material */ - public Pattern getMaterial() { + @Nullable public Pattern getMaterial() { return material; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java index 31b8c9ab7..2df64da79 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java @@ -22,6 +22,9 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Patterns; @@ -35,6 +38,9 @@ public class CylinderBrush implements Brush { @Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + if (pattern == null) { + pattern = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE)); + } editSession.makeCylinder(position, Patterns.wrap(pattern), size, size, height, true); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java index 236e875c6..0f468d666 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java @@ -22,6 +22,9 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Patterns; @@ -35,6 +38,9 @@ public class HollowCylinderBrush implements Brush { @Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + if (pattern == null) { + pattern = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE)); + } editSession.makeCylinder(position, Patterns.wrap(pattern), size, size, height, false); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java index 8f1f6f3be..14813fd99 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java @@ -22,6 +22,9 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Patterns; @@ -29,6 +32,9 @@ public class HollowSphereBrush implements Brush { @Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + if (pattern == null) { + pattern = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE)); + } editSession.makeSphere(position, Patterns.wrap(pattern), size, size, size, false); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/OperationFactoryBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/OperationFactoryBrush.java index 3e84101be..f9a679d62 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/OperationFactoryBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/OperationFactoryBrush.java @@ -22,19 +22,19 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.operation.Operation; -import com.sk89q.worldedit.function.factory.OperationFactory; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.regions.factory.RegionFactory; public class OperationFactoryBrush implements Brush { - private final OperationFactory operationFactory; + private final Contextual operationFactory; private final RegionFactory regionFactory; - public OperationFactoryBrush(OperationFactory operationFactory, RegionFactory regionFactory) { + public OperationFactoryBrush(Contextual operationFactory, RegionFactory regionFactory) { this.operationFactory = operationFactory; this.regionFactory = regionFactory; } @@ -45,7 +45,7 @@ public class OperationFactoryBrush implements Brush { context.setDestination(editSession); context.setRegion(regionFactory.createCenteredAt(position, size)); context.setFill(pattern); - Operation operation = operationFactory.createOperation(context); + Operation operation = operationFactory.createFromContext(context); Operations.completeLegacy(operation); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java index 7df1fa599..6c783a0da 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java @@ -22,6 +22,9 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Patterns; @@ -29,6 +32,9 @@ public class SphereBrush implements Brush { @Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + if (pattern == null) { + pattern = new BlockPattern(new BaseBlock(BlockID.COBBLESTONE)); + } editSession.makeSphere(position, Patterns.wrap(pattern), size, size, size, true); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index 0218b4b76..54db48ef8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -47,17 +47,15 @@ import com.sk89q.worldedit.command.ToolCommands; import com.sk89q.worldedit.command.ToolUtilCommands; import com.sk89q.worldedit.command.UtilityCommands; import com.sk89q.worldedit.command.WorldEditCommands; -import com.sk89q.worldedit.command.argument.DeformArg; -import com.sk89q.worldedit.command.argument.RegionReplaceArg; +import com.sk89q.worldedit.command.argument.ReplaceParser; import com.sk89q.worldedit.command.composition.ApplyCommand; -import com.sk89q.worldedit.command.composition.ReplaceBrushCommand; -import com.sk89q.worldedit.command.composition.ScatterCommand; +import com.sk89q.worldedit.command.composition.DeformCommand; +import com.sk89q.worldedit.command.composition.PaintCommand; import com.sk89q.worldedit.command.composition.ShapedBrushCommand; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandSuggestionEvent; import com.sk89q.worldedit.function.factory.Deform; import com.sk89q.worldedit.function.factory.Deform.Mode; -import com.sk89q.worldedit.function.factory.OperationFactory; import com.sk89q.worldedit.internal.command.ActorAuthorizer; import com.sk89q.worldedit.internal.command.CommandLoggingHandler; import com.sk89q.worldedit.internal.command.UserCommandCompleter; @@ -165,12 +163,12 @@ public final class CommandManager { .group("brush", "br") .describeAs("Brushing commands") .registerMethods(new BrushCommands(worldEdit)) - .register(adapt(new ShapedBrushCommand(new DeformArg(), "worldedit.brush.deform")), "deform") + .register(adapt(new ShapedBrushCommand(new DeformCommand(), "worldedit.brush.deform")), "deform") + .register(adapt(new ShapedBrushCommand(new ApplyCommand(new ReplaceParser(), "Set all blocks within region"), "worldedit.brush.set")), "set") + .register(adapt(new ShapedBrushCommand(new PaintCommand(), "worldedit.brush.paint")), "paint") + .register(adapt(new ShapedBrushCommand(new ApplyCommand(), "worldedit.brush.apply")), "apply") .register(adapt(new ShapedBrushCommand(ProvidedValue.create(new Deform("y-=1", Mode.RAW_COORD), "Raise one block"), "worldedit.brush.raise")), "raise") .register(adapt(new ShapedBrushCommand(ProvidedValue.create(new Deform("y+=1", Mode.RAW_COORD), "Lower one block"), "worldedit.brush.lower")), "lower") - .register(adapt(new ShapedBrushCommand(new ReplaceBrushCommand(new RegionReplaceArg()), "worldedit.brush.set")), "set") - .register(adapt(new ShapedBrushCommand(new ScatterCommand(), "worldedit.brush.scatter")), "scatter") - .register(adapt(new ShapedBrushCommand(new ApplyCommand(), "worldedit.brush.apply")), "apply") .parent() .group("superpickaxe", "pickaxe", "sp") .describeAs("Super-pickaxe commands") diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index 0f1b3fda0..92ed45c30 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -213,6 +213,10 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder public void cancel() { } + @Override + public void addStatusMessages(List messages) { + } + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java index ea9161fea..42306a99d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java @@ -29,6 +29,7 @@ import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.world.World; import java.util.HashSet; +import java.util.List; import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; @@ -106,6 +107,10 @@ public class FastModeExtent extends AbstractDelegateExtent { @Override public void cancel() { } + + @Override + public void addStatusMessages(List messages) { + } }; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/OperationFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/Contextual.java similarity index 77% rename from worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/OperationFactory.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/function/Contextual.java index 364376321..83cda9eef 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/OperationFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/Contextual.java @@ -17,13 +17,10 @@ * along with this program. If not, see . */ -package com.sk89q.worldedit.function.factory; +package com.sk89q.worldedit.function; -import com.sk89q.worldedit.function.EditContext; -import com.sk89q.worldedit.function.operation.Operation; +public interface Contextual { -public interface OperationFactory { - - Operation createOperation(EditContext context); + T createFromContext(EditContext context); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/EditContext.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/EditContext.java index a4683654c..d9ee8c917 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/EditContext.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/EditContext.java @@ -19,43 +19,44 @@ package com.sk89q.worldedit.function; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.NullExtent; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; -import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkNotNull; + public class EditContext { - private Extent destination = new NullExtent(); - private Region region = new CuboidRegion(Vector.ZERO, Vector.ZERO); - private Pattern fill = new BlockPattern(new BaseBlock(BlockID.AIR)); + private Extent destination; + @Nullable private Region region; + @Nullable private Pattern fill; public Extent getDestination() { return destination; } public void setDestination(Extent destination) { + checkNotNull(destination, "destination"); this.destination = destination; } + @Nullable public Region getRegion() { return region; } - public void setRegion(Region region) { + public void setRegion(@Nullable Region region) { this.region = region; } + @Nullable public Pattern getFill() { return fill; } - public void setFill(Pattern fill) { + public void setFill(@Nullable Pattern fill) { this.fill = fill; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/RegionApply.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Apply.java similarity index 57% rename from worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/RegionApply.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Apply.java index abed33419..01c26d522 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/RegionApply.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Apply.java @@ -19,31 +19,41 @@ package com.sk89q.worldedit.function.factory; -import com.google.common.base.Function; +import com.google.common.base.MoreObjects; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.visitor.RegionVisitor; +import com.sk89q.worldedit.regions.NullRegion; +import com.sk89q.worldedit.regions.Region; import static com.google.common.base.Preconditions.checkNotNull; -public class RegionApply implements OperationFactory { +public class Apply implements Contextual { - private final Function regionFunctionFactory; + private final Region region; + private final Contextual function; - public RegionApply(Function regionFunctionFactory) { - checkNotNull(regionFunctionFactory, "regionFunctionFactory"); - this.regionFunctionFactory = regionFunctionFactory; + public Apply(Contextual function) { + this(new NullRegion(), function); + } + + public Apply(Region region, Contextual function) { + checkNotNull(region, "region"); + checkNotNull(function, "function"); + this.region = region; + this.function = function; } @Override - public Operation createOperation(EditContext context) { - return new RegionVisitor(context.getRegion(), regionFunctionFactory.apply(context)); + public Operation createFromContext(EditContext context) { + return new RegionVisitor(MoreObjects.firstNonNull(context.getRegion(), region), function.createFromContext(context)); } @Override public String toString() { - return "set " + regionFunctionFactory; + return "set " + function; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index f1c35c318..51e840ee5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -19,37 +19,73 @@ package com.sk89q.worldedit.function.factory; -import com.google.common.base.Preconditions; +import com.google.common.base.MoreObjects; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.NullExtent; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.internal.expression.ExpressionException; +import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.Region; +import java.util.List; + import static com.google.common.base.Preconditions.checkNotNull; -public class Deform implements OperationFactory { +public class Deform implements Contextual { + private Extent destination; + private Region region; private String expression; private Mode mode = Mode.UNIT_CUBE; private Vector offset = new Vector(); public Deform(String expression) { - checkNotNull(expression, "expression"); - this.expression = expression; + this(new NullExtent(), new NullRegion(), expression); } public Deform(String expression, Mode mode) { + this(new NullExtent(), new NullRegion(), expression, mode); + } + + public Deform(Extent destination, Region region, String expression) { + this(destination, region, expression, Mode.UNIT_CUBE); + } + + public Deform(Extent destination, Region region, String expression, Mode mode) { + checkNotNull(destination, "destination"); + checkNotNull(region, "region"); checkNotNull(expression, "expression"); checkNotNull(mode, "mode"); + this.destination = destination; + this.region = region; this.expression = expression; this.mode = mode; } + public Extent getDestination() { + return destination; + } + + public void setDestination(Extent destination) { + checkNotNull(destination, "destination"); + this.destination = destination; + } + + public Region getRegion() { + return region; + } + + public void setRegion(Region region) { + checkNotNull(region, "region"); + this.region = region; + } + public String getExpression() { return expression; } @@ -83,14 +119,16 @@ public class Deform implements OperationFactory { } @Override - public Operation createOperation(final EditContext context) { + public Operation createFromContext(final EditContext context) { final Vector zero; Vector unit; + Region region = MoreObjects.firstNonNull(context.getRegion(), this.region); + switch (mode) { case UNIT_CUBE: - final Vector min = context.getRegion().getMinimumPoint(); - final Vector max = context.getRegion().getMaximumPoint(); + final Vector min = region.getMinimumPoint(); + final Vector max = region.getMaximumPoint(); zero = max.add(min).multiply(0.5); unit = max.subtract(zero); @@ -109,7 +147,7 @@ public class Deform implements OperationFactory { unit = Vector.ONE; } - return new DeformOperation(context.getDestination(), context.getRegion(), zero, unit, expression); + return new DeformOperation(context.getDestination(), region, zero, unit, expression); } private static final class DeformOperation implements Operation { @@ -141,6 +179,12 @@ public class Deform implements OperationFactory { @Override public void cancel() { } + + @Override + public void addStatusMessages(List messages) { + messages.add("deformed using " + expression); + } + } public enum Mode { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Scatter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Paint.java similarity index 57% rename from worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Scatter.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Paint.java index 1c75d1bce..77421b56c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Scatter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Paint.java @@ -19,7 +19,10 @@ package com.sk89q.worldedit.function.factory; -import com.google.common.base.Function; +import com.google.common.base.MoreObjects; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.NullExtent; +import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.RegionFunction; @@ -28,25 +31,41 @@ import com.sk89q.worldedit.function.mask.NoiseFilter2D; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.visitor.LayerVisitor; import com.sk89q.worldedit.math.noise.RandomNoise; +import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.Region; +import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.regions.Regions.*; -public class Scatter implements OperationFactory { +public class Paint implements Contextual { - private final Function regionFunctionFactory; + private final Extent destination; + private final Region region; + private final Contextual function; private final double density; - public Scatter(Function regionFunctionFactory, double density) { - this.regionFunctionFactory = regionFunctionFactory; + public Paint(Contextual function, double density) { + this(new NullExtent(), new NullRegion(), function, density); + } + + public Paint(Extent destination, Region region, Contextual function, + double density) { + checkNotNull(destination, "destination"); + checkNotNull(region, "region"); + checkNotNull(function, "function"); + checkNotNull(density, "density"); + this.destination = destination; + this.region = region; + this.function = function; this.density = density; - new NoiseFilter2D(new RandomNoise(), density); // Check validity density argument + new NoiseFilter2D(new RandomNoise(), density); // Check validity of the density argument } @Override - public Operation createOperation(EditContext context) { - Region region = context.getRegion(); - GroundFunction ground = new GroundFunction(new ExistingBlockMask(context.getDestination()), regionFunctionFactory.apply(context)); + public Operation createFromContext(EditContext context) { + Extent destination = MoreObjects.firstNonNull(context.getDestination(), this.destination); + Region region = MoreObjects.firstNonNull(context.getRegion(), this.region); + GroundFunction ground = new GroundFunction(new ExistingBlockMask(destination), function.createFromContext(context)); LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground); visitor.setMask(new NoiseFilter2D(new RandomNoise(), density)); return visitor; @@ -54,7 +73,7 @@ public class Scatter implements OperationFactory { @Override public String toString() { - return "scatter " + regionFunctionFactory; + return "scatter " + function; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/RegionReplace.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/RegionReplace.java deleted file mode 100644 index 4ab11320f..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/RegionReplace.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.function.factory; - -import com.sk89q.worldedit.function.EditContext; -import com.sk89q.worldedit.function.block.BlockReplace; -import com.sk89q.worldedit.function.operation.Operation; -import com.sk89q.worldedit.function.visitor.RegionVisitor; - -public class RegionReplace implements OperationFactory { - - @Override - public Operation createOperation(EditContext context) { - BlockReplace replace = new BlockReplace(context.getDestination(), context.getFill()); - return new RegionVisitor(context.getRegion(), replace); - } - - @Override - public String toString() { - return "set blocks"; - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/BlockMapEntryPlacer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/BlockMapEntryPlacer.java index ada3d6231..a12850c10 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/BlockMapEntryPlacer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/BlockMapEntryPlacer.java @@ -25,6 +25,7 @@ import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extent.Extent; import java.util.Iterator; +import java.util.List; import java.util.Map; import static com.google.common.base.Preconditions.checkNotNull; @@ -64,4 +65,9 @@ public class BlockMapEntryPlacer implements Operation { @Override public void cancel() { } + + @Override + public void addStatusMessages(List messages) { + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ChangeSetExecutor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ChangeSetExecutor.java index 3e186e6e4..93c0348e2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ChangeSetExecutor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ChangeSetExecutor.java @@ -25,6 +25,7 @@ import com.sk89q.worldedit.history.changeset.ChangeSet; import com.sk89q.worldedit.history.UndoContext; import java.util.Iterator; +import java.util.List; import static com.google.common.base.Preconditions.checkNotNull; @@ -79,6 +80,10 @@ public class ChangeSetExecutor implements Operation { public void cancel() { } + @Override + public void addStatusMessages(List messages) { + } + /** * Create a new undo operation. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/DelegateOperation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/DelegateOperation.java index d91d6a9aa..509b103c1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/DelegateOperation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/DelegateOperation.java @@ -21,6 +21,8 @@ package com.sk89q.worldedit.function.operation; import com.sk89q.worldedit.WorldEditException; +import java.util.List; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -57,4 +59,10 @@ public class DelegateOperation implements Operation { original.cancel(); } + @Override + public void addStatusMessages(List messages) { + original.addStatusMessages(messages); + delegate.addStatusMessages(messages); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 06da47e6b..b1fafe611 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -246,4 +246,8 @@ public class ForwardExtentCopy implements Operation { public void cancel() { } + @Override + public void addStatusMessages(List messages) { + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java index 2b87cba92..a69653151 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java @@ -21,6 +21,8 @@ package com.sk89q.worldedit.function.operation; import com.sk89q.worldedit.WorldEditException; +import java.util.List; + /** * An task that may be split into multiple steps to be run sequentially * immediately or at a varying or fixed interval. Operations should attempt @@ -49,4 +51,12 @@ public interface Operation { */ void cancel(); + /** + * Add messages to the provided list that describe the current status + * of the operation. + * + * @param messages The list to add messages to + */ + void addStatusMessages(List messages); + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java index 895195c2f..49aa9d637 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java @@ -19,11 +19,13 @@ package com.sk89q.worldedit.function.operation; +import com.google.common.collect.Lists; import com.sk89q.worldedit.WorldEditException; import java.util.ArrayDeque; import java.util.Collection; import java.util.Deque; +import java.util.List; import static com.google.common.base.Preconditions.checkNotNull; @@ -32,6 +34,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class OperationQueue implements Operation { + private final List operations = Lists.newArrayList(); private final Deque queue = new ArrayDeque(); private Operation current; @@ -51,6 +54,7 @@ public class OperationQueue implements Operation { for (Operation operation : operations) { offer(operation); } + this.operations.addAll(operations); } /** @@ -100,4 +104,11 @@ public class OperationQueue implements Operation { queue.clear(); } + @Override + public void addStatusMessages(List messages) { + for (Operation operation : operations) { + operation.addStatusMessages(messages); + } + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 5f1121eb2..b935e0cf6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -176,4 +176,9 @@ public abstract class BreadthFirstSearch implements Operation { public void cancel() { } -} \ No newline at end of file + @Override + public void addStatusMessages(List messages) { + messages.add(getAffected() + " blocks affected"); + } + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java index d412103e9..b4c301ae4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import java.util.Iterator; +import java.util.List; import static com.google.common.base.Preconditions.checkNotNull; @@ -75,4 +76,9 @@ public class EntityVisitor implements Operation { public void cancel() { } + @Override + public void addStatusMessages(List messages) { + messages.add(getAffected() + " entities affected"); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java index 331cccaff..23dd74e4e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java @@ -26,6 +26,8 @@ import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.regions.FlatRegion; +import java.util.List; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -75,5 +77,10 @@ public class FlatRegionVisitor implements Operation { public void cancel() { } + @Override + public void addStatusMessages(List messages) { + messages.add(getAffected() + " columns affected"); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java index 93b03c60e..f128b1301 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java @@ -29,6 +29,8 @@ import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.regions.FlatRegion; +import java.util.List; + import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -125,4 +127,9 @@ public class LayerVisitor implements Operation { @Override public void cancel() { } + + @Override + public void addStatusMessages(List messages) { + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java index 47fd9e281..caec36d7d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java @@ -26,6 +26,8 @@ import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.regions.Region; +import java.util.List; + /** * Utility class to apply region functions to {@link com.sk89q.worldedit.regions.Region}. */ @@ -64,5 +66,10 @@ public class RegionVisitor implements Operation { public void cancel() { } + @Override + public void addStatusMessages(List messages) { + messages.add(getAffected() + " blocks affected"); + } + }