2011-01-29 10:05:22 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
2012-01-05 21:38:23 +00:00
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
|
2011-01-29 10:05:22 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.commands;
|
|
|
|
|
2011-12-15 05:28:09 +00:00
|
|
|
import java.util.Comparator;
|
2011-01-29 10:05:22 +00:00
|
|
|
import java.util.Set;
|
2011-12-13 08:23:21 +00:00
|
|
|
import java.util.SortedSet;
|
|
|
|
import java.util.TreeSet;
|
|
|
|
|
2011-02-18 06:53:44 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
2011-12-13 08:23:21 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.CommandsManager;
|
2011-12-15 12:28:25 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Console;
|
2011-08-08 12:40:02 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.*;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
2011-12-06 05:26:12 +00:00
|
|
|
import com.sk89q.worldedit.LocalWorld.KillFlags;
|
2011-01-29 10:05:22 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.patterns.*;
|
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility commands.
|
|
|
|
*
|
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public class UtilityCommands {
|
2011-12-18 07:45:12 +00:00
|
|
|
private final WorldEdit we;
|
|
|
|
|
|
|
|
public UtilityCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/fill" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "<block> <radius> [depth]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Fill a hole",
|
|
|
|
min = 2,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.fill")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void fill(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
2011-08-15 12:35:21 +00:00
|
|
|
double radius = Math.max(1, args.getDouble(1));
|
2011-01-29 10:05:22 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
|
|
|
|
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
int affected = 0;
|
|
|
|
if (pattern instanceof SingleBlockPattern) {
|
|
|
|
affected = editSession.fillXZ(pos,
|
2011-09-24 19:24:10 +00:00
|
|
|
((SingleBlockPattern) pattern).getBlock(),
|
2011-01-29 10:05:22 +00:00
|
|
|
radius, depth, false);
|
|
|
|
} else {
|
|
|
|
affected = editSession.fillXZ(pos, pattern, radius, depth, false);
|
|
|
|
}
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/fillr" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "<block> <radius> [depth]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Fill a hole recursively",
|
|
|
|
min = 2,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.fill.recursive")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void fillr(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
Pattern pattern = we.getBlockPattern(player, args.getString(0));
|
2011-08-15 12:35:21 +00:00
|
|
|
double radius = Math.max(1, args.getDouble(1));
|
2011-01-29 10:05:22 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
|
|
|
|
|
|
|
|
Vector pos = session.getPlacementPosition(player);
|
|
|
|
int affected = 0;
|
|
|
|
if (pattern instanceof SingleBlockPattern) {
|
|
|
|
affected = editSession.fillXZ(pos,
|
2011-09-24 19:24:10 +00:00
|
|
|
((SingleBlockPattern) pattern).getBlock(),
|
2011-01-29 10:05:22 +00:00
|
|
|
radius, depth, true);
|
|
|
|
} else {
|
|
|
|
affected = editSession.fillXZ(pos, pattern, radius, depth, true);
|
|
|
|
}
|
|
|
|
player.print(affected + " block(s) have been created.");
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/drain" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<radius>",
|
|
|
|
desc = "Drain a pool",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.drain")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void drain(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-08-15 12:35:21 +00:00
|
|
|
double radius = Math.max(0, args.getDouble(0));
|
2011-01-29 10:05:22 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int affected = editSession.drainArea(
|
|
|
|
session.getPlacementPosition(player), radius);
|
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/fixlava", "fixlava" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<radius>",
|
|
|
|
desc = "Fix lava to be stationary",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.fixlava")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void fixLava(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-08-15 12:35:21 +00:00
|
|
|
double radius = Math.max(0, args.getDouble(0));
|
2011-01-29 10:05:22 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int affected = editSession.fixLiquid(
|
|
|
|
session.getPlacementPosition(player), radius, 10, 11);
|
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/fixwater", "fixwater" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "<radius>",
|
|
|
|
desc = "Fix water to be stationary",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.fixwater")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void fixWater(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-08-15 12:35:21 +00:00
|
|
|
double radius = Math.max(0, args.getDouble(0));
|
2011-01-29 10:05:22 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int affected = editSession.fixLiquid(
|
|
|
|
session.getPlacementPosition(player), radius, 8, 9);
|
|
|
|
player.print(affected + " block(s) have been changed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/removeabove", "removeabove" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "[size] [height]",
|
|
|
|
desc = "Remove blocks above your head.",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.removeabove")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void removeAbove(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
|
|
|
we.checkMaxRadius(size);
|
2011-12-13 03:20:31 +00:00
|
|
|
LocalWorld world = player.getWorld();
|
|
|
|
int height = args.argsLength() > 1 ? Math.min((world.getMaxY() + 1), args.getInteger(1) + 2) : (world.getMaxY() + 1);
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
int affected = editSession.removeAbove(
|
|
|
|
session.getPlacementPosition(player), size, height);
|
|
|
|
player.print(affected + " block(s) have been removed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/removebelow", "removebelow" },
|
2011-09-18 05:29:12 +00:00
|
|
|
usage = "[size] [height]",
|
2011-09-17 22:57:34 +00:00
|
|
|
desc = "Remove blocks below you.",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 2
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.removebelow")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void removeBelow(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
|
|
|
|
we.checkMaxRadius(size);
|
2011-12-13 03:20:31 +00:00
|
|
|
LocalWorld world = player.getWorld();
|
|
|
|
int height = args.argsLength() > 1 ? Math.min((world.getMaxY() + 1), args.getInteger(1) + 2) : (world.getMaxY() + 1);
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-09-24 19:24:10 +00:00
|
|
|
int affected = editSession.removeBelow(session.getPlacementPosition(player), size, height);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print(affected + " block(s) have been removed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/removenear", "removenear" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "<block> [size]",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Remove blocks near you.",
|
|
|
|
min = 1,
|
|
|
|
max = 2
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.removenear")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void removeNear(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
BaseBlock block = we.getBlock(player, args.getString(0), true);
|
2011-01-31 06:14:36 +00:00
|
|
|
int size = Math.max(1, args.getInteger(1, 50));
|
2011-01-29 10:05:22 +00:00
|
|
|
we.checkMaxRadius(size);
|
|
|
|
|
2011-09-24 19:24:10 +00:00
|
|
|
int affected = editSession.removeNear(session.getPlacementPosition(player), block.getType(), size);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print(affected + " block(s) have been removed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/replacenear", "replacenear" },
|
2011-09-17 22:57:34 +00:00
|
|
|
usage = "<size> <from-id> <to-id>",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Replace nearby blocks",
|
2011-09-18 04:50:06 +00:00
|
|
|
flags = "f",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 3,
|
|
|
|
max = 3
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.replacenear")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void replaceNear(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
int size = Math.max(1, args.getInteger(0));
|
2011-08-22 06:55:50 +00:00
|
|
|
int affected;
|
2011-08-29 06:57:07 +00:00
|
|
|
Set<BaseBlock> from;
|
2011-08-22 06:55:50 +00:00
|
|
|
Pattern to;
|
2011-01-29 10:05:22 +00:00
|
|
|
if (args.argsLength() == 2) {
|
|
|
|
from = null;
|
2011-08-22 06:55:50 +00:00
|
|
|
to = we.getBlockPattern(player, args.getString(1));
|
2011-01-29 10:05:22 +00:00
|
|
|
} else {
|
2011-09-18 04:50:06 +00:00
|
|
|
from = we.getBlocks(player, args.getString(1), true, !args.hasFlag('f'));
|
2011-08-22 06:55:50 +00:00
|
|
|
to = we.getBlockPattern(player, args.getString(2));
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 16:44:12 +00:00
|
|
|
Vector base = session.getPlacementPosition(player);
|
|
|
|
Vector min = base.subtract(size, size, size);
|
|
|
|
Vector max = base.add(size, size, size);
|
2011-12-13 03:20:31 +00:00
|
|
|
Region region = new CuboidRegion(player.getWorld(), min, max);
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-08-22 06:55:50 +00:00
|
|
|
if (to instanceof SingleBlockPattern) {
|
|
|
|
affected = editSession.replaceBlocks(region, from, ((SingleBlockPattern) to).getBlock());
|
|
|
|
} else {
|
|
|
|
affected = editSession.replaceBlocks(region, from, to);
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print(affected + " block(s) have been replaced.");
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/snow", "snow" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "[radius]",
|
|
|
|
desc = "Simulates snow",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.snow")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void snow(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-08-15 12:35:21 +00:00
|
|
|
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-06-21 16:44:12 +00:00
|
|
|
int affected = editSession.simulateSnow(session.getPlacementPosition(player), size);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print(affected + " surfaces covered. Let it snow~");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-17 22:57:34 +00:00
|
|
|
aliases = {"/thaw", "thaw"},
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "[radius]",
|
|
|
|
desc = "Thaws the area",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.thaw")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void thaw(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-08-15 12:35:21 +00:00
|
|
|
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2011-06-21 16:44:12 +00:00
|
|
|
int affected = editSession.thaw(session.getPlacementPosition(player), size);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print(affected + " surfaces thawed.");
|
|
|
|
}
|
2011-08-16 16:43:13 +00:00
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/green", "green" },
|
2011-08-16 16:43:13 +00:00
|
|
|
usage = "[radius]",
|
|
|
|
desc = "Greens the area",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.green")
|
2011-08-16 16:43:13 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void green(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-08-16 16:43:13 +00:00
|
|
|
|
|
|
|
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
|
|
|
|
|
|
|
|
int affected = editSession.green(session.getPlacementPosition(player), size);
|
|
|
|
player.print(affected + " surfaces greened.");
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "/ex", "/ext", "/extinguish", "ex", "ext", "extinguish" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "[radius]",
|
|
|
|
desc = "Extinguish nearby fire",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.extinguish")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void extinguish(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
|
|
|
LocalConfiguration config = we.getConfiguration();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
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);
|
|
|
|
|
2011-09-24 19:24:10 +00:00
|
|
|
int affected = editSession.removeNear(session.getPlacementPosition(player), 51, size);
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print(affected + " block(s) have been removed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "butcher" },
|
2011-01-29 10:05:22 +00:00
|
|
|
usage = "[radius]",
|
2012-03-17 08:09:31 +00:00
|
|
|
flags = "plangf",
|
2011-01-29 10:05:22 +00:00
|
|
|
desc = "Kill all or nearby mobs",
|
Added help text for most commands that take flags.
//generate, //regen, //deform, //[h]cyl, //[h]sphere, //chunk, //outset, //inset, //stack, //move, //smooth, //paste, //flip, /search //distr /butcher, //brush sphere/cyl/clipboard/smooth
Only //replace and /replacenear are still missing.
2011-12-05 10:21:40 +00:00
|
|
|
help =
|
2012-03-03 06:19:30 +00:00
|
|
|
"Kills nearby mobs, based on radius, if none is given uses default in configuration.\n" +
|
2011-12-06 05:26:12 +00:00
|
|
|
"Flags:" +
|
2011-12-06 06:08:32 +00:00
|
|
|
" -p also kills pets.\n" +
|
|
|
|
" -n also kills NPCs.\n" +
|
2012-03-16 19:02:56 +00:00
|
|
|
" -g also kills Golems.\n" +
|
2011-12-21 17:10:34 +00:00
|
|
|
" -a also kills animals.\n" +
|
2012-03-17 08:09:31 +00:00
|
|
|
" -f compounds all previous flags.\n" +
|
2011-12-21 17:10:34 +00:00
|
|
|
" -l strikes lightning on each killed mob.",
|
2011-01-29 10:05:22 +00:00
|
|
|
min = 0,
|
|
|
|
max = 1
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.butcher")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-15 12:28:25 +00:00
|
|
|
@Console
|
2011-12-18 07:45:12 +00:00
|
|
|
public void butcher(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2012-03-03 06:19:30 +00:00
|
|
|
LocalConfiguration config = we.getConfiguration();
|
|
|
|
|
|
|
|
final int radius;
|
|
|
|
|
|
|
|
if(args.argsLength() > 0){
|
|
|
|
radius = Math.max(1, args.getInteger(0));
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
radius = config.butcherDefaultRadius;
|
|
|
|
}
|
2012-03-16 19:02:56 +00:00
|
|
|
|
2012-03-17 08:09:31 +00:00
|
|
|
FlagContainer flags = new FlagContainer(player);
|
|
|
|
flags.or(KillFlags.FRIENDLY , args.hasFlag('f'));
|
|
|
|
flags.or(KillFlags.PETS , args.hasFlag('p'), "worldedit.butcher.pets");
|
|
|
|
flags.or(KillFlags.NPCS , args.hasFlag('n'), "worldedit.butcher.npcs");
|
|
|
|
flags.or(KillFlags.GOLEMS , args.hasFlag('g'), "worldedit.butcher.golems");
|
|
|
|
flags.or(KillFlags.ANIMALS , args.hasFlag('a'), "worldedit.butcher.animals");
|
|
|
|
flags.or(KillFlags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning");
|
2011-12-06 05:26:12 +00:00
|
|
|
|
2011-12-15 12:28:25 +00:00
|
|
|
int killed;
|
|
|
|
if (player.isPlayer()) {
|
2012-03-17 08:09:31 +00:00
|
|
|
killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags.flags);
|
2011-12-15 12:28:25 +00:00
|
|
|
} else {
|
|
|
|
killed = 0;
|
|
|
|
for (LocalWorld world : we.getServer().getWorlds()) {
|
2012-03-17 08:09:31 +00:00
|
|
|
killed += world.killMobs(new Vector(), radius, flags.flags);
|
2011-12-15 12:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
player.print("Killed " + killed + " mobs.");
|
|
|
|
}
|
2011-02-19 04:31:49 +00:00
|
|
|
|
2012-03-17 08:09:31 +00:00
|
|
|
public class FlagContainer {
|
|
|
|
private final LocalPlayer player;
|
|
|
|
public int flags = 0;
|
|
|
|
public FlagContainer(LocalPlayer player) {
|
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void or(int flag, boolean on) {
|
|
|
|
if (on) flags |= flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void or(int flag, boolean on, String permission) {
|
|
|
|
or(flag, on);
|
|
|
|
|
|
|
|
if ((flags & flag) != 0 && !player.hasPermission(permission)) {
|
|
|
|
flags &= ~flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-19 04:31:49 +00:00
|
|
|
@Command(
|
2011-09-19 05:14:43 +00:00
|
|
|
aliases = { "remove", "rem", "rement" },
|
2011-02-19 04:31:49 +00:00
|
|
|
usage = "<type> <radius>",
|
|
|
|
desc = "Remove all entities of a type",
|
|
|
|
min = 2,
|
|
|
|
max = 2
|
|
|
|
)
|
2011-09-19 05:14:43 +00:00
|
|
|
@CommandPermissions("worldedit.remove")
|
2011-08-08 12:40:02 +00:00
|
|
|
@Logging(PLACEMENT)
|
2011-12-18 07:45:12 +00:00
|
|
|
public void remove(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
2011-02-19 04:31:49 +00:00
|
|
|
|
|
|
|
String typeStr = args.getString(0);
|
|
|
|
int radius = args.getInteger(1);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 04:31:49 +00:00
|
|
|
if (radius < -1) {
|
|
|
|
player.printError("Use -1 to remove all entities in loaded chunks");
|
|
|
|
return;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 04:31:49 +00:00
|
|
|
EntityType type = null;
|
|
|
|
|
|
|
|
if (typeStr.matches("arrows?")) {
|
|
|
|
type = EntityType.ARROWS;
|
|
|
|
} else if (typeStr.matches("items?")
|
|
|
|
|| typeStr.matches("drops?")) {
|
|
|
|
type = EntityType.ITEMS;
|
|
|
|
} else if (typeStr.matches("paintings?")
|
|
|
|
|| typeStr.matches("art")) {
|
|
|
|
type = EntityType.PAINTINGS;
|
|
|
|
} else if (typeStr.matches("boats?")) {
|
|
|
|
type = EntityType.BOATS;
|
|
|
|
} else if (typeStr.matches("minecarts?")
|
|
|
|
|| typeStr.matches("carts?")) {
|
|
|
|
type = EntityType.MINECARTS;
|
|
|
|
} else if (typeStr.matches("tnt")) {
|
|
|
|
type = EntityType.TNT;
|
2011-09-17 05:33:42 +00:00
|
|
|
} else if (typeStr.matches("xp")) {
|
|
|
|
type = EntityType.XP_ORBS;
|
2011-02-19 04:31:49 +00:00
|
|
|
} else {
|
2011-09-17 05:33:42 +00:00
|
|
|
player.printError("Acceptable types: arrows, items, paintings, boats, minecarts, tnt, xp");
|
2011-02-19 04:31:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector origin = session.getPlacementPosition(player);
|
|
|
|
int removed = player.getWorld().removeEntities(type, origin, radius);
|
|
|
|
player.print("Marked " + removed + " entit(ies) for removal.");
|
|
|
|
}
|
2011-12-13 08:23:21 +00:00
|
|
|
|
|
|
|
@Command(
|
|
|
|
aliases = { "/help" },
|
|
|
|
usage = "[<command>]",
|
|
|
|
desc = "Displays help for the given command or lists all commands.",
|
|
|
|
min = 0,
|
|
|
|
max = -1
|
|
|
|
)
|
2011-12-15 12:28:25 +00:00
|
|
|
@Console
|
2011-12-22 10:35:43 +00:00
|
|
|
public void help(CommandContext args, LocalSession session, LocalPlayer player,
|
|
|
|
EditSession editSession) throws WorldEditException {
|
|
|
|
|
|
|
|
help(args, we, session, player, editSession);
|
|
|
|
}
|
2011-12-13 08:23:21 +00:00
|
|
|
|
2011-12-22 10:35:43 +00:00
|
|
|
public static void help(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) {
|
2011-12-13 08:23:21 +00:00
|
|
|
final CommandsManager<LocalPlayer> commandsManager = we.getCommandsManager();
|
|
|
|
|
|
|
|
if (args.argsLength() == 0) {
|
2011-12-15 05:28:09 +00:00
|
|
|
SortedSet<String> commands = new TreeSet<String>(new Comparator<String>() {
|
|
|
|
public int compare(String o1, String o2) {
|
|
|
|
final int ret = o1.replaceAll("/", "").compareToIgnoreCase(o2.replaceAll("/", ""));
|
|
|
|
if (ret == 0) {
|
|
|
|
return o1.compareToIgnoreCase(o2);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
commands.addAll(commandsManager.getCommands().keySet());
|
|
|
|
|
2011-12-13 08:23:21 +00:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
boolean first = true;
|
|
|
|
for (String command : commands) {
|
|
|
|
if (!first) {
|
|
|
|
sb.append(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
sb.append('/');
|
|
|
|
sb.append(command);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.print(sb.toString());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String command = args.getJoinedStrings(0).replaceAll("/", "");
|
|
|
|
|
|
|
|
String helpMessage = commandsManager.getHelpMessages().get(command);
|
|
|
|
if (helpMessage == null) {
|
|
|
|
player.printError("Unknown command '" + command + "'.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.print(helpMessage);
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|