Moved commands into their own classes.

This commit is contained in:
sk89q 2011-01-29 02:05:22 -08:00
parent 67f344e1be
commit 02de4c8200
21 changed files with 2875 additions and 1533 deletions

View File

@ -0,0 +1,31 @@
// $Id$
/*
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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.util.commands;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
String[] aliases();
String usage();
String desc();
int min();
int max();
}

View File

@ -0,0 +1,80 @@
// $Id$
/*
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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.util.commands;
public class CommandContext {
protected String[] args;
public CommandContext(String args) {
this.args = args.split(" ");
}
public CommandContext(String[] args) {
this.args = args;
}
public String getCommand() {
return args[0];
}
public boolean matches(String command) {
return args[0].equalsIgnoreCase(command);
}
public String getString(int index) {
return args[index + 1];
}
public String getJoinedStrings(int initialIndex) {
initialIndex = initialIndex + 1;
StringBuilder buffer = new StringBuilder(args[initialIndex]);
for (int i = initialIndex + 1; i < args.length; i++) {
buffer.append(" ").append(args[i]);
}
return buffer.toString();
}
public int getInteger(int index) throws NumberFormatException {
return Integer.parseInt(args[index + 1]);
}
public double getDouble(int index) throws NumberFormatException {
return Double.parseDouble(args[index + 1]);
}
public String[] getSlice(int index) {
String[] slice = new String[args.length - index];
System.arraycopy(args, index, slice, 0, args.length - index);
return slice;
}
public String[] getPaddedSlice(int index, int padding) {
String[] slice = new String[args.length - index + padding];
System.arraycopy(args, index, slice, padding, args.length - index + padding);
return slice;
}
public int length() {
return args.length;
}
public int argsLength() {
return args.length - 1;
}
}

View File

@ -542,7 +542,7 @@ public abstract class LocalPlayer {
* @return * @return
*/ */
public boolean canDestroyBedrock() { public boolean canDestroyBedrock() {
return hasPermission("worldeditbedrock"); return hasPermission("worldedit.bedrock");
} }
/** /**

File diff suppressed because it is too large Load Diff

View File

@ -102,7 +102,7 @@ public class BukkitPlayer extends LocalPlayer {
@Override @Override
public boolean hasPermission(String perm) { public boolean hasPermission(String perm) {
return plugin.hasPermission(player, "/" + perm); return plugin.hasPermission(player, perm);
} }
@Override @Override

View File

@ -0,0 +1,161 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import java.io.*;
import java.util.Set;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.data.NestedFileChunkStore;
/**
* Chunk tools.
*
* @author sk89q
*/
public class ChunkCommands {
@Command(
aliases = {"/chunkinfo"},
usage = "",
desc = "Get information about the chunk that you are inside",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.chunkinfo"})
public static void chunkInfo(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Vector pos = player.getBlockIn();
int chunkX = (int)Math.floor(pos.getBlockX() / 16.0);
int chunkZ = (int)Math.floor(pos.getBlockZ() / 16.0);
String folder1 = Integer.toString(WorldEdit.divisorMod(chunkX, 64), 36);
String folder2 = Integer.toString(WorldEdit.divisorMod(chunkZ, 64), 36);
String filename = "c." + Integer.toString(chunkX, 36)
+ "." + Integer.toString(chunkZ, 36) + ".dat";
player.print("Chunk: " + chunkX + ", " + chunkZ);
player.print(folder1 + "/" + folder2 + "/" + filename);
}
@Command(
aliases = {"/listchunks"},
usage = "",
desc = "List chunks that your selection includes",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.listchunks"})
public static void listChunks(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Set<Vector2D> chunks = session.getRegion().getChunks();
for (Vector2D chunk : chunks) {
player.print(NestedFileChunkStore.getFilename(chunk));
}
}
@Command(
aliases = {"/delchunks"},
usage = "",
desc = "Delete chunks that your selection includes",
min = 0,
max = 0
)
@CommandPermissions({"delchunks"})
public static void deleteChunks(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
Set<Vector2D> chunks = session.getRegion().getChunks();
FileOutputStream out = null;
if (config.shellSaveType == null) {
player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
} else if (config.shellSaveType.equalsIgnoreCase("bat")) {
try {
out = new FileOutputStream("worldedit-delchunks.bat");
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
writer.write("@ECHO off\r\n");
writer.write("ECHO This batch file was generated by WorldEdit.\r\n");
writer.write("ECHO It contains a list of chunks that were in the selected region\r\n");
writer.write("ECHO at the time that the /delchunks command was used. Run this file\r\n");
writer.write("ECHO in order to delete the chunk files listed in this file.\r\n");
writer.write("ECHO.\r\n");
writer.write("PAUSE\r\n");
for (Vector2D chunk : chunks) {
String filename = NestedFileChunkStore.getFilename(chunk);
writer.write("ECHO " + filename + "\r\n");
writer.write("DEL \"world/" + filename + "\"\r\n");
}
writer.write("ECHO Complete.\r\n");
writer.write("PAUSE\r\n");
writer.close();
player.print("worldedit-delchunks.bat written. Run it when no one is near the region.");
} catch (IOException e) {
player.printError("Error occurred: " + e.getMessage());
} finally {
if (out != null) {
try { out.close(); } catch (IOException ie) {}
}
}
} else if (config.shellSaveType.equalsIgnoreCase("bash")) {
try {
out = new FileOutputStream("worldedit-delchunks.sh");
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
writer.write("#!/bin/bash\n");
writer.write("echo This shell file was generated by WorldEdit.\n");
writer.write("echo It contains a list of chunks that were in the selected region\n");
writer.write("echo at the time that the /delchunks command was used. Run this file\n");
writer.write("echo in order to delete the chunk files listed in this file.\n");
writer.write("echo\n");
writer.write("read -p \"Press any key to continue...\"\n");
for (Vector2D chunk : chunks) {
String filename = NestedFileChunkStore.getFilename(chunk);
writer.write("echo " + filename + "\n");
writer.write("rm \"world/" + filename + "\"\n");
}
writer.write("echo Complete.\n");
writer.write("read -p \"Press any key to continue...\"\n");
writer.close();
player.print("worldedit-delchunks.sh written. Run it when no one is near the region.");
player.print("You will have to chmod it to be executable.");
} catch (IOException e) {
player.printError("Error occurred: " + e.getMessage());
} finally {
if (out != null) {
try { out.close(); } catch (IOException ie) {}
}
}
} else {
player.printError("Shell script type must be configured: 'bat' or 'bash' expected.");
}
}
}

View File

@ -0,0 +1,282 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import java.io.File;
import java.io.IOException;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.data.DataException;
import com.sk89q.worldedit.regions.Region;
/**
* Clipboard commands.
*
* @author sk89q
*/
public class ClipboardCommands {
@Command(
aliases = {"//copy"},
usage = "",
desc = "Copy the selection to the clipboard",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.clipboard.copy"})
public static void copy(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Region region = session.getRegion();
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
Vector pos = player.getBlockIn();
CuboidClipboard clipboard = new CuboidClipboard(
max.subtract(min).add(new Vector(1, 1, 1)),
min, min.subtract(pos));
clipboard.copy(editSession);
session.setClipboard(clipboard);
player.print("Block(s) copied.");
}
@Command(
aliases = {"//cut"},
usage = "[leave-id]",
desc = "Cut the selection to the clipboard",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.clipboard.cut"})
public static void cut(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = new BaseBlock(0);
if (args.argsLength() > 0) {
block = we.getBlock(player, args.getString(0));
}
Region region = session.getRegion();
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
Vector pos = player.getBlockIn();
CuboidClipboard clipboard = new CuboidClipboard(
max.subtract(min).add(new Vector(1, 1, 1)),
min, min.subtract(pos));
clipboard.copy(editSession);
session.setClipboard(clipboard);
editSession.setBlocks(session.getRegion(), block);
player.print("Block(s) cut.");
}
@Command(
aliases = {"//paste"},
usage = "[at-origin?]",
desc = "Paste the clipboard's contents",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.clipboard.paste"})
public static void paste(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
boolean atOrigin = args.argsLength() > 0
? (args.getString(1).equalsIgnoreCase("true")
|| args.getString(0).equalsIgnoreCase("yes"))
: false;
if (atOrigin) {
Vector pos = session.getClipboard().getOrigin();
session.getClipboard().place(editSession, pos, false);
player.findFreePosition();
player.print("Pasted to copy origin. Undo with //undo");
} else {
Vector pos = session.getPlacementPosition(player);
session.getClipboard().paste(editSession, pos, false);
player.findFreePosition();
player.print("Pasted relative to you. Undo with //undo");
}
}
@Command(
aliases = {"//rotate"},
usage = "<angle-in-degrees>",
desc = "Rotate the contents of the clipboard",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.clipboard.rotate"})
public static void rotate(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int angle = args.getInteger(0);
if (angle % 90 == 0) {
CuboidClipboard clipboard = session.getClipboard();
clipboard.rotate2D(angle);
player.print("Clipboard rotated by " + angle + " degrees.");
} else {
player.printError("Angles must be divisible by 90 degrees.");
}
}
@Command(
aliases = {"//flip"},
usage = "[dir]",
desc = "Flip the contents of the clipboard",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.clipboard.flip"})
public static void flip(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
CuboidClipboard.FlipDirection dir = we.getFlipDirection(player,
args.argsLength() > 0 ? args.getString(0).toLowerCase() : "me");
CuboidClipboard clipboard = session.getClipboard();
clipboard.flip(dir);
player.print("Clipboard flipped.");
}
@Command(
aliases = {"//load"},
usage = "<filename>",
desc = "Load a schematic into your clipboard",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.clipboard.load"})
public static void load(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
String filename = args.getString(0).replace("\0", "") + ".schematic";
File dir = new File(config.getWorkingDirectory(), "schematics");
File f = new File(new File(config.getWorkingDirectory(), "schematics"), filename);
if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
player.printError("Valid characters: A-Z, a-z, 0-9, spaces, "
+ "./\'$@~!%^*()[]+{},?");
return;
}
try {
String filePath = f.getCanonicalPath();
String dirPath = dir.getCanonicalPath();
if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
player.printError("Schematic could not read or it does not exist.");
} else {
session.setClipboard(CuboidClipboard.loadSchematic(f));
WorldEdit.logger.info(player.getName() + " loaded " + filePath);
player.print(filename + " loaded. Paste it with //paste");
}
} catch (DataException e) {
player.printError("Load error: " + e.getMessage());
} catch (IOException e) {
player.printError("Schematic could not read or it does not exist: " + e.getMessage());
}
}
@Command(
aliases = {"//save"},
usage = "<filename>",
desc = "Save a schematic into your clipboard",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.clipboard.save"})
public static void save(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
String filename = args.getString(0).replace("\0", "") + ".schematic";
if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
player.printError("Valid characters: A-Z, a-z, 0-9, spaces, "
+ "./\'$@~!%^*()[]+{},?");
return;
}
File dir = new File(config.getWorkingDirectory(), "schematics");
File f = new File(new File(config.getWorkingDirectory(), "schematics"), filename);
if (!dir.exists()) {
if (!dir.mkdir()) {
player.printError("A schematics/ folder could not be created.");
return;
}
}
try {
String filePath = f.getCanonicalPath();
String dirPath = dir.getCanonicalPath();
if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
player.printError("Invalid path for Schematic.");
} else {
// Create parent directories
File parent = f.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
}
session.getClipboard().saveSchematic(f);
WorldEdit.logger.info(player.getName() + " saved " + filePath);
player.print(filename + " saved.");
}
} catch (DataException se) {
player.printError("Save error: " + se.getMessage());
} catch (IOException e) {
player.printError("Schematic could not written: " + e.getMessage());
}
}
@Command(
aliases = {"/clearclipboard"},
usage = "",
desc = "Clear your clipboard",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.clipboard.clear"})
public static void clearClipboard(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setClipboard(null);
player.print("Clipboard cleared.");
}
}

View File

@ -0,0 +1,28 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions {
String[] value();
}

View File

@ -0,0 +1,166 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
/**
* Manager for handling commands.
*
* @author sk89q
*/
public class CommandsManager {
/**
* Mapping of commands (including aliases) with their method.
*/
public Map<String, Method> commands = new HashMap<String, Method>();
/**
* Mapping of commands (not including aliases) with a description.
*/
public Map<String, String> descs = new HashMap<String, String>();
/**
* Register an object that contains commands (denoted by the
* <code>com.sk89q.util.commands.Command</code> annotation. The methods are
* cached into a map for later usage and it reduces the overhead of
* reflection (method lookup via reflection is relatively slow).
*
* @param cls
*/
public void register(Class<?> cls) {
for (Method method : cls.getMethods()) {
if (!method.isAnnotationPresent(Command.class)) {
continue;
}
Command cmd = method.getAnnotation(Command.class);
// Cache the commands
for (String alias : cmd.aliases()) {
commands.put(alias, method);
}
// Build a list of commands and their usage details
if (cmd.usage().length() == 0) {
descs.put(cmd.aliases()[0], cmd.desc());
} else {
descs.put(cmd.aliases()[0], cmd.usage() + " - " + cmd.desc());
}
}
}
/**
* Checks to see whether there is a command.
*
* @param command
* @return
*/
public boolean hasCommand(String command) {
return commands.containsKey(command.toLowerCase());
}
/**
* Get a list of command descriptions.
*
* @return
*/
public Map<String, String> getCommands() {
return descs;
}
/**
* Attempt to execute a command.
*
* @param args
* @param we
* @param session
* @param player
* @param editSession
* @return
*/
public boolean execute(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Method method = commands.get(args.getCommand().toLowerCase());
if (method == null) {
return false; // No command
}
if (!checkPermissions(method, player)) {
return true;
}
Command cmd = method.getAnnotation(Command.class);
if (args.argsLength() < cmd.min()) {
player.printError(args.getCommand() + " " + cmd.usage());
return true;
}
if (cmd.max() != -1 && args.argsLength() > cmd.max()) {
player.printError(args.getCommand() + " " + cmd.usage());
return true;
}
try {
method.invoke(null, args, we, session, player, editSession);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
if (e.getCause() instanceof WorldEditException) {
throw (WorldEditException)e.getCause();
} else {
e.printStackTrace();
}
}
return true;
}
private boolean checkPermissions(Method method, LocalPlayer player) {
CommandPermissions perms = method.getAnnotation(CommandPermissions.class);
if (perms == null) {
return true;
}
for (String perm : perms.value()) {
if (player.hasPermission(perm)) {
return true;
}
}
player.printError("You don't have permission for this command.");
return false;
}
}

View File

@ -0,0 +1,77 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
/**
* General WorldEdit commands.
*
* @author sk89q
*/
public class GeneralCommands {
@Command(
aliases = {"//limit"},
usage = "<limit>",
desc = "Modify block change limit",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.limit"})
public static void limit(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int limit = Math.max(-1, args.getInteger(0));
if (!player.hasPermission("worldedit.limit.unrestricted")
&& config.maxChangeLimit > -1) {
if (limit > config.maxChangeLimit) {
player.printError("Your maximum allowable limit is "
+ config.maxChangeLimit + ".");
return;
}
}
session.setBlockChangeLimit(limit);
player.print("Block change limit set to " + limit + ".");
}
@Command(
aliases = {"/toggleplace"},
usage = "",
desc = "",
min = 0,
max = 0
)
public static void togglePlace(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
if (session.togglePlacementPosition()) {
player.print("Now placing at pos #1.");
} else {
player.print("Now placing at the block you stand in.");
}
}
}

View File

@ -0,0 +1,190 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Generation commands.
*
* @author sk89q
*/
public class GenerationCommands {
@Command(
aliases = {"//hcyl"},
usage = "<block> <radius> [height] ",
desc = "Generate a hollow cylinder",
min = 2,
max = 3
)
@CommandPermissions({"worldedit.generation.cylinder"})
public static void hcyl(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1));
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
Vector pos = session.getPlacementPosition(player);
int affected = editSession.makeHollowCylinder(pos, block, radius, height);
player.print(affected + " block(s) have been created.");
}
@Command(
aliases = {"//cyl"},
usage = "<block> <radius> [height] ",
desc = "Generate a cylinder",
min = 2,
max = 3
)
@CommandPermissions({"worldedit.generation.cylinder"})
public static void cyl(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1));
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
Vector pos = session.getPlacementPosition(player);
int affected = editSession.makeCylinder(pos, block, radius, height);
player.print(affected + " block(s) have been created.");
}
@Command(
aliases = {"//hsphere"},
usage = "<block> <radius> [raised?] ",
desc = "Generate a hollow sphere",
min = 2,
max = 3
)
@CommandPermissions({"worldedit.generation.sphere"})
public static void hsphere(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1));
boolean raised = args.argsLength() > 2
? (args.getString(2).equalsIgnoreCase("true")
|| args.getString(2).equalsIgnoreCase("yes"))
: false;
Vector pos = session.getPlacementPosition(player);
if (raised) {
pos = pos.add(0, radius, 0);
}
int affected = editSession.makeSphere(pos, block, radius, false);
player.findFreePosition();
player.print(affected + " block(s) have been created.");
}
@Command(
aliases = {"//sphere"},
usage = "<block> <radius> [raised?] ",
desc = "Generate a filled sphere",
min = 2,
max = 3
)
@CommandPermissions({"worldedit.generation.sphere"})
public static void sphere(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1));
boolean raised = args.argsLength() > 2
? (args.getString(2).equalsIgnoreCase("true")
|| args.getString(2).equalsIgnoreCase("yes"))
: false;
Vector pos = session.getPlacementPosition(player);
if (raised) {
pos = pos.add(0, radius, 0);
}
int affected = editSession.makeSphere(pos, block, radius, true);
player.findFreePosition();
player.print(affected + " block(s) have been created.");
}
@Command(
aliases = {"/forestgen"},
usage = "[size] [density] ",
desc = "Generate a forest",
min = 0,
max = 2
)
@CommandPermissions({"worldedit.generation.forest"})
public static void forestGen(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
double density = args.argsLength() > 1 ? Double.parseDouble(args.getString(1)) / 100 : 0.05;
int affected = editSession.makeForest(player.getPosition(),
size, density, false);
player.print(affected + " trees created.");
}
@Command(
aliases = {"/pinegen"},
usage = "[size] [density]",
desc = "Generate a pine forest",
min = 0,
max = 2
)
@CommandPermissions({"worldedit.generation.forest"})
public static void pineGen(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
double density = args.argsLength() > 1 ? Double.parseDouble(args.getString(1)) / 100 : 0.05;
int affected = editSession.makeForest(player.getPosition(),
size, density, true);
player.print(affected + " pine trees created.");
}
@Command(
aliases = {"/pumpkins"},
usage = "[size]",
desc = "Generate pumpkin patches",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.generation.pumpkins"})
public static void pumpkins(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
int affected = editSession.makePumpkinPatches(player.getPosition(), size);
player.print(affected + " pumpkin patches created.");
}
}

