2015-10-27 06:14:30 +00:00
|
|
|
/*
|
|
|
|
* 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.CommandPermissionsException;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.MaxBrushRadiusException;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
2015-10-29 20:05:04 +00:00
|
|
|
import com.sk89q.worldedit.command.argument.NumberParser;
|
|
|
|
import com.sk89q.worldedit.command.argument.RegionFactoryParser;
|
2015-10-27 06:14:30 +00:00
|
|
|
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;
|
2015-10-29 20:05:04 +00:00
|
|
|
import com.sk89q.worldedit.function.Contextual;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operation;
|
2015-10-27 06:14:30 +00:00
|
|
|
import com.sk89q.worldedit.regions.factory.RegionFactory;
|
|
|
|
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
2015-10-29 20:05:04 +00:00
|
|
|
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
2015-10-27 20:51:45 +00:00
|
|
|
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
2015-10-27 06:14:30 +00:00
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2015-10-27 20:51:45 +00:00
|
|
|
public class ShapedBrushCommand extends SimpleCommand<Object> {
|
2015-10-27 06:14:30 +00:00
|
|
|
|
2015-10-29 20:05:04 +00:00
|
|
|
private final CommandExecutor<? extends Contextual<? extends Operation>> delegate;
|
2015-10-27 06:14:30 +00:00
|
|
|
private final String permission;
|
|
|
|
|
2015-10-29 20:05:04 +00:00
|
|
|
private final RegionFactoryParser regionFactoryParser = addParameter(new RegionFactoryParser());
|
|
|
|
private final NumberParser radiusCommand = addParameter(new NumberParser("size", "The size of the brush", "5"));
|
2015-10-27 20:51:45 +00:00
|
|
|
|
2015-10-29 20:05:04 +00:00
|
|
|
public ShapedBrushCommand(CommandExecutor<? extends Contextual<? extends Operation>> delegate, String permission) {
|
2015-10-27 06:14:30 +00:00
|
|
|
checkNotNull(delegate, "delegate");
|
|
|
|
this.permission = permission;
|
|
|
|
this.delegate = delegate;
|
2015-10-27 20:51:45 +00:00
|
|
|
addParameter(delegate);
|
2015-10-27 06:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-27 20:51:45 +00:00
|
|
|
public Object call(CommandArgs args, CommandLocals locals) throws CommandException {
|
2015-10-27 06:14:30 +00:00
|
|
|
if (!testPermission(locals)) {
|
|
|
|
throw new CommandPermissionsException();
|
|
|
|
}
|
|
|
|
|
2015-10-29 20:05:04 +00:00
|
|
|
RegionFactory regionFactory = regionFactoryParser.call(args, locals);
|
2015-10-27 20:51:45 +00:00
|
|
|
int radius = radiusCommand.call(args, locals).intValue();
|
2015-10-29 20:05:04 +00:00
|
|
|
Contextual<? extends Operation> factory = delegate.call(args, locals);
|
2015-10-27 06:14:30 +00:00
|
|
|
|
|
|
|
Player player = (Player) locals.get(Actor.class);
|
|
|
|
LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);
|
|
|
|
|
|
|
|
try {
|
|
|
|
WorldEdit.getInstance().checkMaxBrushRadius(radius);
|
|
|
|
BrushTool tool = session.getBrushTool(player.getItemInHand());
|
|
|
|
tool.setSize(radius);
|
|
|
|
tool.setBrush(new OperationFactoryBrush(factory, regionFactory), permission);
|
|
|
|
} catch (MaxBrushRadiusException e) {
|
|
|
|
WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e);
|
|
|
|
} catch (InvalidToolBindException e) {
|
|
|
|
WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
player.print("Set brush to " + factory);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-27 20:51:45 +00:00
|
|
|
public String getDescription() {
|
|
|
|
return delegate.getDescription();
|
2015-10-27 06:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-27 20:51:45 +00:00
|
|
|
public boolean testPermission0(CommandLocals locals) {
|
2015-10-27 06:14:30 +00:00
|
|
|
Actor sender = locals.get(Actor.class);
|
|
|
|
if (sender == null) {
|
|
|
|
throw new RuntimeException("Uh oh! No 'Actor' specified so that we can check permissions");
|
|
|
|
} else {
|
|
|
|
return sender.hasPermission(permission);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|