@Command( aliases = {"/copy"}, flags = "e", desc = "Копирует выделенную территорию в буфер обмена", help = "Копирует выделенную территорию в буфер обмен\n" + "Флаги:\n" + " -e определяет, будут ли объекты копироваться в буфер обмена\n" + "ПРЕДУПРЕЖДЕНИЕ: Вставленные объекты не могут быть отменены!", min = 0, max = 0) @CommandPermissions("worldedit.clipboard.copy") public void copy( CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { Region region = session.getSelection(player.getWorld()); Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); Vector pos = session.getPlacementPosition(player); CuboidClipboard clipboard = new CuboidClipboard(max.subtract(min).add(new Vector(1, 1, 1)), min, min.subtract(pos)); clipboard.copy(editSession); if (args.hasFlag('e')) { for (LocalEntity entity : player.getWorld().getEntities(region)) { clipboard.storeEntity(entity); } } session.setClipboard(clipboard); player.print("Блок(и) скопирован(ы)."); }
@Command( aliases = {"/cut"}, usage = "[leave-id]", desc = "Вырезает выделенную территорию в буфер обмена", help = "Вырезает выделенную территорию в буфер обмена\n" + "Флаги:\n" + " -e controls определяет, будут ли объекты копироваться в буфер обмена\n" + "ПРЕДУПРЕЖДЕНИЕ: Вырезанные и вставленные объекты не могут быть отменены!", flags = "e", min = 0, max = 1) @CommandPermissions("worldedit.clipboard.cut") @Logging(REGION) public void cut( CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { BaseBlock block = new BaseBlock(BlockID.AIR); LocalWorld world = player.getWorld(); if (args.argsLength() > 0) { block = we.getBlock(player, args.getString(0)); } Region region = session.getSelection(world); Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); Vector pos = session.getPlacementPosition(player); CuboidClipboard clipboard = new CuboidClipboard(max.subtract(min).add(new Vector(1, 1, 1)), min, min.subtract(pos)); clipboard.copy(editSession); if (args.hasFlag('e')) { LocalEntity[] entities = world.getEntities(region); for (LocalEntity entity : entities) { clipboard.storeEntity(entity); } world.killEntities(entities); } session.setClipboard(clipboard); int affected = editSession.setBlocks(session.getSelection(world), block); player.print( affected + " " + StringUtil.plural(affected, "блок вырезан", "блока вырезано", "блоков вырезано") + "."); }
/** * Transform NBT data in the given entity state and return a new instance if the NBT data needs to * be transformed. * * @param state the existing state * @return a new state or the existing one */ private BaseEntity transformNbtData(BaseEntity state) { CompoundTag tag = state.getNbtData(); if (tag != null) { // Handle hanging entities (paintings, item frames, etc.) boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ"); boolean hasDirection = tag.containsKey("Direction"); boolean hasLegacyDirection = tag.containsKey("Dir"); boolean hasFacing = tag.containsKey("Facing"); if (hasTilePosition) { Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ")); Vector newTilePosition = transform.apply(tilePosition.subtract(from)).add(to); CompoundTagBuilder builder = tag.createBuilder() .putInt("TileX", newTilePosition.getBlockX()) .putInt("TileY", newTilePosition.getBlockY()) .putInt("TileZ", newTilePosition.getBlockZ()); if (hasDirection || hasLegacyDirection || hasFacing) { int d; if (hasDirection) { d = tag.asInt("Direction"); } else if (hasLegacyDirection) { d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir")); } else { d = tag.asInt("Facing"); } Direction direction = MCDirections.fromHanging(d); if (direction != null) { Vector vector = transform .apply(direction.toVector()) .subtract(transform.apply(Vector.ZERO)) .normalize(); Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL); if (newDirection != null) { byte hangingByte = (byte) MCDirections.toHanging(newDirection); builder.putByte("Direction", hangingByte); builder.putByte("Facing", hangingByte); builder.putByte( "Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection))); } } } return new BaseEntity(state.getTypeId(), builder.build()); } } return state; }
@Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { WorldVector min = new WorldVector( LocalWorldAdapter.adapt(editSession.getWorld()), position.subtract(size, size, size)); Vector max = position.add(size, size + 10, size); Region region = new CuboidRegion(editSession.getWorld(), min, max); HeightMap heightMap = new HeightMap(editSession, region, naturalOnly); HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); heightMap.applyFilter(filter, iterations); }
@Command( aliases = {"/deform"}, usage = "<expression>", desc = "Deforms a selected region with an expression", help = "Deforms a selected region with an expression\n" + "The expression is executed for each block and is expected\n" + "to modify the variables x, y and z to point to a new block\n" + "to fetch. See also tinyurl.com/wesyntax.", flags = "ro", min = 1, max = -1) @CommandPermissions("worldedit.region.deform") @Logging(ALL) public void deform( Player player, LocalSession session, EditSession editSession, @Selection Region region, @Text String expression, @Switch('r') boolean useRawCoords, @Switch('o') boolean offset) throws WorldEditException { final Vector zero; Vector unit; if (useRawCoords) { zero = Vector.ZERO; unit = Vector.ONE; } else if (offset) { zero = session.getPlacementPosition(player); unit = Vector.ONE; } else { final Vector min = region.getMinimumPoint(); final Vector max = region.getMaximumPoint(); zero = max.add(min).multiply(0.5); unit = max.subtract(zero); if (unit.getX() == 0) unit = unit.setX(1.0); if (unit.getY() == 0) unit = unit.setY(1.0); if (unit.getZ() == 0) unit = unit.setZ(1.0); } try { final int affected = editSession.deformRegion(region, zero, unit, expression); player.findFreePosition(); BBC.VISITOR_BLOCK.send(player, affected); } catch (ExpressionException e) { player.printError(e.getMessage()); } }
private RetVal subEntrance(ArrayList<String> arg, String pName) { Log.debug("CommandDungeon.subEntrance"); RetVal r = new RetVal(); if (arg.isEmpty()) { r.Err( Config.ecol + "Error - Invalid number of arguments! Command is /" + Config.command + " dungeon entrance <dungeon name> (while standing at the warp-in point)!"); return r; } DungeonData d = DungeonManager.getDungeon(arg.get(0)); if (d == null) { r.Err(Config.ecol + "Error - Invalid argument! '" + arg.get(0) + "' not a valid Dungeon!"); return r; } InstanceData i = InstanceManager.getEditInstanceForDungeon(d.name); if (i == null) { r.Err( Config.ecol + "Error - Invalid argument! '" + arg.get(0) + "' does not have an edit Instance!"); return r; } Location l = bridge.getPlayerLoc(pName); Vector v = l.getPosition(); Vector vOff = v.subtract(i.getBounds().getMinimumPoint()); d.setSpawn(vOff.getBlockX(), vOff.getBlockY(), vOff.getBlockZ(), l.getYaw(), l.getPitch()); r.add("Successfully added spawn in location to Dungeon '" + arg.get(0) + "'"); r.tru(); return r; }
@Command( aliases = {"/replacenear", "replacenear"}, usage = "<size> <from-id> <to-id>", desc = "Replace nearby blocks", flags = "f", min = 3, max = 3) @CommandPermissions("worldedit.replacenear") @Logging(PLACEMENT) public void replaceNear( CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { int size = Math.max(1, args.getInteger(0)); int affected; Set<BaseBlock> from; Pattern to; if (args.argsLength() == 2) { from = null; to = we.getBlockPattern(player, args.getString(1)); } else { from = we.getBlocks(player, args.getString(1), true, !args.hasFlag('f')); to = we.getBlockPattern(player, args.getString(2)); } Vector base = session.getPlacementPosition(player); Vector min = base.subtract(size, size, size); Vector max = base.add(size, size, size); Region region = new CuboidRegion(player.getWorld(), min, max); if (to instanceof SingleBlockPattern) { affected = editSession.replaceBlocks(region, from, ((SingleBlockPattern) to).getBlock()); } else { affected = editSession.replaceBlocks(region, from, to); } player.print(affected + " block(s) have been replaced."); }
/** * Make a cuboid from the center. * * @param origin the origin * @param apothem the apothem, where 0 is the minimum value to make a 1x1 cuboid * @return a cuboid region */ public static CuboidRegion fromCenter(Vector origin, int apothem) { checkNotNull(origin); checkArgument(apothem >= 0, "apothem => 0 required"); Vector size = new Vector(1, 1, 1).multiply(apothem); return new CuboidRegion(origin.subtract(size), origin.add(size)); }
@Override public Vector subtract(int x, int y, int z) { return wrap(m_parent.subtract(x, y, z)); }
@Override public Vector subtract(double x, double y, double z) { return wrap(m_parent.subtract(x, y, z)); }
@Override public Vector subtract(Vector... others) { return wrap(m_parent.subtract(others)); }
@Command( aliases = {"save"}, desc = "Saves the selected area", usage = "[-n namespace ] <id>", flags = "n:", min = 1) public void saveArea(CommandContext context, CommandSender sender) throws CommandException { if (!(sender instanceof Player)) return; LocalPlayer player = plugin.wrapPlayer((Player) sender); String id; String namespace = player.getName(); boolean personal = true; if (context.hasFlag('n') && player.hasPermission("craftbook.mech.area.save." + context.getFlag('n'))) { namespace = context.getFlag('n'); personal = false; } else if (!player.hasPermission("craftbook.mech.area.save.self")) throw new CommandPermissionsException(); if (plugin.getConfiguration().areaShortenNames && namespace.length() > 14) namespace = namespace.substring(0, 14); if (!CopyManager.isValidNamespace(namespace)) throw new CommandException("Invalid namespace. Needs to be between 1 and 14 letters long."); if (personal) { namespace = "~" + namespace; } id = context.getString(0); if (!CopyManager.isValidName(id)) throw new CommandException("Invalid area name. Needs to be between 1 and 13 letters long."); try { WorldEditPlugin worldEdit = CraftBookPlugin.plugins.getWorldEdit(); World world = ((Player) sender).getWorld(); Selection sel = worldEdit.getSelection((Player) sender); if (sel == null) { sender.sendMessage(ChatColor.RED + "You have not made a selection!"); return; } Vector min = BukkitUtil.toVector(sel.getMinimumPoint()); Vector max = BukkitUtil.toVector(sel.getMaximumPoint()); Vector size = max.subtract(min).add(1, 1, 1); // Check maximum size if (config.areaMaxAreaSize != -1 && size.getBlockX() * size.getBlockY() * size.getBlockZ() > config.areaMaxAreaSize) { throw new CommandException( "Area is larger than allowed " + config.areaMaxAreaSize + " blocks."); } // Check to make sure that a user doesn't have too many toggle // areas (to prevent flooding the server with files) if (config.areaMaxAreaPerUser >= 0 && !namespace.equals("global")) { int count = copyManager.meetsQuota(world, namespace, id, config.areaMaxAreaPerUser); if (count > -1) { throw new CommandException( "You are limited to " + config.areaMaxAreaPerUser + " toggle area(s). " + "You have " + count + " areas."); } } // Copy CuboidCopy copy; if (config.areaUseSchematics) { copy = new MCEditCuboidCopy(min, size, world); } else { copy = new FlatCuboidCopy(min, size, world); } copy.copy(); plugin .getServer() .getLogger() .info( player.getName() + " saving toggle area with folder '" + namespace + "' and ID '" + id + "'."); // Save try { CopyManager.getInstance().save(world, namespace, id.toLowerCase(Locale.ENGLISH), copy); player.print("Area saved as '" + id + "' under the '" + namespace + "' namespace."); } catch (IOException e) { player.printError("Could not save area: " + e.getMessage()); } catch (DataException e) { player.print(e.getMessage()); } } catch (NoClassDefFoundError e) { throw new CommandException( "WorldEdit.jar does not exist in plugins/, or is outdated. (Or you are using an outdated version of CraftBook)"); } }