mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 19:36:41 +00:00
Reorganize and further unify the new commands.
This commit is contained in:
@ -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);
|
@ -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);
|
||||
}
|
@ -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;
|
@ -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);
|
@ -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 {
|
@ -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";
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
@ -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));
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user