mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +00:00
Update new commands with suggestion and help support.
This commit is contained in:
@ -22,24 +22,39 @@ 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.function.RegionFunction;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.function.factory.RegionApply;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.ParameterCommand;
|
||||
|
||||
public class PointGeneratorCommand extends CommandExecutor<Function<EditContext, ? extends RegionFunction>> {
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ApplyCommand extends ParameterCommand<RegionApply> {
|
||||
|
||||
private final PointGeneratorArg pointGeneratorArg = addParameter(new PointGeneratorArg());
|
||||
|
||||
@Override
|
||||
public Function<EditContext, ? extends RegionFunction> call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
String type = args.next();
|
||||
public RegionApply call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
Function<EditContext, ? extends RegionFunction> function = pointGeneratorArg.call(args, locals);
|
||||
return new RegionApply(function);
|
||||
}
|
||||
|
||||
if (type.equalsIgnoreCase("forest") || type.equalsIgnoreCase("tree")) {
|
||||
return new TreeGeneratorCommand().call(args, locals, parentCommands);
|
||||
} else if (type.equalsIgnoreCase("item") || type.equalsIgnoreCase("itemstack")) {
|
||||
return new ItemUseCommand().call(args, locals, parentCommands);
|
||||
} else {
|
||||
throw new CommandException("Unknown type of generator: " + type);
|
||||
}
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Applies a point generator to an area";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testPermission0(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +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.minecraft.util.commands.WrappedCommandException;
|
||||
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.factory.Deform;
|
||||
import com.sk89q.worldedit.function.factory.Deform.Mode;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
|
||||
public class DeformCommand extends CommandExecutor<Deform> {
|
||||
|
||||
@Override
|
||||
public Deform call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
String expression = args.next();
|
||||
boolean rawCoords = args.containsFlag('r');
|
||||
boolean offset = args.containsFlag('o');
|
||||
|
||||
Deform deform = new Deform(expression);
|
||||
|
||||
if (rawCoords) {
|
||||
deform.setMode(Mode.RAW_COORD);
|
||||
} else if (offset) {
|
||||
deform.setMode(Mode.OFFSET);
|
||||
Player player = (Player) locals.get(Actor.class);
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(locals.get(Actor.class));
|
||||
try {
|
||||
deform.setOffset(session.getPlacementPosition(player));
|
||||
} catch (IncompleteRegionException e) {
|
||||
throw new WrappedCommandException(e);
|
||||
}
|
||||
} else {
|
||||
deform.setMode(Mode.UNIT_CUBE);
|
||||
}
|
||||
|
||||
return deform;
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +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;
|
||||
|
||||
public class ForestCommand {
|
||||
}
|
@ -1,63 +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.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
public class ItemCommand extends CommandExecutor<BaseItem> {
|
||||
|
||||
@Override
|
||||
public BaseItem call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
Actor actor = locals.get(Actor.class);
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(actor);
|
||||
if (actor instanceof Entity) {
|
||||
Extent extent = ((Entity) actor).getExtent();
|
||||
if (extent instanceof World) {
|
||||
parserContext.setWorld((World) extent);
|
||||
}
|
||||
}
|
||||
parserContext.setSession(session);
|
||||
|
||||
try {
|
||||
return WorldEdit.getInstance().getItemFactory().parseFromInput(args.next(), parserContext);
|
||||
} catch (NoMatchException e) {
|
||||
throw new CommandException(e.getMessage(), e);
|
||||
} catch (InputParseException e) {
|
||||
throw new CommandException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +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.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.EditContext;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemUseCommand extends CommandExecutor<Function<EditContext, RegionFunction>> {
|
||||
|
||||
@Override
|
||||
public Function<EditContext, RegionFunction> call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
BaseItem item = new ItemCommand().call(args, locals, parentCommands);
|
||||
return new ItemUseFactory(item);
|
||||
}
|
||||
|
||||
private static final class ItemUseFactory implements Function<EditContext, RegionFunction> {
|
||||
private final BaseItem item;
|
||||
|
||||
private ItemUseFactory(BaseItem item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RegionFunction apply(EditContext input) {
|
||||
World world = ((EditSession) input.getDestination()).getWorld();
|
||||
return new ItemUseFunction(world, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "application of the item " + item.getType() + ":" + item.getData();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ItemUseFunction implements RegionFunction {
|
||||
private final World world;
|
||||
private final BaseItem item;
|
||||
|
||||
private ItemUseFunction(World world, BaseItem item) {
|
||||
this.world = world;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Vector position) throws WorldEditException {
|
||||
return world.useItem(position, item, Direction.UP);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +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.entity.Entity;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
public class PatternCommand extends CommandExecutor<Pattern> {
|
||||
|
||||
@Override
|
||||
public Pattern call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
Actor actor = locals.get(Actor.class);
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(actor);
|
||||
if (actor instanceof Entity) {
|
||||
Extent extent = ((Entity) actor).getExtent();
|
||||
if (extent instanceof World) {
|
||||
parserContext.setWorld((World) extent);
|
||||
}
|
||||
}
|
||||
parserContext.setSession(session);
|
||||
|
||||
try {
|
||||
return WorldEdit.getInstance().getPatternFactory().parseFromInput(args.next(), parserContext);
|
||||
} catch (NoMatchException e) {
|
||||
throw new CommandException(e.getMessage(), e);
|
||||
} catch (InputParseException e) {
|
||||
throw new CommandException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +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.regions.factory.CuboidRegionFactory;
|
||||
import com.sk89q.worldedit.regions.factory.CylinderRegionFactory;
|
||||
import com.sk89q.worldedit.regions.factory.RegionFactory;
|
||||
import com.sk89q.worldedit.regions.factory.SphereRegionFactory;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
|
||||
public class RegionFactoryCommand extends CommandExecutor<RegionFactory> {
|
||||
|
||||
@Override
|
||||
public RegionFactory call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
String type = args.next();
|
||||
|
||||
if (type.equals("cuboid")) {
|
||||
return new CuboidRegionFactory();
|
||||
} else if (type.equals("sphere")) {
|
||||
return new SphereRegionFactory();
|
||||
} else if (type.equals("cyl") || type.equals("cylinder")) {
|
||||
return new CylinderRegionFactory(1); // TODO: Adjustable height
|
||||
} else {
|
||||
throw new CommandException("Unknown shape type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +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.function.factory.RegionReplace;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
|
||||
public class RegionReplaceCommand extends CommandExecutor<RegionReplace> {
|
||||
|
||||
@Override
|
||||
public RegionReplace call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
return new RegionReplace();
|
||||
}
|
||||
|
||||
}
|
@ -23,28 +23,31 @@ 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.CommandExecutor;
|
||||
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 FillBrushCommand<T> extends CommandExecutor<T> {
|
||||
public class ReplaceBrushCommand<T> extends SimpleCommand<T> {
|
||||
|
||||
private final PatternArg patternArg = addParameter(new PatternArg("fillPattern"));
|
||||
private final CommandExecutor<? extends T> delegate;
|
||||
|
||||
public FillBrushCommand(CommandExecutor<? extends T> delegate) {
|
||||
public ReplaceBrushCommand(CommandExecutor<? extends T> delegate) {
|
||||
checkNotNull(delegate, "delegate");
|
||||
this.delegate = delegate;
|
||||
this.delegate = addParameter(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
Pattern pattern = new PatternCommand().call(args, locals, parentCommands);
|
||||
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);
|
||||
@ -56,6 +59,17 @@ public class FillBrushCommand<T> extends CommandExecutor<T> {
|
||||
WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e);
|
||||
}
|
||||
|
||||
return delegate.call(args, locals, parentCommands);
|
||||
return delegate.call(args, locals);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Replaces an area with a pattern";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testPermission0(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -22,19 +22,34 @@ 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.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.factory.Scatter;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
||||
|
||||
public class ScatterCommand extends CommandExecutor<Scatter> {
|
||||
public class ScatterCommand extends SimpleCommand<Scatter> {
|
||||
|
||||
private final NumberArg densityCommand = addParameter(new NumberArg("density", "0-100", "20"));
|
||||
private final PointGeneratorArg pointGeneratorArg = addParameter(new PointGeneratorArg());
|
||||
|
||||
@Override
|
||||
public Scatter call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
double density = args.nextDouble() / 100.0;
|
||||
Function<EditContext, ? extends RegionFunction> function = new PointGeneratorCommand().call(args, locals, parentCommands);
|
||||
public Scatter 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Scatters a function over an area";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testPermission0(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,13 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.command.composition;
|
||||
|
||||
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.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.tool.BrushTool;
|
||||
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
|
||||
import com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush;
|
||||
@ -33,39 +34,36 @@ import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.factory.OperationFactory;
|
||||
import com.sk89q.worldedit.regions.factory.RegionFactory;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.Description;
|
||||
import com.sk89q.worldedit.util.command.Parameter;
|
||||
import com.sk89q.worldedit.util.command.SimpleDescription;
|
||||
import com.sk89q.worldedit.util.command.SimpleParameter;
|
||||
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
|
||||
import java.util.List;
|
||||
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class ShapedBrushCommand extends CommandExecutor<Object> {
|
||||
public class ShapedBrushCommand extends SimpleCommand<Object> {
|
||||
|
||||
private final CommandExecutor<? extends OperationFactory> 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"));
|
||||
|
||||
public ShapedBrushCommand(CommandExecutor<? extends OperationFactory> delegate, String permission) {
|
||||
checkNotNull(delegate, "delegate");
|
||||
this.permission = permission;
|
||||
this.delegate = delegate;
|
||||
addParameter(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
public Object call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
if (!testPermission(locals)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
RegionFactory regionFactory = new RegionFactoryCommand().call(args, locals, parentCommands);
|
||||
int radius = args.nextInt();
|
||||
OperationFactory factory = delegate.call(args, locals, parentCommands);
|
||||
|
||||
args.requireAllConsumed();
|
||||
RegionFactory regionFactory = regionFactoryArg.call(args, locals);
|
||||
int radius = radiusCommand.call(args, locals).intValue();
|
||||
OperationFactory factory = delegate.call(args, locals);
|
||||
|
||||
Player player = (Player) locals.get(Actor.class);
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);
|
||||
@ -87,22 +85,12 @@ public class ShapedBrushCommand extends CommandExecutor<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description getDescription() {
|
||||
List<Parameter> parameters = Lists.newArrayList();
|
||||
parameters.add(new SimpleParameter("radius"));
|
||||
parameters.add(new SimpleParameter("shape"));
|
||||
parameters.add(new SimpleParameter("...shapeArgs...").setOptional(true));
|
||||
parameters.add(new SimpleParameter("...brushArgs...").setOptional(true));
|
||||
|
||||
SimpleDescription desc = new SimpleDescription();
|
||||
desc.setDescription(delegate.getDescription().getDescription());
|
||||
desc.setHelp(delegate.getDescription().getHelp());
|
||||
desc.setPermissions(Lists.newArrayList(permission));
|
||||
return desc;
|
||||
public String getDescription() {
|
||||
return delegate.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
public boolean testPermission0(CommandLocals locals) {
|
||||
Actor sender = locals.get(Actor.class);
|
||||
if (sender == null) {
|
||||
throw new RuntimeException("Uh oh! No 'Actor' specified so that we can check permissions");
|
||||
|
@ -1,67 +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.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.function.EditContext;
|
||||
import com.sk89q.worldedit.function.generator.ForestGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.CommandExecutor;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TreeGeneratorCommand extends CommandExecutor<Function<EditContext, ForestGenerator>> {
|
||||
|
||||
@Override
|
||||
public Function<EditContext, ForestGenerator> call(CommandArgs args, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
String input = args.next();
|
||||
TreeType type = TreeGenerator.lookup(input);
|
||||
if (type != null) {
|
||||
return new GeneratorFactory(type);
|
||||
} else {
|
||||
throw new CommandException(String.format("Can't recognize tree type '%s' -- choose from: %s", input, Arrays.toString(TreeType.values())));
|
||||
}
|
||||
}
|
||||
|
||||
private static class GeneratorFactory implements Function<EditContext, ForestGenerator> {
|
||||
private final TreeType type;
|
||||
|
||||
private GeneratorFactory(TreeType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ForestGenerator apply(EditContext input) {
|
||||
return new ForestGenerator((EditSession) input.getDestination(), new TreeGenerator(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tree of type " + type;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user