View File

@ -0,0 +1,89 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
/**
* History little commands.
*
* @author sk89q
*/
public class HistoryCommands {
@Command(
aliases = {"//undo"},
usage = "",
desc = "Undoes the last action",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.history.undo"})
public static void undo(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
EditSession undone = session.undo(session.getBlockBag(player));
if (undone != null) {
player.print("Undo successful.");
we.flushBlockBag(player, undone);
} else {
player.printError("Nothing to undo.");
}
}
@Command(
aliases = {"//redo"},
usage = "",
desc = "Redoes the last action (from history)",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.history.redo"})
public static void redo(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
EditSession redone = session.redo(session.getBlockBag(player));
if (redone != null) {
player.print("Redo successful.");
we.flushBlockBag(player, redone);
} else {
player.printError("Nothing to redo.");
}
}
@Command(
aliases = {"/clearhistory"},
usage = "",
desc = "Clear your history",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.history.clear"})
public static void clearHistory(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.clearHistory();
player.print("History cleared.");
}
}

View File

@ -17,7 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit; package com.sk89q.worldedit.commands;
import com.sk89q.worldedit.WorldEditException;
/** /**
* *

View File

@ -0,0 +1,168 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
/**
* Navigation commands.
*
* @author sk89q
*/
public class NavigationCommands {
@Command(
aliases = {"/unstuck"},
usage = "",
desc = "Escape from being stuck inside a block",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.navigation.unstuck"})
public static void unstuck(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
player.print("There you go!");
player.findFreePosition();
}
@Command(
aliases = {"/ascend"},
usage = "",
desc = "Go up a floor",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.navigation.ascend"})
public static void ascend(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
if (player.ascendLevel()) {
player.print("Ascended a level.");
} else {
player.printError("No free spot above you found.");
}
}
@Command(
aliases = {"/descend"},
usage = "",
desc = "Go down a floor",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.navigation.descend"})
public static void descend(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
if (player.descendLevel()) {
player.print("Descended a level.");
} else {
player.printError("No free spot below you found.");
}
}
@Command(
aliases = {"/ceil"},
usage = "[clearance]",
desc = "Go to the celing",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.navigation.ceiling"})
public static void ceiling(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int clearence = args.argsLength() > 0 ?
Math.max(0, args.getInteger(0)) : 0;
if (player.ascendToCeiling(clearence)) {
player.print("Whoosh!");
} else {
player.printError("No free spot above you found.");
}
}
@Command(
aliases = {"/thru"},
usage = "",
desc = "Passthrough walls",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.navigation.thru"})
public static void thru(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
if (player.passThroughForwardWall(6)) {
player.print("Whoosh!");
} else {
player.printError("No free spot ahead of you found.");
}
}
@Command(
aliases = {"/jumpto"},
usage = "",
desc = "Teleport to a location",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.navigation.jumpto"})
public static void jumpTo(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
WorldVector pos = player.getSolidBlockTrace(300);
if (pos != null) {
player.findFreePosition(pos);
player.print("Poof!");
} else {
player.printError("No block in sight!");
}
}
@Command(
aliases = {"/up"},
usage = "<block>",
desc = "Go upwards some distance",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.navigation.up"})
public static void up(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int distance = args.getInteger(0);
if (player.ascendUpwards(distance)) {
player.print("Whoosh!");
} else {
player.printError("You would hit something above you.");
}
}
}

View File

@ -0,0 +1,225 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import java.util.Set;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.filters.GaussianKernel;
import com.sk89q.worldedit.filters.HeightMapFilter;
import com.sk89q.worldedit.patterns.*;
import com.sk89q.worldedit.regions.Region;
/**
* Region related commands.
*
* @author sk89q
*/
public class RegionCommands {
@Command(
aliases = {"//set"},
usage = "<block>",
desc = "Set all the blocks inside the selection to a block",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.region.set"})
public static void set(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Pattern pattern = we.getBlockPattern(player, args.getString(0));
int affected;
if (pattern instanceof SingleBlockPattern) {
affected = editSession.setBlocks(session.getRegion(),
((SingleBlockPattern)pattern).getBlock());
} else {
affected = editSession.setBlocks(session.getRegion(), pattern);
}
player.print(affected + " block(s) have been changed.");
}
@Command(
aliases = {"//replace"},
usage = "[from-block] <to-block>",
desc = "Replace all blocks in the selection with another",
min = 1,
max = 2
)
@CommandPermissions({"worldedit.region.replace"})
public static void replace(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Set<Integer> from;
Pattern to;
if (args.argsLength() == 1) {
from = null;
to = we.getBlockPattern(player, args.getString(0));
} else {
from = we.getBlockIDs(player, args.getString(0), true);
to = we.getBlockPattern(player, args.getString(1));
}
int affected = 0;
if (to instanceof SingleBlockPattern) {
affected = editSession.replaceBlocks(session.getRegion(), from,
((SingleBlockPattern)to).getBlock());
} else {
affected = editSession.replaceBlocks(session.getRegion(), from, to);
}
player.print(affected + " block(s) have been replaced.");
}
@Command(
aliases = {"//overlay"},
usage = "<block>",
desc = "Set a block on top of blocks in the region",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.region.overlay"})
public static void overlay(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0));
Region region = session.getRegion();
int affected = editSession.overlayCuboidBlocks(region, block);
player.print(affected + " block(s) have been overlayed.");
}
@Command(
aliases = {"//walls"},
usage = "<block>",
desc = "Build the four sides of the selection",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.region.walls"})
public static void walls(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0));
int affected = editSession.makeCuboidWalls(session.getRegion(), block);
player.print(affected + " block(s) have been changed.");
}
@Command(
aliases = {"//faces", "//outline"},
usage = "<block>",
desc = "Build the walls, ceiling, and roof of a selection",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.region.faces"})
public static void faces(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0));
int affected = editSession.makeCuboidFaces(session.getRegion(), block);
player.print(affected + " block(s) have been changed.");
}
@Command(
aliases = {"//smooth"},
usage = "[iterations]",
desc = "Smooth the elevation in the selection",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.region.smooth"})
public static void smooth(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int iterations = 1;
if (args.argsLength() > 0) {
iterations = args.getInteger(0);
}
HeightMap heightMap = new HeightMap(editSession, session.getRegion());
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
int affected = heightMap.applyFilter(filter, iterations);
player.print("Terrain's height map smoothed. " + affected + " block(s) changed.");
}
@Command(
aliases = {"//move"},
usage = "[count] [direction] [leave-id] ",
desc = "Move the contents of the selection",
min = 0,
max = 3
)
@CommandPermissions({"worldedit.region.move"})
public static void move(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
Vector dir = we.getDirection(player,
args.argsLength() > 1 ? args.getString(1).toLowerCase() : "me");
BaseBlock replace;
// Replacement block argument
if (args.argsLength() > 2) {
replace = we.getBlock(player, args.getString(2));
} else {
replace = new BaseBlock(0);
}
int affected = editSession.moveCuboidRegion(session.getRegion(),
dir, count, true, replace);
player.print(affected + " blocks moved.");
}
@Command(
aliases = {"//stack"},
usage = "[count] [direction] ",
desc = "Repeat the contents of the selection",
min = 0,
max = 2
)
@CommandPermissions({"worldedit.region.stack"})
public static void stack(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int count = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
Vector dir = we.getDirection(player,
args.argsLength() > 1 ? args.getString(1).toLowerCase() : "me");
int affected = editSession.stackCuboidRegion(session.getRegion(),
dir, count, true);
player.print(affected + " blocks changed. Undo with //undo");
}
}

View File

@ -0,0 +1,78 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
/**
* Scripting commands.
*
* @author sk89q
*/
public class ScriptingCommands {
@Command(
aliases = {"/cs"},
usage = "<filename> [args...]",
desc = "Execute a CraftScript",
min = 1,
max = -1
)
@CommandPermissions({"worldedit.scripting.execute"})
public static void execute(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
// @TODO: Check for worldedit.scripting.execute.<script> permission
String[] scriptArgs = args.getSlice(1);
session.setLastScript(args.getString(0));
we.runScript(player, args.getString(0), scriptArgs);
}
@Command(
aliases = {"/.s"},
usage = "[args...]",
desc = "Execute last CraftScript",
min = 0,
max = -1
)
@CommandPermissions({"worldedit.scripting.execute"})
public static void executeLast(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
// @TODO: Check for worldedit.scripting.execute.<script> permission
String lastScript = session.getLastScript();
if (lastScript == null) {
player.printError("Use /cs with a script name first.");
return;
}
String[] scriptArgs = args.getPaddedSlice(0, 1);
scriptArgs[0] = lastScript;
we.runScript(player, lastScript, scriptArgs);
}
}

View File

@ -0,0 +1,407 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import java.util.List;
import java.util.Set;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.data.ChunkStore;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.blocks.*;
/**
* Selection commands.
*
* @author sk89q
*/
public class SelectionCommands {
@Command(
aliases = {"//pos1"},
usage = "",
desc = "Set position 1",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.selection.pos"})
public static void pos1(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setPos1(player.getBlockIn());
if (session.isRegionDefined()) {
player.print("First position set to " + player.getBlockIn()
+ " (" + session.getRegion().getSize() + ").");
} else {
player.print("First position set to " + player.getBlockIn() + ".");
}
}
@Command(
aliases = {"//pos2"},
usage = "",
desc = "Set position 2",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.selection.pos"})
public static void pos2(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setPos2(player.getBlockIn());
if (session.isRegionDefined()) {
player.print("Second position set to " + player.getBlockIn()
+ " (" + session.getRegion().getSize() + ").");
} else {
player.print("Second position set to " + player.getBlockIn() + ".");
}
}
@Command(
aliases = {"//hpos1"},
usage = "",
desc = "Set position 1 to targeted block",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.selection.hpos"})
public static void hpos1(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Vector pos = player.getBlockTrace(300);
if (pos != null) {
session.setPos1(pos);
if (session.isRegionDefined()) {
player.print("First position set to " + pos
+ " (" + session.getRegion().getSize() + ").");
} else {
player.print("First position set to " + pos.toString() + " .");
}
} else {
player.printError("No block in sight!");
}
}
@Command(
aliases = {"//hpos2"},
usage = "",
desc = "Set position 2 to targeted block",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.selection.hpos"})
public static void hpos2(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Vector pos = player.getBlockTrace(300);
if (pos != null) {
session.setPos2(pos);
if (session.isRegionDefined()) {
player.print("Second position set to " + pos
+ " (" + session.getRegion().getSize() + ").");
} else {
player.print("Second position set to " + pos.toString() + " .");
}
} else {
player.printError("No block in sight!");
}
}
@Command(
aliases = {"//chunk"},
usage = "",
desc = "Set the selection to your current chunk",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.selection.chunk"})
public static void chunk(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Vector2D min2D = ChunkStore.toChunk(player.getBlockIn());
Vector min = new Vector(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
Vector max = min.add(15, 127, 15);
session.setPos1(min);
session.setPos2(max);
player.print("Chunk selected: "
+ min2D.getBlockX() + ", " + min2D.getBlockZ());
}
@Command(
aliases = {"//wand"},
usage = "",
desc = "Get the wand object",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.wand"})
public static void wand(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
player.giveItem(we.getConfiguration().wandItem, 1);
player.print("Left click: select pos #1; Right click: select pos #2");
}
@Command(
aliases = {"/toggleeditwand"},
usage = "",
desc = "Toggle functionality of the edit wand",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.wand.toggle"})
public static void toggleWand(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setToolControl(!session.isToolControlEnabled());
if (session.isToolControlEnabled()) {
player.print("Edit wand enabled.");
} else {
player.print("Edit wand disabled.");
}
}
@Command(
aliases = {"//expand"},
usage = "<amount> [[reverse-amount] <direction>]",
desc = "Expand the selection area",
min = 1,
max = 3
)
@CommandPermissions({"worldedit.selection.expand"})
public static void expand(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Vector dir;
int change = args.getInteger(0);
int reverseChange = 0;
// Special syntax (//expand vert) to expand the selection between
// sky and bedrock.
if (args.getString(0).equals("vert")
|| args.getString(0).equals("vertical")) {
Region region = session.getRegion();
int oldSize = region.getSize();
region.expand(new Vector(0, 128, 0));
region.expand(new Vector(0, -128, 0));
session.learnRegionChanges();
int newSize = region.getSize();
player.print("Region expanded " + (newSize - oldSize)
+ " blocks [top-to-bottom].");
return;
}
// Specifying a direction
if (args.argsLength() == 2) {
try {
reverseChange = args.getInteger(1) * -1;
dir = we.getDirection(player, "me");
} catch (NumberFormatException e) {
dir = we.getDirection(player,
args.getString(1).toLowerCase());
}
// Specifying a direction and a reverse amount
} else if (args.argsLength() == 3) {
reverseChange = args.getInteger(1) * -1;
dir = we.getDirection(player,
args.getString(2).toLowerCase());
} else {
dir = we.getDirection(player, "me");
}
Region region = session.getRegion();
int oldSize = region.getSize();
region.expand(dir.multiply(change));
if (reverseChange != 0) {
region.expand(dir.multiply(reverseChange));
}
session.learnRegionChanges();
int newSize = region.getSize();
player.print("Region expanded " + (newSize - oldSize) + " blocks.");
}
@Command(
aliases = {"//contract"},
usage = "<amount> [reverse-amount] [direction]",
desc = "Contract the selection area",
min = 1,
max = 3
)
@CommandPermissions({"worldedit.selection.contract"})
public static void contract(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Vector dir;
int change = args.getInteger(0);
int reverseChange = 0;
// Either a reverse amount or a direction
if (args.argsLength() == 2) {
try {
reverseChange = args.getInteger(1) * -1;
dir = we.getDirection(player, "me");
} catch (NumberFormatException e) {
dir = we.getDirection(player,
args.getString(1).toLowerCase());
}
// Both reverse amount and direction
} else if (args.argsLength() == 3) {
reverseChange = args.getInteger(1) * -1;
dir = we.getDirection(player,
args.getString(2).toLowerCase());
} else {
dir = we.getDirection(player, "me");
}
Region region = session.getRegion();
int oldSize = region.getSize();
region.contract(dir.multiply(change));
if (reverseChange != 0) {
region.contract(dir.multiply(reverseChange));
}
session.learnRegionChanges();
int newSize = region.getSize();
player.print("Region contracted " + (oldSize - newSize) + " blocks.");
}
@Command(
aliases = {"//shift"},
usage = "<amount> [direction]",
desc = "Shift the selection area",
min = 1,
max = 3
)
@CommandPermissions({"worldedit.selection.shift"})
public static void shift(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Vector dir;
int change = args.getInteger(0);
if (args.argsLength() == 2) {
dir = we.getDirection(player,
args.getString(1).toLowerCase());
} else {
dir = we.getDirection(player, "me");
}
Region region = session.getRegion();
region.expand(dir.multiply(change));
region.contract(dir.multiply(change));
session.learnRegionChanges();
player.print("Region shifted.");
}
@Command(
aliases = {"//size"},
usage = "",
desc = "Get information about the selection",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.selection.size"})
public static void size(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Region region = session.getRegion();
Vector size = region.getMaximumPoint()
.subtract(region.getMinimumPoint())
.add(1, 1, 1);
player.print("First position: " + session.getPos1());
player.print("Second position: " + session.getPos2());
player.print("Size: " + size);
player.print("# of blocks: " + region.getSize());
}
@Command(
aliases = {"//count"},
usage = "<block>",
desc = "Counts the number of a certain type of block",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.analysis.count"})
public static void count(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Set<Integer> searchIDs = we.getBlockIDs(player,
args.getString(1), true);
player.print("Counted: " +
editSession.countBlocks(session.getRegion(), searchIDs));
}
@Command(
aliases = {"//distr"},
usage = "",
desc = "Get the distribution of blocks in the selection",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.analysis.distr"})
public static void distr(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
List<Countable<Integer>> distribution =
editSession.getBlockDistribution(session.getRegion());
if (distribution.size() > 0) { // *Should* always be true
int size = session.getRegion().getSize();
player.print("# total blocks: " + size);
for (Countable<Integer> c : distribution) {
player.print(String.format("%-7s (%.3f%%) %s #%d",
String.valueOf(c.getAmount()),
c.getAmount() / (double)size * 100,
BlockType.fromID(c.getID()).getName(), c.getID()));
}
} else {
player.printError("No blocks counted.");
}
}
}

View File

@ -0,0 +1,199 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import java.io.IOException;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.data.ChunkStore;
import com.sk89q.worldedit.data.DataException;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.snapshots.InvalidSnapshotException;
import com.sk89q.worldedit.snapshots.Snapshot;
import com.sk89q.worldedit.snapshots.SnapshotRestore;
/**
* Snapshot commands.
*
* @author sk89q
*/
public class SnapshotCommands {
@Command(
aliases = {"/listsnapshots"},
usage = "[num]",
desc = "List snapshots",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.snapshots.list"})
public static void list(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int num = args.argsLength() > 0 ?
Math.min(40, Math.max(5, args.getInteger(0))) : 5;
if (config.snapshotRepo != null) {
Snapshot[] snapshots = config.snapshotRepo.getSnapshots();
if (snapshots.length > 0) {
for (byte i = 0; i < Math.min(num, snapshots.length); i++) {
player.print((i + 1) + ". " + snapshots[i].getName());
}
player.print("Use //use [snapshot] or //use latest to set the snapshot.");
} else {
player.printError("No snapshots are available.");
}
} else {
player.printError("Snapshot/backup restore is not configured.");
}
}
@Command(
aliases = {"//use"},
usage = "<snapshot>",
desc = "Choose a snapshot to use",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.snapshots.restore"})
public static void use(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
if (config.snapshotRepo == null) {
player.printError("Snapshot/backup restore is not configured.");
return;
}
String name = args.getString(0);
// Want the latest snapshot?
if (name.equalsIgnoreCase("latest")) {
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot();
if (snapshot != null) {
session.setSnapshot(null);
player.print("Now using newest snapshot.");
} else {
player.printError("No snapshots were found.");
}
} else {
try {
session.setSnapshot(config.snapshotRepo.getSnapshot(name));
player.print("Snapshot set to: " + name);
} catch (InvalidSnapshotException e) {
player.printError("That snapshot does not exist or is not available.");
}
}
}
@Command(
aliases = {"//restore"},
usage = "[snapshot]",
desc = "Restore the selection from a snapshot",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.snapshots.restore"})
public static void restore(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
if (config.snapshotRepo == null) {
player.printError("Snapshot/backup restore is not configured.");
return;
}
Region region = session.getRegion();
Snapshot snapshot;
if (args.argsLength() > 0) {
try {
snapshot = config.snapshotRepo.getSnapshot(args.getString(0));
} catch (InvalidSnapshotException e) {
player.printError("That snapshot does not exist or is not available.");
return;
}
} else {
snapshot = session.getSnapshot();
}
ChunkStore chunkStore = null;
// No snapshot set?
if (snapshot == null) {
snapshot = config.snapshotRepo.getDefaultSnapshot();
if (snapshot == null) {
player.printError("No snapshots were found.");
return;
}
}
// Load chunk store
try {
chunkStore = snapshot.getChunkStore();
player.print("Snapshot '" + snapshot.getName() + "' loaded; now restoring...");
} catch (DataException e) {
player.printError("Failed to load snapshot: " + e.getMessage());
return;
} catch (IOException e) {
player.printError("Failed to load snapshot: " + e.getMessage());
return;
}
try {
// Restore snapshot
SnapshotRestore restore = new SnapshotRestore(chunkStore, region);
//player.print(restore.getChunksAffected() + " chunk(s) will be loaded.");
restore.restore(editSession);
if (restore.hadTotalFailure()) {
String error = restore.getLastErrorMessage();
if (error != null) {
player.printError("Errors prevented any blocks from being restored.");
player.printError("Last error: " + error);
} else {
player.printError("No chunks could be loaded. (Bad archive?)");
}
} else {
player.print(String.format("Restored; %d "
+ "missing chunks and %d other errors.",
restore.getMissingChunks().size(),
restore.getErrorChunks().size()));
}
} finally {
try {
chunkStore.close();
} catch (IOException e) {
}
}
}
}

View File

@ -0,0 +1,280 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.superpickaxe.*;
/**
* Super pickaxe commands.
*
* @author sk89q
*/
public class SuperPickaxeCommands {
@Command(
aliases = {"//", "/,"},
usage = "",
desc = "Toggle the super pickaxe pickaxe function",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.pickaxe"})
public static void togglePickaxe(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
if (session.toggleSuperPickAxe()) {
player.print("Super pick axe enabled.");
} else {
player.print("Super pick axe disabled.");
}
}
@Command(
aliases = {"/single"},
usage = "",
desc = "Enable the single block super pickaxe mode",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.pickaxe"})
public static void single(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setLeftClickMode(new SinglePickaxe());
session.enableSuperPickAxe();
player.print("Mode changed. Left click with a pickaxe. // to disable.");
}
@Command(
aliases = {"/area"},
usage = "<radius>",
desc = "Enable the area super pickaxe pickaxe mode",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.superpickaxe.pickaxe.area"})
public static void area(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int range = args.getInteger(0);
if (range > config.maxSuperPickaxeSize) {
player.printError("Maximum range: " + config.maxSuperPickaxeSize);
return;
}
session.setLeftClickMode(new AreaPickaxe(range));
session.enableSuperPickAxe();
player.print("Mode changed. Left click with a pickaxe. // to disable.");
}
@Command(
aliases = {"/recur"},
usage = "<radius>",
desc = "Enable the recursive super pickaxe pickaxe mode",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.superpickaxe.pickaxe.recursive"})
public static void recursive(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int range = args.getInteger(0);
if (range > config.maxSuperPickaxeSize) {
player.printError("Maximum range: " + config.maxSuperPickaxeSize);
return;
}
session.setLeftClickMode(new RecursivePickaxe(range));
session.enableSuperPickAxe();
player.print("Mode changed. Left click with a pickaxe. // to disable.");
}
@Command(
aliases = {"/none"},
usage = "",
desc = "Turn off all superpickaxe alternate modes",
min = 0,
max = 0
)
public static void none(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setArmSwingMode(null);
session.setRightClickMode(null);
player.print("Now no longer equipping a tool.");
}
@Command(
aliases = {"/info"},
usage = "",
desc = "Block information tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.info"})
public static void info(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setArmSwingMode(null);
session.setRightClickMode(new QueryTool());
player.print("Info tool equipped. Right click with a pickaxe.");
}
@Command(
aliases = {"/tree"},
usage = "",
desc = "Tree generator tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.tree"})
public static void tree(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setArmSwingMode(null);
session.setRightClickMode(new TreePlanter());
player.print("Tree tool equipped. Right click grass with a pickaxe.");
}
@Command(
aliases = {"/bigtree"},
usage = "",
desc = "Big tree generator tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.tree.big"})
public static void bigTree(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setArmSwingMode(null);
session.setRightClickMode(new BigTreePlanter());
player.print("Big tree tool equipped. Right click grass with a pickaxe.");
}
@Command(
aliases = {"/pinetree"},
usage = "",
desc = "Pine tree generator tool",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.superpickaxe.tree.pine"})
public static void pineTree(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
session.setArmSwingMode(null);
session.setRightClickMode(new PineTreePlanter());
player.print("Pine tree tool equipped. Right click a block with a pickaxe.");
}
@Command(
aliases = {"/repl"},
usage = "<block>",
desc = "Block replacer tool",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.superpickaxe.replacer"})
public static void repl(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock targetBlock = we.getBlock(player, args.getString(0));
session.setArmSwingMode(null);
session.setRightClickMode(new BlockReplacer(targetBlock));
player.print("Block replacer tool equipped. Right click with a pickaxe.");
}
@Command(
aliases = {"/brush"},
usage = "<block> [radius] [no-replace?]",
desc = "Build spheres from far away",
min = 1,
max = 3
)
@CommandPermissions({"worldedit.superpickaxe.drawing.brush"})
public static void brush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int radius = args.argsLength() > 1 ? args.getInteger(1) : 2;
boolean nonReplacing = args.argsLength() > 2
? (args.getString(2).equalsIgnoreCase("true")
|| args.getString(2).equalsIgnoreCase("yes")) : false;
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
BaseBlock targetBlock = we.getBlock(player, args.getString(0));
session.setRightClickMode(null);
session.setArmSwingMode(new SphereBrush(targetBlock, radius, nonReplacing));
if (nonReplacing) {
player.print("Non-replacing sphere brush tool equipped.");
} else {
player.print("Sphere brush tool equipped. Swing with a pickaxe.");
}
}
@Command(
aliases = {"/rbrush"},
usage = "<block> [radius] ",
desc = "Brush tool that will only replace blocks",
min = 1,
max = 2
)
@CommandPermissions({"worldedit.superpickaxe.drawing.brush"})
public static void rbrush(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int radius = args.argsLength() > 1 ? args.getInteger(1) : 2;
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
BaseBlock targetBlock = we.getBlock(player, args.getString(0));
session.setRightClickMode(null);
session.setArmSwingMode(new ReplacingSphereBrush(targetBlock, radius));
player.print("Replacing sphere brush tool equipped. Swing with a pickaxe.");
}
}

View File

@ -0,0 +1,325 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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;
import java.util.Set;
import com.sk89q.util.commands.Command;
import com.sk89q.util.commands.CommandContext;
import com.sk89q.worldedit.*;
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 {
@Command(
aliases = {"//fill"},
usage = " <block> <radius> [depth] ",
desc = "Fill a hole",
min = 2,
max = 3
)
@CommandPermissions({"worldedit.fill"})
public static void fill(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Pattern pattern = we.getBlockPattern(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1));
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,
((SingleBlockPattern)pattern).getBlock(),
radius, depth, false);
} else {
affected = editSession.fillXZ(pos, pattern, radius, depth, false);
}
player.print(affected + " block(s) have been created.");
}
@Command(
aliases = {"//fillr"},
usage = " <block> <radius> [depth] ",
desc = "Fill a hole recursively",
min = 2,
max = 3
)
@CommandPermissions({"worldedit.fill.recursive"})
public static void fillr(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
Pattern pattern = we.getBlockPattern(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1));
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,
((SingleBlockPattern)pattern).getBlock(),
radius, depth, true);
} else {
affected = editSession.fillXZ(pos, pattern, radius, depth, true);
}
player.print(affected + " block(s) have been created.");
}
@Command(
aliases = {"//drain"},
usage = "<radius>",
desc = "Drain a pool",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.drain"})
public static void drain(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int radius = Math.max(0, args.getInteger(0));
we.checkMaxRadius(radius);
int affected = editSession.drainArea(
session.getPlacementPosition(player), radius);
player.print(affected + " block(s) have been changed.");
}
@Command(
aliases = {"/fixlava"},
usage = "<radius>",
desc = "Fix lava to be stationary",
min = 1,
max = 1
)
@CommandPermissions({"worldedit.fixlava"})
public static void fixLava(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int radius = Math.max(0, args.getInteger(0));
we.checkMaxRadius(radius);
int affected = editSession.fixLiquid(
session.getPlacementPosition(player), radius, 10, 11);
player.print(affected + " block(s) have been changed.");
}
@Command(
aliases = {"/fixwater"},
usage = "<radius>",
desc = "Fix water to be stationary",
min = 1,
max = 1
)
@CommandPermissions({"fixWater"})
public static void fixWater(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int radius = Math.max(0, args.getInteger(0));
we.checkMaxRadius(radius);
int affected = editSession.fixLiquid(
session.getPlacementPosition(player), radius, 8, 9);
player.print(affected + " block(s) have been changed.");
}
@Command(
aliases = {"/removeabove"},
usage = "[size] [height] ",
desc = "Remove blocks above your head. ",
min = 0,
max = 2
)
@CommandPermissions({"worldedit.removeabove"})
public static void removeAbove(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
we.checkMaxRadius(size);
int height = args.argsLength() > 1 ? Math.min(128, args.getInteger(1) + 2) : 128;
int affected = editSession.removeAbove(
session.getPlacementPosition(player), size, height);
player.print(affected + " block(s) have been removed.");
}
@Command(
aliases = {"/removebelow"},
usage = "[size] [height] ",
desc = "Remove blocks below your head. ",
min = 0,
max = 2
)
@CommandPermissions({"worldedit.removebelow"})
public static void removeBelow(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
we.checkMaxRadius(size);
int height = args.argsLength() > 1 ? Math.min(128, args.getInteger(1) + 2) : 128;
int affected = editSession.removeBelow(
session.getPlacementPosition(player), size, height);
player.print(affected + " block(s) have been removed.");
}
@Command(
aliases = {"/removenear"},
usage = "<block> [size] ",
desc = "Remove blocks near you.",
min = 1,
max = 2
)
@CommandPermissions({"worldedit.removenear"})
public static void removeNear(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
BaseBlock block = we.getBlock(player, args.getString(0), true);
int size = Math.max(1, args.getInteger(1));
we.checkMaxRadius(size);
int affected = editSession.removeNear(
session.getPlacementPosition(player), block.getType(), size);
player.print(affected + " block(s) have been removed.");
}
@Command(
aliases = {"/replacenear"},
usage = "<size> <from-id> <to-id> ",
desc = "Replace nearby blocks",
min = 3,
max = 3
)
@CommandPermissions({"worldedit.replacenear"})
public static void replaceNear(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = Math.max(1, args.getInteger(0));
Set<Integer> from;
BaseBlock to;
if (args.argsLength() == 2) {
from = null;
to = we.getBlock(player, args.getString(1));
} else {
from = we.getBlockIDs(player, args.getString(1), true);
to = we.getBlock(player, args.getString(2));
}
Vector min = player.getBlockIn().subtract(size, size, size);
Vector max = player.getBlockIn().add(size, size, size);
Region region = new CuboidRegion(min, max);
int affected = editSession.replaceBlocks(region, from, to);
player.print(affected + " block(s) have been replaced.");
}
@Command(
aliases = {"/snow"},
usage = "[radius]",
desc = "Simulates snow",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.snow"})
public static void snow(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
int affected = editSession.simulateSnow(player.getBlockIn(), size);
player.print(affected + " surfaces covered. Let it snow~");
}
@Command(
aliases = {"/thaw"},
usage = "[radius]",
desc = "Thaws the area",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.thaw"})
public static void thaw(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
int affected = editSession.thaw(player.getBlockIn(), size);
player.print(affected + " surfaces thawed.");
}
@Command(
aliases = {"/ex", "/ext", "/extinguish"},
usage = "[radius]",
desc = "Extinguish nearby fire",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.extinguish"})
public static void extinguish(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0))
: defaultRadius;
we.checkMaxRadius(size);
int affected = editSession.removeNear(
session.getPlacementPosition(player), 51, size);
player.print(affected + " block(s) have been removed.");
}
@Command(
aliases = {"/butcher"},
usage = "[radius]",
desc = "Kill all or nearby mobs",
min = 0,
max = 1
)
@CommandPermissions({"worldedit.butcher"})
public static void butcher(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int radius = args.argsLength() > 0 ?
Math.max(1, args.getInteger(0)) : -1;
Vector origin = session.getPlacementPosition(player);
int killed = player.getWorld().killMobs(origin, radius);
player.print("Killed " + killed + " mobs.");
}
}

View File

@ -27,7 +27,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import com.sk89q.worldedit.DisallowedItemException; import com.sk89q.worldedit.DisallowedItemException;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.InsufficientArgumentsException;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -35,6 +34,7 @@ import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.UnknownItemException; import com.sk89q.worldedit.UnknownItemException;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.commands.InsufficientArgumentsException;
import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.patterns.Pattern;
/** /**