use of org.enginehub.piston.annotation.Command in project FastAsyncWorldEdit by IntellectualSites.
the class UtilityCommands method fill.
@Command(name = "/fill", desc = "Fill a hole")
@CommandPermissions("worldedit.fill")
@Logging(PLACEMENT)
public int fill(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The blocks to fill with") Pattern pattern, // FAWE start - we take an expression over a double
@Arg(desc = "The radius to fill in") Expression radiusExp, // FAWE end
@Arg(desc = "The depth to fill", def = "1") int depth, @Arg(desc = "The direction to move", def = "down") @Direction BlockVector3 direction) throws WorldEditException, EvaluationException {
// FAWE start
double radius = radiusExp.evaluate();
// FAWE end
radius = Math.max(1, radius);
we.checkMaxRadius(radius);
depth = Math.max(1, depth);
BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.fillDirection(pos, pattern, radius, depth, direction);
actor.print(Caption.of("worldedit.fill.created", TextComponent.of(affected)));
return affected;
}
use of org.enginehub.piston.annotation.Command in project FastAsyncWorldEdit by IntellectualSites.
the class UtilityCommands method heightmapInterface.
@Command(name = "/heightmapinterface", aliases = { "/hmi", "hmi" }, desc = "Generate the heightmap interface: https://github.com/IntellectualSites/HeightMap")
@CommandPermissions("fawe.admin")
public void heightmapInterface(Actor actor, @Arg(name = "min", desc = "int", def = "100") int min, @Arg(name = "max", desc = "int", def = "200") int max) throws IOException {
actor.print(TextComponent.of("Please wait while we generate the minified heightmaps."));
File srcFolder = MainUtil.getFile(Fawe.platform().getDirectory(), Settings.settings().PATHS.HEIGHTMAP);
File webSrc = new File(Fawe.platform().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<>();
MainUtil.iterateFiles(srcFolder, file -> {
switch(file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase(Locale.ROOT)) {
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);
actor.print(TextComponent.of(String.format("Writing %s", name)));
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);
}
});
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");
actor.print(TextComponent.of(String.format("Writing %s", configFile)));
Files.write(configFile.toPath(), config.toString().getBytes());
actor.print(TextComponent.of("Done! See: `FastAsyncWorldEdit/web/heightmap`"));
}
use of org.enginehub.piston.annotation.Command in project FastAsyncWorldEdit by IntellectualSites.
the class UtilityCommands method butcher.
@Command(name = "butcher", aliases = { "/butcher" }, desc = "Kill all or nearby mobs")
@CommandPermissions("worldedit.butcher")
@Logging(PLACEMENT)
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, @Switch(name = 'w', desc = "Also kill water mobs") boolean killWater) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
if (radius == null) {
radius = config.butcherDefaultRadius;
} else if (radius < -1) {
actor.print(Caption.of("worldedit.butcher.explain-all"));
return 0;
} else if (radius == -1) {
if (config.butcherMaxRadius != -1) {
radius = config.butcherMaxRadius;
}
}
if (config.butcherMaxRadius != -1) {
radius = Math.min(radius, config.butcherMaxRadius);
}
CreatureButcher flags = new CreatureButcher(actor);
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");
flags.or(CreatureButcher.Flags.WATER, killWater, "worldedit.butcher.water");
// FAWE start - run this sync
int finalRadius = radius;
int killed = TaskManager.taskManager().sync(() -> killMatchingEntities(finalRadius, actor, flags::createFunction));
// FAWE end
actor.print(Caption.of("worldedit.butcher.killed", TextComponent.of(killed), TextComponent.of(radius)));
return killed;
}
use of org.enginehub.piston.annotation.Command in project FastAsyncWorldEdit by IntellectualSites.
the class SchematicCommands method list.
@Command(name = "list", aliases = { "all", "ls" }, desc = "List saved schematics", descFooter = "Note: Format is not fully verified until loading.")
@CommandPermissions("worldedit.schematic.list")
public void list(Actor actor, LocalSession session, @ArgFlag(name = 'p', desc = "Page to view.", def = "1") int page, @Switch(name = 'd', desc = "Sort by date, oldest first") boolean oldFirst, @Switch(name = 'n', desc = "Sort by date, newest first") boolean newFirst, @ArgFlag(name = 'f', desc = "Restricts by format.", def = "") String formatName, @Arg(name = "filter", desc = "Filter for schematics", def = "all") String filter, Arguments arguments) throws WorldEditException {
if (oldFirst && newFirst) {
throw new StopExecutionException(Caption.of("worldedit.schematic.sorting-old-new"));
}
// FAWE start
String pageCommand = "/" + arguments.get();
LocalConfiguration config = worldEdit.getConfiguration();
File dir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
String schemCmd = "//schematic";
String loadSingle = schemCmd + " load";
String loadMulti = schemCmd + " loadall";
String unload = schemCmd + " unload";
String delete = schemCmd + " delete";
String list = schemCmd + " list";
String showCmd = schemCmd + " show";
List<String> args = filter.isEmpty() ? Collections.emptyList() : Arrays.asList(filter.split(" "));
URIClipboardHolder multi = as(URIClipboardHolder.class, session.getExistingClipboard());
final boolean hasShow = false;
// If player forgot -p argument
boolean playerFolder = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS;
UUID uuid = playerFolder ? actor.getUniqueId() : null;
List<File> files = UtilityCommands.getFiles(dir, actor, args, formatName, playerFolder, oldFirst, newFirst);
List<Map.Entry<URI, String>> entries = UtilityCommands.filesToEntry(dir, files, uuid);
Function<URI, Boolean> isLoaded = multi == null ? f -> false : multi::contains;
List<Component> components = UtilityCommands.entryToComponent(dir, entries, isLoaded, (name, path, type, loaded) -> {
TextComponentProducer msg = new TextComponentProducer();
msg.append(Caption.of("worldedit.schematic.dash.symbol"));
if (loaded) {
msg.append(Caption.of("worldedit.schematic.minus.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.unload"))));
} else {
msg.append(Caption.of("worldedit.schematic.plus.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.clipboard"))));
}
if (type != UtilityCommands.URIType.DIRECTORY) {
msg.append(Caption.of("worldedit.schematic.x.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.delete"))));
} else if (hasShow) {
msg.append(Caption.of("worldedit.schematic.0.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.visualize"))));
}
TextComponent msgElem = TextComponent.of(name);
if (type != UtilityCommands.URIType.DIRECTORY) {
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + path));
msgElem = msgElem.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.load")));
} else {
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + path));
msgElem = msgElem.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.list")));
}
msg.append(msgElem);
if (type == UtilityCommands.URIType.FILE) {
long filesize = 0;
try {
filesize = Files.size(Paths.get(dir.getAbsolutePath() + File.separator + (playerFolder ? (uuid.toString() + File.separator) : "") + path));
} catch (IOException e) {
e.printStackTrace();
}
TextComponent sizeElem = TextComponent.of(String.format(" (%.1f kb)", filesize / 1000.0), TextColor.GRAY);
msg.append(sizeElem);
}
return msg.create();
});
long totalBytes = 0;
File parentDir = new File(dir.getAbsolutePath() + (playerFolder ? File.separator + uuid.toString() : ""));
try {
List<File> toAddUp = getFiles(parentDir, null, null);
if (toAddUp != null && toAddUp.size() != 0) {
for (File schem : toAddUp) {
if (schem.getName().endsWith(".schem") || schem.getName().endsWith(".schematic")) {
totalBytes += Files.size(Paths.get(schem.getAbsolutePath()));
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
String headerBytesElem = String.format("%.1fkb", totalBytes / 1000.0);
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT > -1) {
headerBytesElem += String.format(" / %dkb", Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT);
}
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS) {
String fullHeader = "| My Schematics: " + headerBytesElem + " |";
PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
actor.print(paginationBox.create(page));
} else {
String fullHeader = "| Schematics: " + headerBytesElem + " |";
PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
actor.print(paginationBox.create(page));
}
// FAWE end
}
use of org.enginehub.piston.annotation.Command in project FastAsyncWorldEdit by IntellectualSites.
the class SchematicCommands method save.
@Command(name = "save", desc = "Save your clipboard into a schematic file")
@CommandPermissions({ "worldedit.clipboard.save", "worldedit.schematic.save", "worldedit.schematic.save.other", "worldedit.schematic.save.global" })
public void save(Actor actor, LocalSession session, @Arg(desc = "File name.") String filename, @Arg(desc = "Format name.", def = "fast") String formatName, @Switch(name = 'f', desc = "Overwrite an existing file.") boolean allowOverwrite, // FAWE start
@Switch(name = 'g', desc = "Bypasses per-player-schematic folders") boolean global) throws WorldEditException {
if (global && !actor.hasPermission("worldedit.schematic.save.global")) {
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.save.global"));
return;
}
// FAWE end
if (worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getDataVersion() == -1) {
actor.print(TranslatableComponent.of("worldedit.schematic.unsupported-minecraft-version"));
return;
}
LocalConfiguration config = worldEdit.getConfiguration();
File dir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
// FAWE start
if (!global && Settings.settings().PATHS.PER_PLAYER_SCHEMATICS) {
dir = new File(dir, actor.getUniqueId().toString());
}
ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) {
actor.print(Caption.of("worldedit.schematic.unknown-format", TextComponent.of(formatName)));
return;
}
boolean other = false;
if (filename.contains("../")) {
other = true;
if (!actor.hasPermission("worldedit.schematic.save.other")) {
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.save.other"));
return;
}
if (filename.startsWith("../")) {
dir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
filename = filename.substring(3);
}
}
// FAWE end
File f = worldEdit.getSafeSaveFile(actor, dir, filename, format.getPrimaryFileExtension());
boolean overwrite = f.exists();
if (overwrite) {
if (!actor.hasPermission("worldedit.schematic.delete")) {
throw new StopExecutionException(Caption.of("worldedit.schematic.already-exists"));
}
if (other) {
if (!actor.hasPermission("worldedit.schematic.delete.other")) {
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.delete.other"));
return;
}
}
if (!allowOverwrite) {
actor.print(Caption.of("worldedit.schematic.save.already-exists"));
return;
}
}
// Create parent directories
File parent = f.getParentFile();
if (parent != null && !parent.exists()) {
if (!parent.mkdirs()) {
throw new StopExecutionException(Caption.of("worldedit.schematic.save.failed-directory"));
}
}
ClipboardHolder holder = session.getClipboard();
SchematicSaveTask task = new SchematicSaveTask(actor, f, dir, format, holder, overwrite);
AsyncCommandBuilder.wrap(task, actor).registerWithSupervisor(worldEdit.getSupervisor(), "Saving schematic " + filename).setDelayMessage(Caption.of("worldedit.schematic.save.saving")).onSuccess(filename + " saved" + (overwrite ? " (overwriting previous file)." : "."), null).onFailure(Caption.of("worldedit.schematic.failed-to-save"), worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()).buildAndExec(worldEdit.getExecutorService());
}
Aggregations