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;
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
|
2019-07-25 18:44:10 +00:00
|
|
|
import static com.sk89q.worldedit.util.formatting.text.TextComponent.newline;
|
2019-07-06 00:46:48 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.Fawe;
|
|
|
|
import com.boydti.fawe.config.BBC;
|
|
|
|
import com.boydti.fawe.config.Settings;
|
|
|
|
import com.boydti.fawe.object.DelegateConsumer;
|
|
|
|
import com.boydti.fawe.object.FawePlayer;
|
|
|
|
import com.boydti.fawe.object.RunnableVal3;
|
|
|
|
import com.boydti.fawe.util.MainUtil;
|
|
|
|
import com.boydti.fawe.util.MathMan;
|
2018-09-06 20:40:13 +00:00
|
|
|
import com.boydti.fawe.util.image.ImageUtil;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.IncompleteRegionException;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
2019-07-18 17:10:04 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandQueued;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandQueuedConditionGenerator;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CreatureButcher;
|
|
|
|
import com.sk89q.worldedit.command.util.EntityRemover;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.command.util.Logging;
|
|
|
|
import com.sk89q.worldedit.command.util.PrintCommandHelp;
|
|
|
|
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
2014-06-28 00:55:39 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Capability;
|
|
|
|
import com.sk89q.worldedit.extension.platform.Platform;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
2019-01-31 15:08:58 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.function.EntityFunction;
|
|
|
|
import com.sk89q.worldedit.function.mask.BlockTypeMask;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
|
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
2018-06-15 05:41:37 +00:00
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.function.visitor.EntityVisitor;
|
2019-07-22 02:49:08 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.Range;
|
2014-07-03 10:34:19 +00:00
|
|
|
import com.sk89q.worldedit.internal.expression.Expression;
|
|
|
|
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
2019-08-06 20:18:44 +00:00
|
|
|
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
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;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
|
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
2019-07-25 18:44:10 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent.Builder;
|
|
|
|
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
|
|
|
|
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
2019-07-06 00:46:48 +00:00
|
|
|
import java.awt.RenderingHints;
|
2018-09-06 20:40:13 +00:00
|
|
|
import java.awt.image.BufferedImage;
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.io.File;
|
2018-09-06 20:40:13 +00:00
|
|
|
import java.io.IOException;
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.net.URI;
|
2018-09-06 20:40:13 +00:00
|
|
|
import java.nio.file.Files;
|
2019-07-06 00:46:48 +00:00
|
|
|
import java.text.DecimalFormat;
|
|
|
|
import java.text.NumberFormat;
|
|
|
|
import java.util.ArrayList;
|
2018-09-06 20:40:13 +00:00
|
|
|
import java.util.List;
|
2019-07-06 00:46:48 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.UUID;
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.util.function.Consumer;
|
2019-07-06 00:46:48 +00:00
|
|
|
import java.util.function.Supplier;
|
|
|
|
import javax.imageio.ImageIO;
|
2019-07-28 19:26:44 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
|
|
|
import org.enginehub.piston.annotation.param.ArgFlag;
|
|
|
|
import org.enginehub.piston.annotation.param.Switch;
|
2019-07-28 19:26:44 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
/**
|
|
|
|
* Utility commands.
|
|
|
|
*/
|
2019-08-06 20:24:05 +00:00
|
|
|
@CommandContainer(superTypes = {
|
|
|
|
// CommandQueuedConditionGenerator.Registration.class,
|
|
|
|
CommandPermissionsConditionGenerator.Registration.class // TODO NOT IMPLEMENTED - Piston doesn't seem to work with multiple conditions???
|
|
|
|
})
|
2019-07-06 00:46:48 +00:00
|
|
|
public class UtilityCommands {
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2019-04-03 11:28:57 +00:00
|
|
|
private final WorldEdit we;
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
public UtilityCommands(WorldEdit we) {
|
2019-04-03 11:28:57 +00:00
|
|
|
this.we = we;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/heightmapinterface",
|
2018-09-07 15:09:31 +00:00
|
|
|
desc = "Generate the heightmap interface: https://github.com/boy0001/HeightMap"
|
2018-09-06 20:40:13 +00:00
|
|
|
)
|
2018-10-04 18:42:43 +00:00
|
|
|
@CommandPermissions("fawe.admin")
|
2019-07-17 06:11:55 +00:00
|
|
|
public void heightmapInterface(Player player, @Arg(name = "min", desc = "int", def = "100") int min, @Arg(name = "max", desc = "int", def = "200") int max) throws IOException {
|
2019-06-08 00:58:48 +00:00
|
|
|
player.print("Please wait while we generate the minified heightmaps.");
|
2018-09-06 20:40:13 +00:00
|
|
|
File srcFolder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP);
|
|
|
|
|
|
|
|
File webSrc = new File(Fawe.imp().getDirectory(), "web" + File.separator + "heightmap");
|
|
|
|
File minImages = new File(webSrc, "images" + File.separator + "min");
|
|
|
|
File maxImages = new File(webSrc, "images" + File.separator + "max");
|
|
|
|
final int sub = srcFolder.getAbsolutePath().length();
|
|
|
|
List<String> images = new ArrayList<>();
|
2019-03-28 19:02:37 +00:00
|
|
|
MainUtil.iterateFiles(srcFolder, file -> {
|
|
|
|
switch (file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase()) {
|
|
|
|
case ".png":
|
|
|
|
case ".jpeg":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
String name = file.getAbsolutePath().substring(sub);
|
|
|
|
if (name.startsWith(File.separator)) name = name.replaceFirst(java.util.regex.Pattern.quote(File.separator), "");
|
|
|
|
BufferedImage img = MainUtil.readImage(file);
|
|
|
|
BufferedImage minImg = ImageUtil.getScaledInstance(img, min, min, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
|
|
|
|
BufferedImage maxImg = max == -1 ? img : ImageUtil.getScaledInstance(img, max, max, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
|
2019-06-08 00:58:48 +00:00
|
|
|
player.print("Writing " + name);
|
2019-03-28 19:02:37 +00:00
|
|
|
File minFile = new File(minImages, name);
|
|
|
|
File maxFile = new File(maxImages, name);
|
|
|
|
minFile.getParentFile().mkdirs();
|
|
|
|
maxFile.getParentFile().mkdirs();
|
|
|
|
ImageIO.write(minImg, "png", minFile);
|
|
|
|
ImageIO.write(maxImg, "png", maxFile);
|
|
|
|
images.add(name);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
2018-09-06 20:40:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
StringBuilder config = new StringBuilder();
|
|
|
|
config.append("var images = [\n");
|
|
|
|
for (String image : images) {
|
|
|
|
config.append('"' + image.replace(File.separator, "/") + "\",\n");
|
|
|
|
}
|
|
|
|
config.append("];\n");
|
|
|
|
config.append("// The low res images (they should all be the same size)\n");
|
|
|
|
config.append("var src_min = \"images/min/\";\n");
|
|
|
|
config.append("// The max resolution images (Use the same if there are no higher resolution ones available)\n");
|
|
|
|
config.append("var src_max = \"images/max/\";\n");
|
|
|
|
config.append("// The local source for the image (used in commands)\n");
|
|
|
|
config.append("var src_local = \"file://\";\n");
|
|
|
|
File configFile = new File(webSrc, "config.js");
|
2019-06-08 00:58:48 +00:00
|
|
|
player.print("Writing " + configFile);
|
2018-09-06 20:40:13 +00:00
|
|
|
Files.write(configFile.toPath(), config.toString().getBytes());
|
2019-06-08 00:58:48 +00:00
|
|
|
player.print("Done! See: `FastAsyncWorldEdit/web/heightmap`");
|
2018-09-06 20:40:13 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 09:33:52 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/cancel",
|
|
|
|
aliases= {"fcancel"},
|
|
|
|
desc = "Cancel your current command"
|
2018-08-24 09:33:52 +00:00
|
|
|
)
|
2019-06-12 22:48:40 +00:00
|
|
|
@CommandPermissions("fawe.cancel")
|
2019-07-18 17:10:04 +00:00
|
|
|
@CommandQueued(false)
|
2019-08-06 15:32:05 +00:00
|
|
|
public void cancel(FawePlayer fp) {
|
|
|
|
int cancelled = fp.cancel(false);
|
|
|
|
BBC.WORLDEDIT_CANCEL_COUNT.send(fp, cancelled);
|
2018-08-24 09:33:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/fill",
|
|
|
|
desc = "Fill a hole"
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fill")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int fill(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The blocks to fill with")
|
|
|
|
Pattern pattern,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The radius to fill in")
|
2019-08-06 20:18:44 +00:00
|
|
|
Expression radiusExp,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The depth to fill", def = "1")
|
2019-07-25 18:44:10 +00:00
|
|
|
int depth,
|
2019-08-06 20:18:44 +00:00
|
|
|
@Arg(desc = "Direction to fill", def = "down") BlockVector3 direction) throws WorldEditException, EvaluationException {
|
|
|
|
double radius = radiusExp.evaluate();
|
2019-07-25 18:44:10 +00:00
|
|
|
radius = Math.max(1, radius);
|
2019-06-12 21:12:12 +00:00
|
|
|
we.checkMaxRadius(radius);
|
2019-07-25 18:44:10 +00:00
|
|
|
depth = Math.max(1, depth);
|
2019-07-06 00:46:48 +00:00
|
|
|
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(player);
|
2019-07-06 00:46:48 +00:00
|
|
|
int affected = editSession.fillDirection(pos, pattern, radius, depth, direction);
|
2019-06-12 21:12:12 +00:00
|
|
|
player.print(affected + " block(s) have been created.");
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
/*
|
2014-04-03 02:08:50 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "patterns",
|
|
|
|
desc = "View help about patterns",
|
2019-07-17 05:43:18 +00:00
|
|
|
descFooter = "Patterns determine what blocks are placed\n" +
|
2019-07-06 00:46:48 +00:00
|
|
|
" - Use [brackets] for arguments\n" +
|
|
|
|
" - Use , to OR multiple\n" +
|
|
|
|
"e.g. #surfacespread[10][#existing],andesite\n" +
|
|
|
|
"More Info: https://git.io/vSPmA"
|
|
|
|
)
|
2019-07-18 17:10:04 +00:00
|
|
|
@CommandQueued(false)
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandPermissions("worldedit.patterns")
|
2019-07-18 20:03:27 +00:00
|
|
|
public void patterns(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
2019-07-06 00:46:48 +00:00
|
|
|
displayModifierHelp(player, DefaultPatternParser.class, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
name = "masks",
|
|
|
|
desc = "View help about masks",
|
2019-07-17 05:43:18 +00:00
|
|
|
descFooter = "Masks determine if a block can be placed\n" +
|
2019-07-06 00:46:48 +00:00
|
|
|
" - Use [brackets] for arguments\n" +
|
|
|
|
" - Use , to OR multiple\n" +
|
|
|
|
" - Use & to AND multiple\n" +
|
|
|
|
"e.g. >[stone,dirt],#light[0][5],$jungle\n" +
|
|
|
|
"More Info: https://git.io/v9r4K"
|
|
|
|
)
|
2019-07-18 17:10:04 +00:00
|
|
|
@CommandQueued(false)
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandPermissions("worldedit.masks")
|
2019-07-18 20:03:27 +00:00
|
|
|
public void masks(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
2019-07-06 00:46:48 +00:00
|
|
|
displayModifierHelp(player, DefaultMaskParser.class, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
name = "transforms",
|
|
|
|
desc = "View help about transforms",
|
2019-07-17 05:43:18 +00:00
|
|
|
descFooter = "Transforms modify how a block is placed\n" +
|
2019-07-06 00:46:48 +00:00
|
|
|
" - Use [brackets] for arguments\n" +
|
|
|
|
" - Use , to OR multiple\n" +
|
|
|
|
" - Use & to AND multiple\n" +
|
|
|
|
"More Info: https://git.io/v9KHO",
|
|
|
|
)
|
2019-07-18 17:10:04 +00:00
|
|
|
@CommandQueued(false)
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandPermissions("worldedit.transforms")
|
2019-07-18 20:03:27 +00:00
|
|
|
public void transforms(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
2019-07-06 00:46:48 +00:00
|
|
|
displayModifierHelp(player, DefaultTransformParser.class, args);
|
|
|
|
}
|
|
|
|
|
2019-07-18 20:03:27 +00:00
|
|
|
private void displayModifierHelp(Player player, Class<? extends FaweParser> clazz, InjectedValueAccess args) {
|
2019-07-06 00:46:48 +00:00
|
|
|
FaweParser parser = FaweAPI.getParser(clazz);
|
|
|
|
if (args.argsLength() == 0) {
|
|
|
|
String base = getCommand().aliases()[0];
|
|
|
|
UsageMessage msg = new UsageMessage(getCallable(), "/" + base, args.getLocals());
|
|
|
|
msg.newline().paginate(base, 0, 1).send(player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parser != null) {
|
|
|
|
CommandMapping mapping = parser.getDispatcher().get(args.getString(0));
|
|
|
|
if (mapping != null) {
|
|
|
|
new UsageMessage(mapping.getCallable(), args.getString(0), args.getLocals()) {
|
|
|
|
@Override
|
|
|
|
public String separateArg(String arg) {
|
|
|
|
return "&7[" + arg + "&7]";
|
|
|
|
}
|
|
|
|
}.send(player);
|
|
|
|
} else {
|
|
|
|
UtilityCommands.help(args, player, getCommand().aliases()[0] + " ", parser.getDispatcher());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
name = "/fillr",
|
|
|
|
desc = "Fill a hole recursively"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fill.recursive")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int fillr(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The blocks to fill with")
|
|
|
|
Pattern pattern,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The radius to fill in")
|
2019-08-06 20:18:44 +00:00
|
|
|
Expression radiusExp,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Arg(desc = "The depth to fill", def = "")
|
2019-08-06 20:18:44 +00:00
|
|
|
Integer depth) throws WorldEditException, EvaluationException {
|
|
|
|
double radius = radiusExp.evaluate();
|
2019-07-25 18:44:10 +00:00
|
|
|
radius = Math.max(1, radius);
|
2019-07-06 00:46:48 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
depth = depth == null ? Integer.MAX_VALUE : Math.max(1, depth);
|
2019-06-12 21:12:12 +00:00
|
|
|
we.checkMaxRadius(radius);
|
2019-07-06 00:46:48 +00:00
|
|
|
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(player);
|
2019-07-06 00:46:48 +00:00
|
|
|
int affected = editSession.fillXZ(pos, pattern, radius, depth, true);
|
2019-06-12 21:12:12 +00:00
|
|
|
player.print(affected + " block(s) have been created.");
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/drain",
|
|
|
|
desc = "Drain a pool"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.drain")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int drain(Player player, LocalSession session, EditSession editSession,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=0) @Arg(desc = "The radius to drain")
|
2019-08-06 20:18:44 +00:00
|
|
|
Expression radiusExp,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Switch(name = 'w', desc = "Also un-waterlog blocks")
|
2019-08-06 20:18:44 +00:00
|
|
|
boolean waterlogged) throws WorldEditException, EvaluationException {
|
|
|
|
double radius = radiusExp.evaluate();
|
2019-07-25 18:44:10 +00:00
|
|
|
radius = Math.max(0, radius);
|
2019-06-12 21:12:12 +00:00
|
|
|
we.checkMaxRadius(radius);
|
2014-04-03 02:08:50 +00:00
|
|
|
int affected = editSession.drainArea(
|
2019-07-06 00:46:48 +00:00
|
|
|
session.getPlacementPosition(player), radius, waterlogged);
|
2019-06-12 21:12:12 +00:00
|
|
|
player.print(affected + " block(s) have been changed.");
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "fixlava",
|
|
|
|
aliases = { "/fixlava" },
|
|
|
|
desc = "Fix lava to be stationary"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fixlava")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int fixLava(Player player, LocalSession session, EditSession editSession,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=0) @Arg(desc = "The radius to fix in")
|
2019-08-06 20:18:44 +00:00
|
|
|
Expression radiusExp) throws WorldEditException, EvaluationException {
|
|
|
|
double radius = radiusExp.evaluate();
|
2019-07-25 18:44:10 +00:00
|
|
|
radius = Math.max(0, radius);
|
2019-06-12 21:12:12 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.LAVA);
|
|
|
|
player.print(affected + " block(s) have been changed.");
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "fixwater",
|
|
|
|
aliases = { "/fixwater" },
|
|
|
|
desc = "Fix water to be stationary"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fixwater")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int fixWater(Player player, LocalSession session, EditSession editSession,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=0) @Arg(desc = "The radius to fix in")
|
2019-08-06 20:18:44 +00:00
|
|
|
Expression radiusExp) throws WorldEditException, EvaluationException {
|
|
|
|
double radius = radiusExp.evaluate();
|
2019-07-23 02:22:32 +00:00
|
|
|
radius = Math.max(0, radius);
|
2019-06-12 21:12:12 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.WATER);
|
2019-04-05 16:04:27 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(player, affected);
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "removeabove",
|
|
|
|
aliases = { "/removeabove" },
|
|
|
|
desc = "Remove blocks above your head."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.removeabove")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int removeAbove(Player player, LocalSession session, EditSession editSession,
|
2019-08-06 15:32:05 +00:00
|
|
|
@Range(min=1) @Arg(name = "size", desc = "The apothem of the square to remove from", def = "1")
|
|
|
|
int sizeOpt,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Arg(desc = "The maximum height above you to remove from", def = "")
|
|
|
|
Integer height) throws WorldEditException {
|
2019-08-06 15:32:05 +00:00
|
|
|
sizeOpt = Math.max(1, sizeOpt);
|
|
|
|
we.checkMaxRadius(sizeOpt);
|
2019-07-25 18:44:10 +00:00
|
|
|
World world = player.getWorld();
|
|
|
|
height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1);
|
2019-08-06 15:32:05 +00:00
|
|
|
int affected = editSession.removeAbove(session.getPlacementPosition(player), sizeOpt, height);
|
2019-04-05 16:04:27 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(player, affected);
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "removebelow",
|
|
|
|
aliases = { "/removebelow" },
|
|
|
|
desc = "Remove blocks below you."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.removebelow")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int removeBelow(Player player, LocalSession session, EditSession editSession,
|
2019-08-06 15:32:05 +00:00
|
|
|
@Arg(name = "size", desc = "The apothem of the square to remove from", def = "1")
|
|
|
|
int sizeOpt,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Arg(desc = "The maximum height below you to remove from", def = "")
|
|
|
|
Integer height) throws WorldEditException {
|
2019-08-06 15:32:05 +00:00
|
|
|
sizeOpt = Math.max(1, sizeOpt);
|
|
|
|
we.checkMaxRadius(sizeOpt);
|
2019-07-06 00:46:48 +00:00
|
|
|
World world = player.getWorld();
|
|
|
|
height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1);
|
|
|
|
|
2019-08-06 15:32:05 +00:00
|
|
|
int affected = editSession.removeBelow(session.getPlacementPosition(player), sizeOpt, height);
|
2019-04-05 16:04:27 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(player, affected);
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "removenear",
|
|
|
|
aliases = { "/removenear" },
|
|
|
|
desc = "Remove blocks near you."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.removenear")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int removeNear(Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The mask of blocks to remove")
|
|
|
|
Mask mask,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The radius of the square to remove from", def = "50")
|
2019-07-25 18:44:10 +00:00
|
|
|
int radius) throws WorldEditException {
|
|
|
|
radius = Math.max(1, radius);
|
2019-07-06 00:46:48 +00:00
|
|
|
we.checkMaxRadius(radius);
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
int affected = editSession.removeNear(session.getPlacementPosition(player), mask, radius);
|
2019-04-05 16:04:27 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(player, affected);
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "replacenear",
|
|
|
|
aliases = { "/replacenear" },
|
|
|
|
desc = "Replace nearby blocks"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.replacenear")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int replaceNear(Player player, LocalSession session, EditSession editSession,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The radius of the square to remove in")
|
2019-07-25 18:44:10 +00:00
|
|
|
int radius,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Arg(desc = "The mask matching blocks to remove", def = "")
|
|
|
|
Mask from,
|
|
|
|
@Arg(desc = "The pattern of blocks to replace with")
|
|
|
|
Pattern to) throws WorldEditException {
|
2019-07-25 18:44:10 +00:00
|
|
|
radius = Math.max(1, radius);
|
2019-07-06 00:46:48 +00:00
|
|
|
we.checkMaxRadius(radius);
|
|
|
|
|
|
|
|
BlockVector3 base = session.getPlacementPosition(player);
|
|
|
|
BlockVector3 min = base.subtract(radius, radius, radius);
|
|
|
|
BlockVector3 max = base.add(radius, radius, radius);
|
|
|
|
Region region = new CuboidRegion(player.getWorld(), min, max);
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
if (from == null) {
|
|
|
|
from = new ExistingBlockMask(editSession);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
int affected = editSession.replaceBlocks(region, from, to);
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(player, affected);
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "snow",
|
|
|
|
aliases = { "/snow" },
|
|
|
|
desc = "Simulates snow"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.snow")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int snow(Player player, LocalSession session, EditSession editSession,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The radius of the circle to snow in", def = "10")
|
2019-08-06 20:18:44 +00:00
|
|
|
double sizeOpt) throws WorldEditException {
|
|
|
|
sizeOpt = Math.max(1, sizeOpt);
|
|
|
|
we.checkMaxRadius(sizeOpt);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-08-06 20:18:44 +00:00
|
|
|
int affected = editSession.simulateSnow(session.getPlacementPosition(player), sizeOpt);
|
2019-07-25 18:44:10 +00:00
|
|
|
player.print(affected + " surface(s) covered. Let it snow~");
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "thaw",
|
|
|
|
aliases = { "/thaw" },
|
|
|
|
desc = "Thaws the area"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.thaw")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int thaw(Player player, LocalSession session, EditSession editSession,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The radius of the circle to thaw in", def = "10")
|
2019-08-06 20:18:44 +00:00
|
|
|
double sizeOpt) throws WorldEditException {
|
|
|
|
sizeOpt = Math.max(1, sizeOpt);
|
|
|
|
we.checkMaxRadius(sizeOpt);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-08-06 20:18:44 +00:00
|
|
|
int affected = editSession.thaw(session.getPlacementPosition(player), sizeOpt);
|
2019-07-25 18:44:10 +00:00
|
|
|
player.print(affected + " surface(s) thawed.");
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "green",
|
|
|
|
aliases = { "/green" },
|
|
|
|
desc = "Converts dirt to grass blocks in the area"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.green")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int green(Player player, LocalSession session, EditSession editSession,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The radius of the circle to convert in", def = "10")
|
2019-08-06 20:18:44 +00:00
|
|
|
double sizeOpt,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Switch(name = 'f', desc = "Also convert coarse dirt")
|
|
|
|
boolean convertCoarse) throws WorldEditException {
|
2019-08-06 20:18:44 +00:00
|
|
|
sizeOpt = Math.max(1, sizeOpt);
|
|
|
|
we.checkMaxRadius(sizeOpt);
|
2019-07-06 00:46:48 +00:00
|
|
|
final boolean onlyNormalDirt = !convertCoarse;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-08-06 20:18:44 +00:00
|
|
|
final int affected = editSession.green(session.getPlacementPosition(player), sizeOpt, onlyNormalDirt);
|
2019-04-05 16:04:27 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(player, affected);
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "extinguish",
|
|
|
|
aliases = { "/ex", "/ext", "/extinguish", "ex", "ext" },
|
|
|
|
desc = "Extinguish nearby fire"
|
|
|
|
)
|
2014-04-03 02:08:50 +00:00
|
|
|
@CommandPermissions("worldedit.extinguish")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void extinguish(Player player, LocalSession session, EditSession editSession,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=1) @Arg(desc = "The radius of the square to remove in", def = "")
|
2019-07-25 18:44:10 +00:00
|
|
|
Integer radius) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-06-12 21:12:12 +00:00
|
|
|
LocalConfiguration config = we.getConfiguration();
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
|
2019-07-25 18:44:10 +00:00
|
|
|
int size = radius != null ? Math.max(1, radius) : defaultRadius;
|
2019-06-12 21:12:12 +00:00
|
|
|
we.checkMaxRadius(size);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE);
|
|
|
|
int affected = editSession.removeNear(session.getPlacementPosition(player), mask, size);
|
2019-04-05 16:04:27 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(player, affected);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "butcher",
|
|
|
|
desc = "Kill all or nearby mobs"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.butcher")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int butcher(Actor actor,
|
|
|
|
@Arg(desc = "Radius to kill mobs in", def = "")
|
|
|
|
Integer radius,
|
|
|
|
@Switch(name = 'p', desc = "Also kill pets")
|
|
|
|
boolean killPets,
|
|
|
|
@Switch(name = 'n', desc = "Also kill NPCs")
|
|
|
|
boolean killNpcs,
|
|
|
|
@Switch(name = 'g', desc = "Also kill golems")
|
|
|
|
boolean killGolems,
|
|
|
|
@Switch(name = 'a', desc = "Also kill animals")
|
|
|
|
boolean killAnimals,
|
|
|
|
@Switch(name = 'b', desc = "Also kill ambient mobs")
|
|
|
|
boolean killAmbient,
|
|
|
|
@Switch(name = 't', desc = "Also kill mobs with name tags")
|
|
|
|
boolean killWithName,
|
|
|
|
@Switch(name = 'f', desc = "Also kill all friendly mobs (Applies the flags `-abgnpt`)")
|
|
|
|
boolean killFriendly,
|
|
|
|
@Switch(name = 'r', desc = "Also destroy armor stands")
|
|
|
|
boolean killArmorStands) throws WorldEditException {
|
2019-06-12 21:12:12 +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
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
if (radius == null) {
|
|
|
|
radius = config.butcherDefaultRadius;
|
|
|
|
} else if (radius < -1) {
|
|
|
|
actor.printError("Use -1 to remove all mobs in loaded chunks");
|
|
|
|
return 0;
|
|
|
|
} else if (radius == -1) {
|
|
|
|
if (config.butcherMaxRadius != -1) {
|
|
|
|
radius = config.butcherMaxRadius;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
if (config.butcherMaxRadius != -1) {
|
|
|
|
radius = Math.min(radius, config.butcherMaxRadius);
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
CreatureButcher flags = new CreatureButcher(actor);
|
2019-07-06 00:46:48 +00:00
|
|
|
flags.or(CreatureButcher.Flags.FRIENDLY, killFriendly); // No permission check here. Flags will instead be filtered by the subsequent calls.
|
|
|
|
flags.or(CreatureButcher.Flags.PETS, killPets, "worldedit.butcher.pets");
|
|
|
|
flags.or(CreatureButcher.Flags.NPCS, killNpcs, "worldedit.butcher.npcs");
|
|
|
|
flags.or(CreatureButcher.Flags.GOLEMS, killGolems, "worldedit.butcher.golems");
|
|
|
|
flags.or(CreatureButcher.Flags.ANIMALS, killAnimals, "worldedit.butcher.animals");
|
|
|
|
flags.or(CreatureButcher.Flags.AMBIENT, killAmbient, "worldedit.butcher.ambient");
|
|
|
|
flags.or(CreatureButcher.Flags.TAGGED, killWithName, "worldedit.butcher.tagged");
|
|
|
|
flags.or(CreatureButcher.Flags.ARMOR_STAND, killArmorStands, "worldedit.butcher.armorstands");
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
int killed = killMatchingEntities(radius, player, flags::createFunction);
|
2014-07-16 02:47:47 +00:00
|
|
|
|
2019-07-06 00:46:48 +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
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
return killed;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "remove",
|
|
|
|
aliases = { "rem", "rement" },
|
|
|
|
desc = "Remove all entities of a type"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.remove")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int remove(Actor actor,
|
|
|
|
@Arg(desc = "The type of entity to remove")
|
|
|
|
EntityRemover remover,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min=-1) @Arg(desc = "The radius of the cuboid to remove from")
|
2019-07-06 00:46:48 +00:00
|
|
|
int radius) throws WorldEditException {
|
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");
|
2019-07-06 00:46:48 +00:00
|
|
|
return 0;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
int removed = killMatchingEntities(radius, player, remover::createFunction);
|
|
|
|
|
|
|
|
actor.print("Marked " + removed + (removed != 1 ? " entities" : " entity") + " for removal.");
|
|
|
|
return removed;
|
|
|
|
}
|
2014-07-16 02:47:47 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
private int killMatchingEntities(Integer radius, Player player, Supplier<EntityFunction> func) throws IncompleteRegionException, MaxChangedBlocksException {
|
2019-02-16 02:46:10 +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) {
|
2019-06-12 21:12:12 +00:00
|
|
|
session = we.getSessionManager().get(player);
|
2018-12-23 16:19:33 +00:00
|
|
|
BlockVector3 center = session.getPlacementPosition(player);
|
2014-07-16 02:47:47 +00:00
|
|
|
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();
|
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
visitors.add(new EntityVisitor(entities.iterator(), func.get()));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2019-06-12 21:12:12 +00:00
|
|
|
Platform platform = we.getPlatformManager().queryCapability(Capability.WORLD_EDITING);
|
2014-07-16 02:47:47 +00:00
|
|
|
for (World world : platform.getWorlds()) {
|
|
|
|
List<? extends Entity> entities = world.getEntities();
|
2019-07-06 00:46:48 +00:00
|
|
|
visitors.add(new EntityVisitor(entities.iterator(), func.get()));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-16 02:47:47 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
int killed = 0;
|
2014-07-16 02:47:47 +00:00
|
|
|
for (EntityVisitor visitor : visitors) {
|
|
|
|
Operations.completeLegacy(visitor);
|
2019-07-06 00:46:48 +00:00
|
|
|
killed += visitor.getAffected();
|
2014-07-16 02:47:47 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
BBC.KILL_SUCCESS.send(player, killed, radius);
|
2014-07-16 02:47:47 +00:00
|
|
|
|
|
|
|
if (editSession != null) {
|
|
|
|
session.remember(editSession);
|
2018-10-21 01:54:58 +00:00
|
|
|
editSession.flushSession();
|
2014-07-16 02:47:47 +00:00
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
return killed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the formatter with the system locale. in the future, if we can get a local from a player, we can use that
|
|
|
|
private static final DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.getDefault());
|
|
|
|
static {
|
|
|
|
formatter.applyPattern("#,##0.#####"); // pattern is locale-insensitive. this can translate to "1.234,56789"
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 10:34:19 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/calculate",
|
|
|
|
aliases = { "/calc", "/eval", "/evaluate", "/solve" },
|
2019-06-12 21:12:12 +00:00
|
|
|
desc = "Evaluate a mathematical expression"
|
2014-07-03 10:34:19 +00:00
|
|
|
)
|
2015-12-21 21:14:44 +00:00
|
|
|
@CommandPermissions("worldedit.calc")
|
2019-07-06 00:46:48 +00:00
|
|
|
public void calc(Actor actor,
|
|
|
|
@Arg(desc = "Expression to evaluate", variable = true)
|
|
|
|
List<String> input) {
|
|
|
|
Expression expression;
|
2014-07-03 10:34:19 +00:00
|
|
|
try {
|
2019-07-06 00:46:48 +00:00
|
|
|
expression = Expression.compile(String.join(" ", input));
|
2014-07-03 10:34:19 +00:00
|
|
|
} catch (ExpressionException e) {
|
|
|
|
actor.printError(String.format(
|
2019-07-06 00:46:48 +00:00
|
|
|
"'%s' could not be parsed as a valid expression", input));
|
|
|
|
return;
|
2014-07-03 10:34:19 +00:00
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> {
|
2019-07-25 18:44:10 +00:00
|
|
|
double result = expression.evaluate(
|
|
|
|
new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout());
|
2019-07-06 00:46:48 +00:00
|
|
|
String formatted = Double.isNaN(result) ? "NaN" : formatter.format(result);
|
|
|
|
return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE));
|
|
|
|
}, null);
|
2014-07-03 10:34:19 +00:00
|
|
|
}
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/confirm",
|
2018-08-12 14:03:07 +00:00
|
|
|
desc = "Confirm a command"
|
|
|
|
)
|
2019-06-12 22:48:40 +00:00
|
|
|
@CommandPermissions("fawe.confirm")
|
2018-08-12 14:03:07 +00:00
|
|
|
public void confirm(FawePlayer fp) throws WorldEditException {
|
|
|
|
if (!fp.confirm()) {
|
|
|
|
BBC.NOTHING_CONFIRMED.send(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/help",
|
|
|
|
desc = "Displays help for WorldEdit commands"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2019-06-12 21:12:12 +00:00
|
|
|
@CommandPermissions("worldedit.help")
|
2019-07-06 00:46:48 +00:00
|
|
|
public void help(Actor actor,
|
|
|
|
@Switch(name = 's', desc = "List sub-commands of the given command, if applicable")
|
|
|
|
boolean listSubCommands,
|
|
|
|
@ArgFlag(name = 'p', desc = "The page to retrieve", def = "1")
|
|
|
|
int page,
|
|
|
|
@Arg(desc = "The command to retrieve help for", def = "", variable = true)
|
2019-08-06 20:18:44 +00:00
|
|
|
List<String> commandStr) throws WorldEditException {
|
|
|
|
PrintCommandHelp.help(commandStr, page, listSubCommands, we, actor);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-28 19:26:44 +00:00
|
|
|
public static void list(File dir, Actor actor, List<String> args, @Range(min = 0) int page, String formatName, boolean playerFolder, String onClickCmd) {
|
|
|
|
list(dir, actor, args, page, -1, formatName, playerFolder, false, false, new RunnableVal3<Builder, URI, String>() {
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
2019-07-25 18:44:10 +00:00
|
|
|
public void run(Builder m, URI uri, String fileName) {
|
|
|
|
m.append(BBC.SCHEMATIC_LIST_ELEM.format(fileName, ""));
|
|
|
|
if (onClickCmd != null) { m.hoverEvent(HoverEvent.showText(TextComponent.of(onClickCmd + " " + fileName)))
|
|
|
|
.clickEvent(ClickEvent.runCommand(onClickCmd + " " + fileName));
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-07-01 04:56:05 +00:00
|
|
|
|
2019-07-28 19:26:44 +00:00
|
|
|
public static void list(File dir, Actor actor, List<String> args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, boolean oldFirst, boolean newFirst, RunnableVal3<Builder, URI, String> eachMsg) {
|
2018-08-12 14:03:07 +00:00
|
|
|
List<File> fileList = new ArrayList<>();
|
|
|
|
if (perPage == -1) perPage = actor instanceof Player ? 12 : 20; // More pages for console
|
2019-06-12 21:12:12 +00:00
|
|
|
page = getFiles(dir, actor, args, page, perPage, formatName, playerFolder, fileList::add);
|
2014-07-01 04:56:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
if (fileList.isEmpty()) {
|
|
|
|
BBC.SCHEMATIC_NONE.send(actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pageCount = (fileList.size() + perPage - 1) / perPage;
|
|
|
|
if (page < 1) {
|
|
|
|
BBC.SCHEMATIC_PAGE.send(actor, ">0");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (page > pageCount) {
|
|
|
|
BBC.SCHEMATIC_PAGE.send(actor, "<" + (pageCount + 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-28 19:26:44 +00:00
|
|
|
final int sortType = oldFirst ? -1 : newFirst ? 1 : 0;
|
2018-08-12 14:03:07 +00:00
|
|
|
// cleanup file list
|
2019-03-28 19:02:37 +00:00
|
|
|
fileList.sort((f1, f2) -> {
|
|
|
|
boolean dir1 = f1.isDirectory();
|
|
|
|
boolean dir2 = f2.isDirectory();
|
|
|
|
if (dir1 != dir2)
|
|
|
|
return dir1 ? -1 : 1;
|
|
|
|
int res;
|
|
|
|
if (sortType == 0) { // use name by default
|
|
|
|
int p = f1.getParent().compareTo(f2.getParent());
|
|
|
|
if (p == 0) { // same parent, compare names
|
|
|
|
res = f1.getName().compareTo(f2.getName());
|
|
|
|
} else { // different parent, sort by that
|
|
|
|
res = p;
|
2014-07-01 04:56:05 +00:00
|
|
|
}
|
2019-03-28 19:02:37 +00:00
|
|
|
} else {
|
|
|
|
res = Long.compare(f1.lastModified(), f2.lastModified()); // use date if there is a flag
|
|
|
|
if (sortType == 1)
|
|
|
|
res = -res; // flip date for newest first instead of oldest first
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-03-28 19:02:37 +00:00
|
|
|
return res;
|
2018-08-12 14:03:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
int offset = (page - 1) * perPage;
|
2014-07-01 04:56:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
int limit = Math.min(offset + perPage, fileList.size());
|
|
|
|
|
2019-07-28 19:26:44 +00:00
|
|
|
// String fullArgs = (String) args.getLocals().get("arguments");
|
|
|
|
// String baseCmd = null;
|
|
|
|
// if (fullArgs != null) {
|
|
|
|
// baseCmd = fullArgs.endsWith(" " + page) ? fullArgs.substring(0, fullArgs.length() - (" " + page).length()) : fullArgs;
|
|
|
|
// }
|
|
|
|
@NotNull Builder m = TextComponent.builder(BBC.SCHEMATIC_LIST.format(page, pageCount));
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
UUID uuid = playerFolder ? actor.getUniqueId() : null;
|
|
|
|
for (int i = offset; i < limit; i++) {
|
2019-07-25 18:44:10 +00:00
|
|
|
m.append(newline());
|
2018-08-12 14:03:07 +00:00
|
|
|
File file = fileList.get(i);
|
|
|
|
eachMsg.run(m, file.toURI(), getPath(dir, file, uuid));
|
|
|
|
}
|
2019-07-28 19:26:44 +00:00
|
|
|
// if (baseCmd != null) {
|
|
|
|
// //TODO m.newline().paginate(baseCmd, page, pageCount);
|
|
|
|
// }
|
2019-07-25 18:44:10 +00:00
|
|
|
actor.print(m.build());
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-28 19:26:44 +00:00
|
|
|
public static int getFiles(File dir, Actor actor, List<String> args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, Consumer<File> forEachFile) {
|
2018-08-12 14:03:07 +00:00
|
|
|
Consumer<File> rootFunction = forEachFile;
|
2019-07-20 05:32:15 +00:00
|
|
|
//schem list all <path>
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2019-07-28 19:26:44 +00:00
|
|
|
int len = args.size();
|
2018-08-12 14:03:07 +00:00
|
|
|
List<String> filters = new ArrayList<>();
|
|
|
|
|
|
|
|
String dirFilter = File.separator;
|
|
|
|
|
|
|
|
boolean listMine = false;
|
|
|
|
boolean listGlobal = !Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS;
|
|
|
|
if (len > 0) {
|
|
|
|
int max = len;
|
2019-07-28 19:26:44 +00:00
|
|
|
if (MathMan.isInteger(args.get(len - 1))) {
|
|
|
|
page = Integer.parseInt(args.get(--len));
|
2014-07-01 04:56:05 +00:00
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2019-07-23 20:26:18 +00:00
|
|
|
String arg = "";
|
2018-08-12 14:03:07 +00:00
|
|
|
switch (arg.toLowerCase()) {
|
|
|
|
case "me":
|
|
|
|
case "mine":
|
|
|
|
case "local":
|
|
|
|
case "private":
|
|
|
|
listMine = true;
|
|
|
|
break;
|
|
|
|
case "public":
|
|
|
|
case "global":
|
|
|
|
listGlobal = true;
|
|
|
|
break;
|
|
|
|
case "all":
|
|
|
|
listMine = true;
|
|
|
|
listGlobal = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (arg.endsWith("/") || arg.endsWith(File.separator)) {
|
|
|
|
arg = arg.replace("/", File.separator);
|
|
|
|
String newDirFilter = dirFilter + arg;
|
|
|
|
boolean exists = new File(dir, newDirFilter).exists() || playerFolder && MainUtil.resolveRelative(new File(dir, actor.getUniqueId() + newDirFilter)).exists();
|
|
|
|
if (!exists) {
|
|
|
|
arg = arg.substring(0, arg.length() - File.separator.length());
|
|
|
|
if (arg.length() > 3 && arg.length() <= 16) {
|
|
|
|
UUID fromName = Fawe.imp().getUUID(arg);
|
|
|
|
if (fromName != null) {
|
|
|
|
newDirFilter = dirFilter + fromName + File.separator;
|
|
|
|
listGlobal = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dirFilter = newDirFilter;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
filters.add(arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!listMine && !listGlobal) {
|
|
|
|
listMine = true;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
List<File> toFilter = new ArrayList<>();
|
|
|
|
if (!filters.isEmpty()) {
|
|
|
|
forEachFile = new DelegateConsumer<File>(forEachFile) {
|
|
|
|
@Override
|
|
|
|
public void accept(File file) {
|
|
|
|
toFilter.add(file);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (formatName != null) {
|
2019-01-31 15:08:58 +00:00
|
|
|
final ClipboardFormat cf = ClipboardFormats.findByAlias(formatName);
|
2018-08-12 14:03:07 +00:00
|
|
|
forEachFile = new DelegateConsumer<File>(forEachFile) {
|
|
|
|
@Override
|
|
|
|
public void accept(File file) {
|
|
|
|
if (cf.isFormat(file)) super.accept(file);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
forEachFile = new DelegateConsumer<File>(forEachFile) {
|
|
|
|
@Override
|
|
|
|
public void accept(File file) {
|
|
|
|
if (!file.toString().endsWith(".cached")) super.accept(file);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (playerFolder) {
|
|
|
|
if (listMine) {
|
|
|
|
File playerDir = MainUtil.resolveRelative(new File(dir, actor.getUniqueId() + dirFilter));
|
|
|
|
if (playerDir.exists()) allFiles(playerDir.listFiles(), false, forEachFile);
|
|
|
|
}
|
|
|
|
if (listGlobal) {
|
|
|
|
File rel = MainUtil.resolveRelative(new File(dir, dirFilter));
|
|
|
|
forEachFile = new DelegateConsumer<File>(forEachFile) {
|
|
|
|
@Override
|
|
|
|
public void accept(File f) {
|
|
|
|
try {
|
|
|
|
if (f.isDirectory()) {
|
|
|
|
UUID uuid = UUID.fromString(f.getName());
|
|
|
|
return;
|
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
} catch (IllegalArgumentException ignored) {}
|
2018-08-12 14:03:07 +00:00
|
|
|
super.accept(f);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (rel.exists()) allFiles(rel.listFiles(), false, forEachFile);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
File rel = MainUtil.resolveRelative(new File(dir, dirFilter));
|
|
|
|
if (rel.exists()) allFiles(rel.listFiles(), false, forEachFile);
|
|
|
|
}
|
|
|
|
if (!filters.isEmpty() && !toFilter.isEmpty()) {
|
|
|
|
List<File> result = filter(toFilter, filters);
|
|
|
|
for (File file : result) rootFunction.accept(file);
|
|
|
|
}
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static List<File> filter(List<File> fileList, List<String> filters) {
|
|
|
|
String[] normalizedNames = new String[fileList.size()];
|
|
|
|
for (int i = 0; i < fileList.size(); i++) {
|
|
|
|
String normalized = fileList.get(i).getName().toLowerCase();
|
|
|
|
if (normalized.startsWith("../")) normalized = normalized.substring(3);
|
|
|
|
normalizedNames[i] = normalized.replace("/", File.separator);
|
|
|
|
}
|
2014-07-01 04:56:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
for (String filter : filters) {
|
|
|
|
if (fileList.isEmpty()) return fileList;
|
|
|
|
String lowerFilter = filter.toLowerCase().replace("/", File.separator);
|
|
|
|
List<File> newList = new ArrayList<>();
|
2014-07-01 04:56:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
for (int i = 0; i < normalizedNames.length; i++) {
|
|
|
|
if (normalizedNames[i].startsWith(lowerFilter)) newList.add(fileList.get(i));
|
|
|
|
}
|
|
|
|
if (newList.isEmpty()) {
|
|
|
|
for (int i = 0; i < normalizedNames.length; i++) {
|
|
|
|
if (normalizedNames[i].contains(lowerFilter)) newList.add(fileList.get(i));
|
2014-07-01 04:56:05 +00:00
|
|
|
}
|
2014-06-27 23:03:29 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
if (newList.isEmpty()) {
|
|
|
|
String checkName = filter.replace("\\", "/").split("/")[0];
|
|
|
|
if (checkName.length() > 3 && checkName.length() <= 16) {
|
|
|
|
UUID fromName = Fawe.imp().getUUID(checkName);
|
|
|
|
if (fromName != null) {
|
|
|
|
lowerFilter = filter.replaceFirst(checkName, fromName.toString()).toLowerCase();
|
|
|
|
for (int i = 0; i < normalizedNames.length; i++) {
|
|
|
|
if (normalizedNames[i].startsWith(lowerFilter)) newList.add(fileList.get(i));
|
|
|
|
}
|
|
|
|
}
|
2014-07-01 04:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
fileList = newList;
|
|
|
|
}
|
|
|
|
return fileList;
|
|
|
|
}
|
2014-07-01 04:56:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
public static void allFiles(File[] files, boolean recursive, Consumer<File> task) {
|
|
|
|
if (files == null || files.length == 0) return;
|
|
|
|
for (File f : files) {
|
|
|
|
if (f.isDirectory()) {
|
|
|
|
if (recursive) {
|
|
|
|
allFiles(f.listFiles(), recursive, task);
|
|
|
|
} else {
|
|
|
|
task.accept(f);
|
|
|
|
}
|
2014-07-01 04:56:05 +00:00
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
task.accept(f);
|
2014-07-01 04:56:05 +00:00
|
|
|
}
|
2014-06-27 23:03:29 +00:00
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static String getPath(File root, File file, UUID uuid) {
|
|
|
|
File dir;
|
|
|
|
if (uuid != null) {
|
|
|
|
dir = new File(root, uuid.toString());
|
|
|
|
} else {
|
|
|
|
dir = root;
|
|
|
|
}
|
|
|
|
|
2019-01-31 15:08:58 +00:00
|
|
|
ClipboardFormat format = ClipboardFormats.findByFile(file);
|
2018-08-12 14:03:07 +00:00
|
|
|
URI relative = dir.toURI().relativize(file.toURI());
|
|
|
|
StringBuilder name = new StringBuilder();
|
|
|
|
if (relative.isAbsolute()) {
|
|
|
|
relative = root.toURI().relativize(file.toURI());
|
|
|
|
name.append(".." + File.separator);
|
|
|
|
}
|
|
|
|
name.append(relative.getPath());
|
|
|
|
return name.toString();
|
|
|
|
}
|
2014-06-27 23:03:29 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|