Improved the quality of the command-related messages and renamed /setchangelimit to /editlimit.

This commit is contained in:
sk89q 2010-10-04 23:08:08 -07:00
parent 87780f0a78
commit c0a9d0d551

View File

@ -57,19 +57,19 @@ public class WorldEdit extends Plugin {
commands.put("/clearhistory", "Clear history"); commands.put("/clearhistory", "Clear history");
commands.put("/clearclipboard", "Clear clipboard"); commands.put("/clearclipboard", "Clear clipboard");
commands.put("/editsize", "Get size of selected region"); commands.put("/editsize", "Get size of selected region");
commands.put("/editset", "<Type> - Set all blocks inside region"); commands.put("/editset", "[ID] - Set all blocks inside region");
commands.put("/editoutline", "<Type> - Outline the region with blocks"); commands.put("/editoutline", "[ID] - Outline the region with blocks");
commands.put("/editreplace", "<ID> <ToReplaceID> - Replace all existing blocks inside region"); commands.put("/editreplace", "[ID] <ToReplaceID> - Replace all existing blocks inside region");
commands.put("/editoverlay", "<ID> - Overlay the area one layer"); commands.put("/editoverlay", "[ID] - Overlay the area one layer");
commands.put("/removeabove", "<Size> - Remove blocks above head"); commands.put("/removeabove", "<Size> - Remove blocks above head");
commands.put("/editcopy", "Copies the currently selected region"); commands.put("/editcopy", "Copies the currently selected region");
commands.put("/editpaste", "Pastes the clipboard"); commands.put("/editpaste", "Pastes the clipboard");
commands.put("/editpasteair", "Pastes the clipboard (with air)"); commands.put("/editpasteair", "Pastes the clipboard (with air)");
commands.put("/editload", "[Filename] - Load .schematic into clipboard"); commands.put("/editload", "[Filename] - Load .schematic into clipboard");
commands.put("/editsave", "[Filename] - Save clipboard to .schematic"); commands.put("/editsave", "[Filename] - Save clipboard to .schematic");
commands.put("/editfill", "<ID> <Radius> <Depth> - Fill a hole"); commands.put("/editfill", "[ID] [Radius] <Depth> - Fill a hole");
commands.put("/editscript", "[Filename] <Args...> - Run a WorldEdit script"); commands.put("/editscript", "[Filename] <Args...> - Run a WorldEdit script");
commands.put("/setchangelimit", "<Num> - See documentation"); commands.put("/editlimit", "[Num] - See documentation");
} }
/** /**
@ -148,15 +148,23 @@ public class WorldEdit extends Plugin {
} }
/** /**
* Checks to make sure that there are enough arguments. * Checks to make sure that there are enough but not too many arguments.
* *
* @param args * @param args
* @param min * @param min
* @param max -1 for no maximum
* @param cmd command name
* @throws InsufficientArgumentsException * @throws InsufficientArgumentsException
*/ */
private void checkArgs(String[] args, int min) throws InsufficientArgumentsException { private void checkArgs(String[] args, int min, int max, String cmd)
if (args.length <= min) { throws InsufficientArgumentsException {
throw new InsufficientArgumentsException(String.format("Min. %d arguments required", min)); if (args.length <= min || (max != -1 && args.length - 1 > max)) {
if (commands.containsKey(cmd)) {
throw new InsufficientArgumentsException(cmd + " usage: " +
commands.get(cmd));
} else {
throw new InsufficientArgumentsException("Invalid number of arguments");
}
} }
} }
@ -345,12 +353,13 @@ public class WorldEdit extends Plugin {
player.sendMessage(Colors.LightPurple + "Second edit position set."); player.sendMessage(Colors.LightPurple + "Second edit position set.");
return true; return true;
// Set edit position #2 // Set max number of blocks to change at a time
} else if (split[0].equalsIgnoreCase("/setchangelimit")) { } else if (split[0].equalsIgnoreCase("/editlimit")) {
checkArgs(split, 1); checkArgs(split, 1, 1, "/editlimit");
int limit = Math.max(-1, Integer.parseInt(split[1])); int limit = Math.max(-1, Integer.parseInt(split[1]));
session.setBlockChangeLimit(limit); session.setBlockChangeLimit(limit);
player.sendMessage(Colors.LightPurple + "Block change limit set."); player.sendMessage(Colors.LightPurple + "Block change limit set to "
+ limit + ".");
return true; return true;
// Undo // Undo
@ -395,16 +404,16 @@ public class WorldEdit extends Plugin {
session.getClipboard().paste(editSession, pos, session.getClipboard().paste(editSession, pos,
split[0].equalsIgnoreCase("/editpaste")); split[0].equalsIgnoreCase("/editpaste"));
logger.log(Level.INFO, player.getName() + " used " + split[0]); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + "Pasted."); player.sendMessage(Colors.LightPurple + "Pasted. Undo with /editundo");
} }
return true; return true;
// Fill a hole // Fill a hole
} else if (split[0].equalsIgnoreCase("/editfill")) { } else if (split[0].equalsIgnoreCase("/editfill")) {
checkArgs(split, 1); checkArgs(split, 2, 3, "/editfill");
int blockType = getItem(split[1]); int blockType = getItem(split[1]);
int radius = split.length > 2 ? Math.max(1, Integer.parseInt(split[2])) : 50; int radius = Math.max(1, Integer.parseInt(split[2]));
int depth = split.length > 3 ? Math.max(1, Integer.parseInt(split[3])) : 1; int depth = split.length > 3 ? Math.max(1, Integer.parseInt(split[3])) : 1;
int cx = (int)Math.floor(player.getX()); int cx = (int)Math.floor(player.getX());
@ -415,7 +424,7 @@ public class WorldEdit extends Plugin {
int affected = fill(editSession, cx, cz, cx, cy, cz, int affected = fill(editSession, cx, cz, cx, cy, cz,
blockType, radius, minY); blockType, radius, minY);
logger.log(Level.INFO, player.getName() + " used /editfill"); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + affected + " block(s) have been created."); player.sendMessage(Colors.LightPurple + affected + " block(s) have been created.");
return true; return true;
@ -440,14 +449,14 @@ public class WorldEdit extends Plugin {
} }
} }
logger.log(Level.INFO, player.getName() + " used /removeabove"); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + affected + " block(s) have been removed."); player.sendMessage(Colors.LightPurple + affected + " block(s) have been removed.");
return true; return true;
// Load .schematic to clipboard // Load .schematic to clipboard
} else if (split[0].equalsIgnoreCase("/editload")) { } else if (split[0].equalsIgnoreCase("/editload")) {
checkArgs(split, 1); checkArgs(split, 1, 1, "/editload");
String filename = split[1].replace("\0", "") + ".schematic"; String filename = split[1].replace("\0", "") + ".schematic";
File dir = new File("schematics"); File dir = new File("schematics");
File f = new File("schematics", filename); File f = new File("schematics", filename);
@ -482,7 +491,7 @@ public class WorldEdit extends Plugin {
return true; return true;
} }
checkArgs(split, 1); checkArgs(split, 1, 1, "/editsave");
String filename = split[1].replace("\0", "") + ".schematic"; String filename = split[1].replace("\0", "") + ".schematic";
File dir = new File("schematics"); File dir = new File("schematics");
File f = new File("schematics", filename); File f = new File("schematics", filename);
@ -521,7 +530,7 @@ public class WorldEdit extends Plugin {
// Run a script // Run a script
} else if (split[0].equalsIgnoreCase("/editscript")) { } else if (split[0].equalsIgnoreCase("/editscript")) {
checkArgs(split, 1); checkArgs(split, 1, -1, "/editscript");
String filename = split[1].replace("\0", "") + ".js"; String filename = split[1].replace("\0", "") + ".js";
String[] args = new String[split.length - 2]; String[] args = new String[split.length - 2];
System.arraycopy(split, 2, args, 0, split.length - 2); System.arraycopy(split, 2, args, 0, split.length - 2);
@ -547,7 +556,7 @@ public class WorldEdit extends Plugin {
// Replace all blocks in the region // Replace all blocks in the region
} else if(split[0].equalsIgnoreCase("/editset")) { } else if(split[0].equalsIgnoreCase("/editset")) {
checkArgs(split, 1); checkArgs(split, 1, 1, "/editset");
int blockType = getItem(split[1]); int blockType = getItem(split[1]);
int affected = 0; int affected = 0;
@ -560,14 +569,14 @@ public class WorldEdit extends Plugin {
} }
} }
logger.log(Level.INFO, player.getName() + " used /editset"); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + affected + " block(s) have been set."); player.sendMessage(Colors.LightPurple + affected + " block(s) have been set.");
return true; return true;
// Set the outline of a region // Set the outline of a region
} else if(split[0].equalsIgnoreCase("/editoutline")) { } else if(split[0].equalsIgnoreCase("/editoutline")) {
checkArgs(split, 1); checkArgs(split, 1, 1, "/editoutline");
int blockType = getItem(split[1]); int blockType = getItem(split[1]);
int affected = 0; int affected = 0;
@ -595,14 +604,14 @@ public class WorldEdit extends Plugin {
} }
} }
logger.log(Level.INFO, player.getName() + " used /editoutline"); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + affected + " block(s) have been set."); player.sendMessage(Colors.LightPurple + affected + " block(s) have been set.");
return true; return true;
// Replace all blocks in the region // Replace all blocks in the region
} else if(split[0].equalsIgnoreCase("/editreplace")) { } else if(split[0].equalsIgnoreCase("/editreplace")) {
checkArgs(split, 1); checkArgs(split, 1, 2, "/editreplace");
int blockType = getItem(split[1]); int blockType = getItem(split[1]);
int replaceType = split.length > 2 ? getItem(split[2], true) : -1; int replaceType = split.length > 2 ? getItem(split[2], true) : -1;
@ -620,14 +629,14 @@ public class WorldEdit extends Plugin {
} }
} }
logger.log(Level.INFO, player.getName() + " used /editreplace"); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + affected + " block(s) have been replaced."); player.sendMessage(Colors.LightPurple + affected + " block(s) have been replaced.");
return true; return true;
// Lay blocks over an area // Lay blocks over an area
} else if (split[0].equalsIgnoreCase("/editoverlay")) { } else if (split[0].equalsIgnoreCase("/editoverlay")) {
checkArgs(split, 1); checkArgs(split, 1, 1, "/editoverlay");
int blockType = getItem(split[1]); int blockType = getItem(split[1]);
// We don't want to pass beyond boundaries // We don't want to pass beyond boundaries
@ -648,7 +657,7 @@ public class WorldEdit extends Plugin {
} }
} }
logger.log(Level.INFO, player.getName() + " used /editoverlay"); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + affected + " block(s) have been overlayed."); player.sendMessage(Colors.LightPurple + affected + " block(s) have been overlayed.");
return true; return true;
@ -665,7 +674,7 @@ public class WorldEdit extends Plugin {
clipboard.copy(editSession); clipboard.copy(editSession);
session.setClipboard(clipboard); session.setClipboard(clipboard);
logger.log(Level.INFO, player.getName() + " used /editcopy"); logger.log(Level.INFO, player.getName() + " used " + split[0]);
player.sendMessage(Colors.LightPurple + "Block(s) copied."); player.sendMessage(Colors.LightPurple + "Block(s) copied.");
return true; return true;