2014-04-03 02:08:50 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
import com.google.common.base.Joiner;
|
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
2014-07-03 10:34:19 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.CommandException;
|
2014-07-01 04:56:05 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.Vector;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CreatureButcher;
|
|
|
|
import com.sk89q.worldedit.command.util.EntityRemover;
|
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
2014-06-28 00:55:39 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2018-06-15 05:41:37 +00:00
|
|
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
2014-06-28 00:55:39 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Capability;
|
2014-07-01 06:17:44 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.CommandManager;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Platform;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
2018-06-15 05:41:37 +00:00
|
|
|
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.function.visitor.EntityVisitor;
|
2014-07-03 10:34:19 +00:00
|
|
|
import com.sk89q.worldedit.internal.expression.Expression;
|
|
|
|
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
|
|
|
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.regions.CylinderRegion;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2014-07-01 04:56:05 +00:00
|
|
|
import com.sk89q.worldedit.util.command.CommandCallable;
|
2014-06-27 23:03:29 +00:00
|
|
|
import com.sk89q.worldedit.util.command.CommandMapping;
|
|
|
|
import com.sk89q.worldedit.util.command.Dispatcher;
|
2014-07-01 04:56:05 +00:00
|
|
|
import com.sk89q.worldedit.util.command.PrimaryAliasComparator;
|
2014-07-03 10:34:19 +00:00
|
|
|
import com.sk89q.worldedit.util.command.binding.Text;
|
2014-07-01 04:56:05 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
|
|
|
|
import com.sk89q.worldedit.util.formatting.Style;
|
|
|
|
import com.sk89q.worldedit.util.formatting.StyledFragment;
|
2014-07-01 08:39:54 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.component.Code;
|
|
|
|
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
|
|
|
|
import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2014-04-03 02:08:50 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility commands.
|
|
|
|
*/
|
|
|
|
public class UtilityCommands {
|
2014-07-29 18:04:04 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
private final WorldEdit we;
|
|
|
|
|
|
|
|
public UtilityCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/fill" },
|
|
|
|
usage = "<block> <radius> [depth]",
|
|
|
|
desc = "Fill a hole",
|
|
|
|
min = 2,
|
|
|
|
max = 3
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fill")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void fill(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-06-15 05:41:37 +00:00
|
|
|
ParserContext context = new ParserContext();
|
|
|
|
context.setActor(player);
|
|
|
|
context.setWorld(player.getWorld());
|
|
|
|
context.setSession(session);
|
|
|
|
Pattern pattern = we.getPatternFactory().parseFromInput(args.getString(0), context);
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
double radius = Math.max(1, args.getDouble(1));
|
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
|
|
|
|
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
2018-06-15 05:41:37 +00:00
|
|
|
int affected;
|
|
|
|
if (pattern instanceof BlockPattern) {
|
|
|
|
affected = editSession.fillXZ(pos, ((BlockPattern) pattern).getBlock(), radius, depth, false);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
affected = editSession.fillXZ(pos, pattern, radius, depth, false);
|
|
|
|
}
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/fillr" },
|
|
|
|
usage = "<block> <radius> [depth]",
|
|
|
|
desc = "Fill a hole recursively",
|
|
|
|
min = 2,
|
|
|
|
max = 3
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fill.recursive")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void fillr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-06-15 05:41:37 +00:00
|
|
|
ParserContext context = new ParserContext();
|
|
|
|
context.setActor(player);
|
|
|
|
context.setWorld(player.getWorld());
|
|
|
|
context.setSession(session);
|
|
|
|
Pattern pattern = we.getPatternFactory().parseFromInput(args.getString(0), context);
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
double radius = Math.max(1, args.getDouble(1));
|
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : Integer.MAX_VALUE;
|
|
|
|
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
int affected = 0;
|
2018-06-15 05:41:37 +00:00
|
|
|
if (pattern instanceof BlockPattern) {
|
|
|
|
affected = editSession.fillXZ(pos, ((BlockPattern) pattern).getBlock(), radius, depth, true);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
affected = editSession.fillXZ(pos, pattern, radius, depth, true);
|
|
|
|
}
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/drain" },
|
|
|
|
usage = "<radius>",
|
|
|
|
desc = "Drain a pool",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.drain")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void drain(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
double radius = Math.max(0, args.getDouble(0));
|
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int affected = editSession.drainArea(
|
|
|
|
session.getPlacementPosition(player), radius);
|
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/fixlava", "fixlava" },
|
|
|
|
usage = "<radius>",
|
|
|
|
desc = "Fix lava to be stationary",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fixlava")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void fixLava(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
double radius = Math.max(0, args.getDouble(0));
|
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int affected = editSession.fixLiquid(
|
|
|
|
session.getPlacementPosition(player), radius, 10, 11);
|
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/fixwater", "fixwater" },
|
|
|
|
usage = "<radius>",
|
|
|
|
desc = "Fix water to be stationary",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fixwater")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void fixWater(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
double radius = Math.max(0, args.getDouble(0));
|
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int affected = editSession.fixLiquid(
|
|
|
|
session.getPlacementPosition(player), radius, 8, 9);
|
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/removeabove", "removeabove" },
|
|
|
|
usage = "[size] [height]",
|
|
|
|
desc = "Remove blocks above your head.",
|
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.removeabove")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void removeAbove(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
|
|
|
we.checkMaxRadius(size);
|
2014-04-05 09:59:38 +00:00
|
|
|
World world = player.getWorld();
|
2014-04-03 02:08:50 +00:00
|
|
|
int height = args.argsLength() > 1 ? Math.min((world.getMaxY() + 1), args.getInteger(1) + 2) : (world.getMaxY() + 1);
|
|
|
|
|
|
|
|
int affected = editSession.removeAbove(
|
|
|
|
session.getPlacementPosition(player), size, height);
|
|
|
|
player.print(affected + " block(s) have been removed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/removebelow", "removebelow" },
|
|
|
|
usage = "[size] [height]",
|
|
|
|
desc = "Remove blocks below you.",
|
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.removebelow")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void removeBelow(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
|
|
|
we.checkMaxRadius(size);
|
2014-04-05 09:59:38 +00:00
|
|
|
World world = player.getWorld();
|
2014-04-03 02:08:50 +00:00
|
|
|
int height = args.argsLength() > 1 ? Math.min((world.getMaxY() + 1), args.getInteger(1) + 2) : (world.getMaxY() + 1);
|
|
|
|
|
|
|
|
int affected = editSession.removeBelow(session.getPlacementPosition(player), size, height);
|
|
|
|
player.print(affected + " block(s) have been removed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/removenear", "removenear" },
|
|
|
|
usage = "<block> [size]",
|
|
|
|
desc = "Remove blocks near you.",
|
|
|
|
min = 1,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.removenear")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void removeNear(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-06-17 05:42:47 +00:00
|
|
|
ParserContext context = new ParserContext();
|
|
|
|
context.setActor(player);
|
|
|
|
context.setWorld(player.getWorld());
|
|
|
|
context.setSession(session);
|
|
|
|
context.setRestricted(false);
|
|
|
|
context.setPreferringWildcard(false);
|
|
|
|
|
|
|
|
BaseBlock block = we.getBlockFactory().parseFromInput(args.getString(0), context);
|
2014-04-03 02:08:50 +00:00
|
|
|
int size = Math.max(1, args.getInteger(1, 50));
|
|
|
|
we.checkMaxRadius(size);
|
|
|
|
|
2018-01-03 05:35:51 +00:00
|
|
|
int affected = editSession.removeNear(session.getPlacementPosition(player), block.getType().getLegacyId(), size);
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print(affected + " block(s) have been removed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/replacenear", "replacenear" },
|
|
|
|
usage = "<size> <from-id> <to-id>",
|
|
|
|
desc = "Replace nearby blocks",
|
|
|
|
flags = "f",
|
|
|
|
min = 3,
|
|
|
|
max = 3
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.replacenear")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void replaceNear(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
int size = Math.max(1, args.getInteger(0));
|
|
|
|
int affected;
|
|
|
|
Set<BaseBlock> from;
|
|
|
|
Pattern to;
|
2018-06-15 05:41:37 +00:00
|
|
|
|
|
|
|
ParserContext context = new ParserContext();
|
|
|
|
context.setActor(player);
|
|
|
|
context.setWorld(player.getWorld());
|
|
|
|
context.setSession(session);
|
|
|
|
context.setRestricted(false);
|
|
|
|
context.setPreferringWildcard(!args.hasFlag('f'));
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
if (args.argsLength() == 2) {
|
|
|
|
from = null;
|
2018-06-15 05:41:37 +00:00
|
|
|
to = we.getPatternFactory().parseFromInput(args.getString(1), context);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-06-15 05:41:37 +00:00
|
|
|
from = we.getBlockFactory().parseFromListInput(args.getString(1), context);
|
|
|
|
to = we.getPatternFactory().parseFromInput(args.getString(2), context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector base = session.getPlacementPosition(player);
|
|
|
|
Vector min = base.subtract(size, size, size);
|
|
|
|
Vector max = base.add(size, size, size);
|
|
|
|
Region region = new CuboidRegion(player.getWorld(), min, max);
|
|
|
|
|
2018-06-15 05:41:37 +00:00
|
|
|
if (to instanceof BlockPattern) {
|
|
|
|
affected = editSession.replaceBlocks(region, from, ((BlockPattern) to).getBlock());
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
|
|
|
affected = editSession.replaceBlocks(region, from, to);
|
|
|
|
}
|
|
|
|
player.print(affected + " block(s) have been replaced.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/snow", "snow" },
|
|
|
|
usage = "[radius]",
|
|
|
|
desc = "Simulates snow",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.snow")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void snow(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
|
|
|
|
|
|
|
|
int affected = editSession.simulateSnow(session.getPlacementPosition(player), size);
|
|
|
|
player.print(affected + " surfaces covered. Let it snow~");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = {"/thaw", "thaw"},
|
|
|
|
usage = "[radius]",
|
|
|
|
desc = "Thaws the area",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.thaw")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void thaw(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
|
|
|
|
|
|
|
|
int affected = editSession.thaw(session.getPlacementPosition(player), size);
|
|
|
|
player.print(affected + " surfaces thawed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/green", "green" },
|
|
|
|
usage = "[radius]",
|
|
|
|
desc = "Greens the area",
|
|
|
|
flags = "f",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.green")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void green(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
final double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
|
|
|
|
final boolean onlyNormalDirt = !args.hasFlag('f');
|
|
|
|
|
|
|
|
final int affected = editSession.green(session.getPlacementPosition(player), size, onlyNormalDirt);
|
|
|
|
player.print(affected + " surfaces greened.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/ex", "/ext", "/extinguish", "ex", "ext", "extinguish" },
|
|
|
|
usage = "[radius]",
|
|
|
|
desc = "Extinguish nearby fire",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.extinguish")
|
|
|
|
@Logging(PLACEMENT)
|
2014-06-28 08:01:49 +00:00
|
|
|
public void extinguish(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
LocalConfiguration config = we.getConfiguration();
|
|
|
|
|
|
|
|
int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
|
|
|
|
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0))
|
|
|
|
: defaultRadius;
|
|
|
|
we.checkMaxRadius(size);
|
|
|
|
|
|
|
|
int affected = editSession.removeNear(session.getPlacementPosition(player), 51, size);
|
|
|
|
player.print(affected + " block(s) have been removed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "butcher" },
|
|
|
|
usage = "[radius]",
|
2015-01-22 20:48:45 +00:00
|
|
|
flags = "plangbtfr",
|
2014-04-03 02:08:50 +00:00
|
|
|
desc = "Kill all or nearby mobs",
|
|
|
|
help =
|
|
|
|
"Kills nearby mobs, based on radius, if none is given uses default in configuration.\n" +
|
2015-01-22 20:48:45 +00:00
|
|
|
"Flags:\n" +
|
2014-04-03 02:08:50 +00:00
|
|
|
" -p also kills pets.\n" +
|
|
|
|
" -n also kills NPCs.\n" +
|
|
|
|
" -g also kills Golems.\n" +
|
|
|
|
" -a also kills animals.\n" +
|
|
|
|
" -b also kills ambient mobs.\n" +
|
2014-05-02 00:36:11 +00:00
|
|
|
" -t also kills mobs with name tags.\n" +
|
2014-04-03 02:08:50 +00:00
|
|
|
" -f compounds all previous flags.\n" +
|
2015-01-22 20:48:45 +00:00
|
|
|
" -r also destroys armor stands.\n" +
|
2014-07-16 02:47:47 +00:00
|
|
|
" -l currently does nothing.",
|
2014-04-03 02:08:50 +00:00
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.butcher")
|
|
|
|
@Logging(PLACEMENT)
|
2014-07-01 22:04:30 +00:00
|
|
|
public void butcher(Actor actor, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
LocalConfiguration config = we.getConfiguration();
|
2014-07-01 22:04:30 +00:00
|
|
|
Player player = actor instanceof Player ? (Player) actor : null;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
// technically the default can be larger than the max, but that's not my problem
|
|
|
|
int radius = config.butcherDefaultRadius;
|
|
|
|
|
|
|
|
// there might be a better way to do this but my brain is fried right now
|
|
|
|
if (args.argsLength() > 0) { // user inputted radius, override the default
|
|
|
|
radius = args.getInteger(0);
|
2016-04-26 23:40:25 +00:00
|
|
|
if (radius < -1) {
|
|
|
|
actor.printError("Use -1 to remove all mobs in loaded chunks");
|
|
|
|
return;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
if (config.butcherMaxRadius != -1) { // clamp if there is a max
|
|
|
|
if (radius == -1) {
|
|
|
|
radius = config.butcherMaxRadius;
|
|
|
|
} else { // Math.min does not work if radius is -1 (actually highest possible value)
|
|
|
|
radius = Math.min(radius, config.butcherMaxRadius);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
CreatureButcher flags = new CreatureButcher(actor);
|
|
|
|
flags.fromCommand(args);
|
|
|
|
|
2018-06-16 06:36:55 +00:00
|
|
|
List<EntityVisitor> visitors = new ArrayList<>();
|
2014-07-16 02:47:47 +00:00
|
|
|
LocalSession session = null;
|
|
|
|
EditSession editSession = null;
|
|
|
|
|
2014-06-28 00:55:39 +00:00
|
|
|
if (player != null) {
|
2014-07-16 02:47:47 +00:00
|
|
|
session = we.getSessionManager().get(player);
|
|
|
|
Vector center = session.getPlacementPosition(player);
|
|
|
|
editSession = session.createEditSession(player);
|
|
|
|
List<? extends Entity> entities;
|
|
|
|
if (radius >= 0) {
|
|
|
|
CylinderRegion region = CylinderRegion.createRadius(editSession, center, radius);
|
|
|
|
entities = editSession.getEntities(region);
|
|
|
|
} else {
|
|
|
|
entities = editSession.getEntities();
|
|
|
|
}
|
|
|
|
visitors.add(new EntityVisitor(entities.iterator(), flags.createFunction(editSession.getWorld().getWorldData().getEntityRegistry())));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2014-07-16 02:47:47 +00:00
|
|
|
Platform platform = we.getPlatformManager().queryCapability(Capability.WORLD_EDITING);
|
|
|
|
for (World world : platform.getWorlds()) {
|
|
|
|
List<? extends Entity> entities = world.getEntities();
|
|
|
|
visitors.add(new EntityVisitor(entities.iterator(), flags.createFunction(world.getWorldData().getEntityRegistry())));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
int killed = 0;
|
|
|
|
for (EntityVisitor visitor : visitors) {
|
|
|
|
Operations.completeLegacy(visitor);
|
|
|
|
killed += visitor.getAffected();
|
|
|
|
}
|
|
|
|
|
2015-01-21 08:46:35 +00:00
|
|
|
actor.print("Killed " + killed + (killed != 1 ? " mobs" : " mob") + (radius < 0 ? "" : " in a radius of " + radius) + ".");
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
if (editSession != null) {
|
|
|
|
session.remember(editSession);
|
|
|
|
editSession.flushQueue();
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "remove", "rem", "rement" },
|
|
|
|
usage = "<type> <radius>",
|
|
|
|
desc = "Remove all entities of a type",
|
|
|
|
min = 2,
|
|
|
|
max = 2
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.remove")
|
|
|
|
@Logging(PLACEMENT)
|
2014-07-16 02:47:47 +00:00
|
|
|
public void remove(Actor actor, CommandContext args) throws WorldEditException, CommandException {
|
2014-04-03 02:08:50 +00:00
|
|
|
String typeStr = args.getString(0);
|
|
|
|
int radius = args.getInteger(1);
|
2014-07-16 02:47:47 +00:00
|
|
|
Player player = actor instanceof Player ? (Player) actor : null;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
if (radius < -1) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printError("Use -1 to remove all entities in loaded chunks");
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
EntityRemover remover = new EntityRemover();
|
|
|
|
remover.fromString(typeStr);
|
|
|
|
|
2018-06-16 06:36:55 +00:00
|
|
|
List<EntityVisitor> visitors = new ArrayList<>();
|
2014-07-16 02:47:47 +00:00
|
|
|
LocalSession session = null;
|
|
|
|
EditSession editSession = null;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-28 00:55:39 +00:00
|
|
|
if (player != null) {
|
2014-07-16 02:47:47 +00:00
|
|
|
session = we.getSessionManager().get(player);
|
|
|
|
Vector center = session.getPlacementPosition(player);
|
|
|
|
editSession = session.createEditSession(player);
|
|
|
|
List<? extends Entity> entities;
|
|
|
|
if (radius >= 0) {
|
|
|
|
CylinderRegion region = CylinderRegion.createRadius(editSession, center, radius);
|
|
|
|
entities = editSession.getEntities(region);
|
|
|
|
} else {
|
|
|
|
entities = editSession.getEntities();
|
|
|
|
}
|
|
|
|
visitors.add(new EntityVisitor(entities.iterator(), remover.createFunction(editSession.getWorld().getWorldData().getEntityRegistry())));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2014-07-16 02:47:47 +00:00
|
|
|
Platform platform = we.getPlatformManager().queryCapability(Capability.WORLD_EDITING);
|
|
|
|
for (World world : platform.getWorlds()) {
|
|
|
|
List<? extends Entity> entities = world.getEntities();
|
|
|
|
visitors.add(new EntityVisitor(entities.iterator(), remover.createFunction(world.getWorldData().getEntityRegistry())));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-16 02:47:47 +00:00
|
|
|
|
|
|
|
int removed = 0;
|
|
|
|
for (EntityVisitor visitor : visitors) {
|
|
|
|
Operations.completeLegacy(visitor);
|
|
|
|
removed += visitor.getAffected();
|
|
|
|
}
|
|
|
|
|
2015-01-19 19:15:31 +00:00
|
|
|
actor.print("Marked " + removed + (removed != 1 ? " entities" : " entity") + " for removal.");
|
2014-07-16 02:47:47 +00:00
|
|
|
|
|
|
|
if (editSession != null) {
|
|
|
|
session.remember(editSession);
|
|
|
|
editSession.flushQueue();
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 10:34:19 +00:00
|
|
|
@Command(
|
|
|
|
aliases = { "/calc", "/calculate", "/eval", "/evaluate", "/solve" },
|
|
|
|
usage = "<expression>",
|
|
|
|
desc = "Evaluate a mathematical expression"
|
|
|
|
)
|
2015-12-21 21:14:44 +00:00
|
|
|
@CommandPermissions("worldedit.calc")
|
2014-07-03 10:34:19 +00:00
|
|
|
public void calc(Actor actor, @Text String input) throws CommandException {
|
|
|
|
try {
|
|
|
|
Expression expression = Expression.compile(input);
|
|
|
|
actor.print("= " + expression.evaluate());
|
|
|
|
} catch (EvaluationException e) {
|
|
|
|
actor.printError(String.format(
|
|
|
|
"'%s' could not be parsed as a valid expression", input));
|
|
|
|
} catch (ExpressionException e) {
|
|
|
|
actor.printError(String.format(
|
|
|
|
"'%s' could not be evaluated (error: %s)", input, e.getMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
@Command(
|
|
|
|
aliases = { "/help" },
|
|
|
|
usage = "[<command>]",
|
2014-06-29 01:44:09 +00:00
|
|
|
desc = "Displays help for WorldEdit commands",
|
2014-04-03 02:08:50 +00:00
|
|
|
min = 0,
|
|
|
|
max = -1
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.help")
|
2014-06-28 00:55:39 +00:00
|
|
|
public void help(Actor actor, CommandContext args) throws WorldEditException {
|
|
|
|
help(args, we, actor);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
private static CommandMapping detectCommand(Dispatcher dispatcher, String command, boolean isRootLevel) {
|
|
|
|
CommandMapping mapping;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
// First try the command as entered
|
|
|
|
mapping = dispatcher.get(command);
|
|
|
|
if (mapping != null) {
|
|
|
|
return mapping;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
// Then if we're looking at root commands and the user didn't use
|
|
|
|
// any slashes, let's try double slashes and then single slashes.
|
|
|
|
// However, be aware that there exists different single slash
|
|
|
|
// and double slash commands in WorldEdit
|
|
|
|
if (isRootLevel && !command.contains("/")) {
|
|
|
|
mapping = dispatcher.get("//" + command);
|
|
|
|
if (mapping != null) {
|
|
|
|
return mapping;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
mapping = dispatcher.get("/" + command);
|
|
|
|
if (mapping != null) {
|
|
|
|
return mapping;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
return null;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
public static void help(CommandContext args, WorldEdit we, Actor actor) {
|
|
|
|
CommandCallable callable = we.getPlatformManager().getCommandManager().getDispatcher();
|
|
|
|
|
|
|
|
int page = 0;
|
|
|
|
final int perPage = actor instanceof Player ? 8 : 20; // More pages for console
|
|
|
|
int effectiveLength = args.argsLength();
|
|
|
|
|
|
|
|
// Detect page from args
|
|
|
|
try {
|
|
|
|
if (args.argsLength() > 0) {
|
|
|
|
page = args.getInteger(args.argsLength() - 1);
|
|
|
|
if (page <= 0) {
|
|
|
|
page = 1;
|
|
|
|
} else {
|
|
|
|
page--;
|
|
|
|
}
|
|
|
|
|
|
|
|
effectiveLength--;
|
|
|
|
}
|
|
|
|
} catch (NumberFormatException ignored) {
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
boolean isRootLevel = true;
|
2018-06-16 06:36:55 +00:00
|
|
|
List<String> visited = new ArrayList<>();
|
2014-07-01 04:56:05 +00:00
|
|
|
|
|
|
|
// Drill down to the command
|
|
|
|
for (int i = 0; i < effectiveLength; i++) {
|
|
|
|
String command = args.getString(i);
|
|
|
|
|
|
|
|
if (callable instanceof Dispatcher) {
|
|
|
|
// Chop off the beginning / if we're are the root level
|
|
|
|
if (isRootLevel && command.length() > 1 && command.charAt(0) == '/') {
|
|
|
|
command = command.substring(1);
|
|
|
|
}
|
2014-06-27 23:03:29 +00:00
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
CommandMapping mapping = detectCommand((Dispatcher) callable, command, isRootLevel);
|
|
|
|
if (mapping != null) {
|
|
|
|
callable = mapping.getCallable();
|
|
|
|
} else {
|
|
|
|
if (isRootLevel) {
|
|
|
|
actor.printError(String.format("The command '%s' could not be found.", args.getString(i)));
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
actor.printError(String.format("The sub-command '%s' under '%s' could not be found.",
|
|
|
|
command, Joiner.on(" ").join(visited)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
visited.add(args.getString(i));
|
|
|
|
isRootLevel = false;
|
|
|
|
} else {
|
|
|
|
actor.printError(String.format("'%s' has no sub-commands. (Maybe '%s' is for a parameter?)",
|
|
|
|
Joiner.on(" ").join(visited), command));
|
|
|
|
return;
|
|
|
|
}
|
2014-06-27 23:03:29 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 04:56:05 +00:00
|
|
|
// Create the message
|
|
|
|
if (callable instanceof Dispatcher) {
|
|
|
|
Dispatcher dispatcher = (Dispatcher) callable;
|
|
|
|
|
|
|
|
// Get a list of aliases
|
2018-06-16 06:36:55 +00:00
|
|
|
List<CommandMapping> aliases = new ArrayList<>(dispatcher.getCommands());
|
|
|
|
aliases.sort(new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN));
|
2014-07-01 04:56:05 +00:00
|
|
|
|
|
|
|
// Calculate pagination
|
|
|
|
int offset = perPage * page;
|
|
|
|
int pageTotal = (int) Math.ceil(aliases.size() / (double) perPage);
|
|
|
|
|
|
|
|
// Box
|
|
|
|
CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page + 1, pageTotal));
|
|
|
|
StyledFragment contents = box.getContents();
|
|
|
|
StyledFragment tip = contents.createFragment(Style.GRAY);
|
|
|
|
|
|
|
|
if (offset >= aliases.size()) {
|
|
|
|
tip.createFragment(Style.RED).append(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal)).newLine();
|
|
|
|
} else {
|
|
|
|
List<CommandMapping> list = aliases.subList(offset, Math.min(offset + perPage, aliases.size()));
|
|
|
|
|
|
|
|
tip.append("Type ");
|
2014-07-01 05:08:08 +00:00
|
|
|
tip.append(new Code().append("//help ").append("<command> [<page>]"));
|
2014-07-01 04:56:05 +00:00
|
|
|
tip.append(" for more information.").newLine();
|
|
|
|
|
|
|
|
// Add each command
|
|
|
|
for (CommandMapping mapping : list) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
if (isRootLevel) {
|
|
|
|
builder.append("/");
|
|
|
|
}
|
|
|
|
if (!visited.isEmpty()) {
|
|
|
|
builder.append(Joiner.on(" ").join(visited));
|
|
|
|
builder.append(" ");
|
|
|
|
}
|
|
|
|
builder.append(mapping.getPrimaryAlias());
|
2015-10-27 06:14:30 +00:00
|
|
|
box.appendCommand(builder.toString(), mapping.getDescription().getDescription());
|
2014-07-01 04:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actor.printRaw(ColorCodeBuilder.asColorCodes(box));
|
2014-06-27 23:03:29 +00:00
|
|
|
} else {
|
2014-07-01 05:48:04 +00:00
|
|
|
CommandUsageBox box = new CommandUsageBox(callable, Joiner.on(" ").join(visited));
|
2014-07-01 04:56:05 +00:00
|
|
|
actor.printRaw(ColorCodeBuilder.asColorCodes(box));
|
2014-06-27 23:03:29 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2014-07-29 18:04:04 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|