Reorganize and further unify the new commands.

This commit is contained in:
Albert Pham 2015-10-29 13:05:04 -07:00
parent 25ad916611
commit fdfc3cdb33
42 changed files with 543 additions and 321 deletions

View File

@ -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<BaseItem> {
public class ItemParser extends SimpleCommand<BaseItem> {
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);

View File

@ -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<Contextual<RegionFunction>> {
public class ItemUserArg extends SimpleCommand<Function<EditContext, RegionFunction>> {
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<EditContext, RegionFunction> call(CommandArgs args, CommandLocals locals) throws CommandException {
BaseItem item = itemArg.call(args, locals);
public Contextual<RegionFunction> 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<Function<EditContext, RegionFunct
return true;
}
private static final class ItemUseFactory implements Function<EditContext, RegionFunction> {
private static final class ItemUseFactory implements Contextual<RegionFunction> {
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);
}

View File

@ -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<Number> {
public class NumberParser implements CommandExecutor<Number> {
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;

View File

@ -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<Pattern> {
public class PatternParser extends SimpleCommand<Pattern> {
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);

View File

@ -33,7 +33,7 @@ import com.sk89q.worldedit.util.command.composition.CommandExecutor;
import java.util.List;
public class RegionFactoryArg implements CommandExecutor<RegionFactory> {
public class RegionFactoryParser implements CommandExecutor<RegionFactory> {
@Override
public RegionFactory call(CommandArgs args, CommandLocals locals) throws CommandException {

View File

@ -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<Function<EditContext, ? extends RegionFunction>> {
public class RegionFunctionParser extends BranchingCommand<Contextual<? extends RegionFunction>> {
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";
}
}

View File

@ -1,59 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<RegionReplace> {
@Override
public RegionReplace call(CommandArgs args, CommandLocals locals) throws CommandException {
return new RegionReplace();
}
@Override
public List<String> 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;
}
}

View File

@ -0,0 +1,75 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<Contextual<? extends RegionFunction>> {
private final PatternParser fillArg = addParameter(new PatternParser("fillPattern"));
@Override
public Contextual<RegionFunction> 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<RegionFunction> {
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";
}
}
}

View File

@ -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<String> {
public class StringParser implements CommandExecutor<String> {
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;

View File

@ -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<Function<EditContext, ForestGenerator>> {
public class TreeGeneratorParser implements CommandExecutor<Contextual<ForestGenerator>> {
private final String name;
public TreeGeneratorArg(String name) {
public TreeGeneratorParser(String name) {
this.name = name;
}
@ -51,7 +50,7 @@ public class TreeGeneratorArg implements CommandExecutor<Function<EditContext, F
}
@Override
public Function<EditContext, ForestGenerator> call(CommandArgs args, CommandLocals locals) throws CommandException {
public Contextual<ForestGenerator> 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<Function<EditContext, F
return true;
}
private static class GeneratorFactory implements Function<EditContext, ForestGenerator> {
private static final class GeneratorFactory implements Contextual<ForestGenerator> {
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));
}

View File

@ -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<RegionApply> {
import static com.google.common.base.Preconditions.checkNotNull;
private final PointGeneratorArg pointGeneratorArg = addParameter(new PointGeneratorArg());
public class ApplyCommand extends SimpleCommand<Contextual<? extends Operation>> {
private final CommandExecutor<Contextual<? extends RegionFunction>> functionParser;
private final String description;
public ApplyCommand() {
this(new RegionFunctionParser(), "Applies a function to every block");
}
public ApplyCommand(CommandExecutor<Contextual<? extends RegionFunction>> 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<EditContext, ? extends RegionFunction> function = pointGeneratorArg.call(args, locals);
return new RegionApply(function);
public Apply call(CommandArgs args, CommandLocals locals) throws CommandException {
Contextual<? extends RegionFunction> function = functionParser.call(args, locals);
return new Apply(function);
}
@Override
public String getDescription() {
return "Applies a point generator to an area";
return description;
}
@Override

View File

@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<Deform> {
public class DeformCommand extends SimpleCommand<Contextual<? extends Operation>> {
private final Flag<Boolean> rawCoordsFlag = addFlag('r', new BooleanFlag("Raw coords mode"));
private final Flag<Boolean> 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<Deform> {
@Override
public String getDescription() {
return "Deforms an area by applying a math expression";
return "Apply math expression to area";
}
@Override

View File

@ -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<Scatter> {
public class PaintCommand extends SimpleCommand<Paint> {
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<? extends Contextual<? extends RegionFunction>> functionParser;
public PaintCommand() {
this(new RegionFunctionParser());
}
public PaintCommand(CommandExecutor<? extends Contextual<? extends RegionFunction>> 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<EditContext, ? extends RegionFunction> function = pointGeneratorArg.call(args, locals);
return new Scatter(function, density);
Contextual<? extends RegionFunction> 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

View File

@ -1,75 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<T> extends SimpleCommand<T> {
private final PatternArg patternArg = addParameter(new PatternArg("fillPattern"));
private final CommandExecutor<? extends T> delegate;
public ReplaceBrushCommand(CommandExecutor<? extends T> 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;
}
}

View File

@ -0,0 +1,114 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<Operation> {
private final CommandExecutor<Contextual<? extends Operation>> delegate;
private final String permission;
public SelectionCommand(CommandExecutor<Contextual<? extends Operation>> 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<? extends Operation> 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<String> 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);
}
}

View File

@ -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<Object> {
private final CommandExecutor<? extends OperationFactory> delegate;
private final CommandExecutor<? extends Contextual<? extends Operation>> 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<? extends OperationFactory> delegate, String permission) {
public ShapedBrushCommand(CommandExecutor<? extends Contextual<? extends Operation>> delegate, String permission) {
checkNotNull(delegate, "delegate");
this.permission = permission;
this.delegate = delegate;
@ -61,9 +62,9 @@ public class ShapedBrushCommand extends SimpleCommand<Object> {
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<? extends Operation> factory = delegate.call(args, locals);
Player player = (Player) locals.get(Actor.class);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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<? extends Operation> operationFactory;
private final RegionFactory regionFactory;
public OperationFactoryBrush(OperationFactory operationFactory, RegionFactory regionFactory) {
public OperationFactoryBrush(Contextual<? extends Operation> 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);
}

View File

@ -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);
}
}

View File

@ -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<OperationFactory>(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")

View File

@ -213,6 +213,10 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
public void cancel() {
}
@Override
public void addStatusMessages(List<String> messages) {
}
}
}

View File

@ -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<String> messages) {
}
};
}

View File

@ -17,13 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<T> {
public interface OperationFactory {
Operation createOperation(EditContext context);
T createFromContext(EditContext context);
}

View File

@ -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;
}

View File

@ -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<Operation> {
private final Function<EditContext, ? extends RegionFunction> regionFunctionFactory;
private final Region region;
private final Contextual<? extends RegionFunction> function;
public RegionApply(Function<EditContext, ? extends RegionFunction> regionFunctionFactory) {
checkNotNull(regionFunctionFactory, "regionFunctionFactory");
this.regionFunctionFactory = regionFunctionFactory;
public Apply(Contextual<? extends RegionFunction> function) {
this(new NullRegion(), function);
}
public Apply(Region region, Contextual<? extends RegionFunction> 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;
}
}

View File

@ -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<Operation> {
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<String> messages) {
messages.add("deformed using " + expression);
}
}
public enum Mode {

View File

@ -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<Operation> {
private final Function<EditContext, ? extends RegionFunction> regionFunctionFactory;
private final Extent destination;
private final Region region;
private final Contextual<? extends RegionFunction> function;
private final double density;
public Scatter(Function<EditContext, ? extends RegionFunction> regionFunctionFactory, double density) {
this.regionFunctionFactory = regionFunctionFactory;
public Paint(Contextual<? extends RegionFunction> function, double density) {
this(new NullExtent(), new NullRegion(), function, density);
}
public Paint(Extent destination, Region region, Contextual<? extends RegionFunction> 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;
}
}

View File

@ -1,40 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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";
}
}

View File

@ -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<String> messages) {
}
}

View File

@ -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<String> messages) {
}
/**
* Create a new undo operation.
*

View File

@ -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<String> messages) {
original.addStatusMessages(messages);
delegate.addStatusMessages(messages);
}
}

View File

@ -246,4 +246,8 @@ public class ForwardExtentCopy implements Operation {
public void cancel() {
}
@Override
public void addStatusMessages(List<String> messages) {
}
}

View File

@ -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<String> messages);
}

View File

@ -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<Operation> operations = Lists.newArrayList();
private final Deque<Operation> queue = new ArrayDeque<Operation>();
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<String> messages) {
for (Operation operation : operations) {
operation.addStatusMessages(messages);
}
}
}

View File

@ -176,4 +176,9 @@ public abstract class BreadthFirstSearch implements Operation {
public void cancel() {
}
}
@Override
public void addStatusMessages(List<String> messages) {
messages.add(getAffected() + " blocks affected");
}
}

View File

@ -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<String> messages) {
messages.add(getAffected() + " entities affected");
}
}

View File

@ -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<String> messages) {
messages.add(getAffected() + " columns affected");
}
}

View File

@ -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<String> messages) {
}
}

View File

@ -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<String> messages) {
messages.add(getAffected() + " blocks affected");
}
}