mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 11:26:42 +00:00
Purge intake-like command system
This commit is contained in:
@ -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.argument;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BooleanFlag implements CommandExecutor<Boolean> {
|
||||
|
||||
private final String description;
|
||||
|
||||
public BooleanFlag(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,85 +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.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
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 java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class NumberParser implements CommandExecutor<Number> {
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final @Nullable String defaultSuggestion;
|
||||
|
||||
public NumberParser(String name, String description) {
|
||||
this(name, description, null);
|
||||
}
|
||||
|
||||
public NumberParser(String name, String description, @Nullable String defaultSuggestion) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.defaultSuggestion = defaultSuggestion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
String next = args.next();
|
||||
try {
|
||||
return Double.parseDouble(next);
|
||||
} catch (NumberFormatException ignored) {
|
||||
throw new CommandException("The value for <" + name + "> should be a number. '" + next + "' is not a number.");
|
||||
}
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing value for <" + name + "> (try a number).");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
String value = args.next();
|
||||
return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<" + name + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -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.argument;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
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.argument.ArgumentUtils;
|
||||
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 java.util.List;
|
||||
|
||||
public class RegionFactoryParser implements CommandExecutor<RegionFactory> {
|
||||
|
||||
@Override
|
||||
public RegionFactory call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
String type = args.next();
|
||||
|
||||
switch (type) {
|
||||
case "cuboid":
|
||||
return new CuboidRegionFactory();
|
||||
case "sphere":
|
||||
return new SphereRegionFactory();
|
||||
case "cyl":
|
||||
case "cylinder":
|
||||
return new CylinderRegionFactory(1); // TODO: Adjustable height
|
||||
|
||||
default:
|
||||
throw new CommandException("Unknown shape type: " + type + " (try one of " + getUsage() + ")");
|
||||
}
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing shape type (try one of " + getUsage() + ")");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
return ArgumentUtils.getMatchingSuggestions(Lists.newArrayList("cuboid", "sphere", "cyl"), args.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "(cuboid | sphere | cyl)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Defines a region";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,80 +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.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
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 java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StringParser implements CommandExecutor<String> {
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final @Nullable String defaultSuggestion;
|
||||
|
||||
public StringParser(String name, String description) {
|
||||
this(name, description, null);
|
||||
}
|
||||
|
||||
public StringParser(String name, String description, @Nullable String defaultSuggestion) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.defaultSuggestion = defaultSuggestion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
return args.next();
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing value for <" + name + ">.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
String value = args.next();
|
||||
return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<" + name + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,106 +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.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;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.argument.ArgumentUtils;
|
||||
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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TreeGeneratorParser implements CommandExecutor<Contextual<ForestGenerator>> {
|
||||
|
||||
private final String name;
|
||||
|
||||
public TreeGeneratorParser(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String getOptionsList() {
|
||||
return Joiner.on(" | ").join(Arrays.asList(TreeType.values()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contextual<ForestGenerator> call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
String input = args.next();
|
||||
TreeType type = TreeGenerator.lookup(input);
|
||||
if (type != null) {
|
||||
return new GeneratorFactory(type);
|
||||
} else {
|
||||
throw new CommandException("Unknown value for <" + name + "> (try one of " + getOptionsList() + ").");
|
||||
}
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing value for <" + name + "> (try one of " + getOptionsList() + ").");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
String s = args.next();
|
||||
return s.isEmpty() ? Lists.newArrayList(TreeType.getPrimaryAliases()) : ArgumentUtils.getMatchingSuggestions(TreeType.getAliases(), s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<" + name + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Choose a tree generator";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final class GeneratorFactory implements Contextual<ForestGenerator> {
|
||||
private final TreeType type;
|
||||
|
||||
private GeneratorFactory(TreeType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForestGenerator createFromContext(EditContext input) {
|
||||
return new ForestGenerator((EditSession) input.getDestination(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tree of type " + type;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,84 +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.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 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 StringParser expressionParser = addParameter(new StringParser("expression", "Expression to apply", "y-=0.2"));
|
||||
|
||||
@Override
|
||||
public Deform call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
FlagData flagData = getFlagParser().call(args, locals);
|
||||
String expression = expressionParser.call(args, locals);
|
||||
boolean rawCoords = rawCoordsFlag.get(flagData, false);
|
||||
boolean offset = offsetFlag.get(flagData, false);
|
||||
|
||||
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).toVector3());
|
||||
} catch (IncompleteRegionException e) {
|
||||
throw new WrappedCommandException(e);
|
||||
}
|
||||
} else {
|
||||
deform.setMode(Mode.UNIT_CUBE);
|
||||
}
|
||||
|
||||
return deform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Apply math expression to area";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testPermission0(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,115 +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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
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;
|
||||
|
||||
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.enableStandardMode();
|
||||
locals.put(EditSession.class, editSession);
|
||||
session.tellVersion(player);
|
||||
|
||||
EditContext editContext = new EditContext();
|
||||
editContext.setDestination(locals.get(EditSession.class));
|
||||
editContext.setRegion(selection);
|
||||
editContext.setSession(session);
|
||||
|
||||
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().getPlatformCommandManager().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);
|
||||
}
|
||||
|
||||
}
|
@ -1,103 +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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
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.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.Contextual;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.regions.factory.RegionFactory;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
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 ShapedBrushCommand extends SimpleCommand<Object> {
|
||||
|
||||
private final CommandExecutor<? extends Contextual<? extends Operation>> delegate;
|
||||
private final String permission;
|
||||
|
||||
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 Contextual<? extends Operation>> delegate, String permission) {
|
||||
checkNotNull(delegate, "delegate");
|
||||
this.permission = permission;
|
||||
this.delegate = delegate;
|
||||
addParameter(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
if (!testPermission(locals)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
RegionFactory regionFactory = regionFactoryParser.call(args, locals);
|
||||
int radius = radiusCommand.call(args, locals).intValue();
|
||||
Contextual<? extends Operation> factory = delegate.call(args, locals);
|
||||
|
||||
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(HandSide.MAIN_HAND).getType());
|
||||
tool.setSize(radius);
|
||||
tool.setFill(null);
|
||||
tool.setBrush(new OperationFactoryBrush(factory, regionFactory, session), permission);
|
||||
} catch (MaxBrushRadiusException | InvalidToolBindException e) {
|
||||
WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getExceptionConverter().convert(e);
|
||||
}
|
||||
|
||||
player.print("Set brush to " + factory);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return delegate.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
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");
|
||||
} else {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user