Added support for replacing a list of blocks with one block with //replace.

Dieser Commit ist enthalten in:
sk89q 2010-11-06 09:35:05 -07:00
Ursprung cd16ca3abb
Commit 01340152e3
4 geänderte Dateien mit 42 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -546,7 +546,7 @@ public class EditSession {
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int replaceBlocks(Region region, int fromBlockType, BaseBlock toBlock)
public int replaceBlocks(Region region, Set<Integer> fromBlockTypes, BaseBlock toBlock)
throws MaxChangedBlocksException {
int affected = 0;
@ -561,8 +561,8 @@ public class EditSession {
Vector pt = new Vector(x, y, z);
int curBlockType = getBlock(pt).getID();
if (fromBlockType == -1 && curBlockType != 0 ||
curBlockType == fromBlockType) {
if (fromBlockTypes == null && curBlockType != 0 ||
fromBlockTypes.contains(curBlockType)) {
if (setBlock(pt, toBlock)) {
affected++;
}
@ -574,8 +574,8 @@ public class EditSession {
for (Vector pt : region) {
int curBlockType = getBlock(pt).getID();
if (fromBlockType == -1 && curBlockType != 0 ||
curBlockType == fromBlockType) {
if (fromBlockTypes == null && curBlockType != 0 ||
fromBlockTypes.contains(curBlockType)) {
if (setBlock(pt, toBlock)) {
affected++;
}

Datei anzeigen

@ -227,7 +227,7 @@ public class WorldEditListener extends PluginListener {
}
if (blockType == null) {
throw new UnknownItemException();
throw new UnknownItemException(arg);
}
// Check if the item is allowed
@ -245,7 +245,7 @@ public class WorldEditListener extends PluginListener {
return new BaseBlock(blockType.getID(), data);
}
throw new DisallowedItemException();
throw new DisallowedItemException(arg);
}
/**
@ -261,6 +261,19 @@ public class WorldEditListener extends PluginListener {
return getBlock(id, false);
}
/**
* Get a list of blocks as a set.
*/
public Set<Integer> getBlockIDs(String list) throws UnknownItemException,
DisallowedItemException {
String[] items = list.split(",");
Set<Integer> blocks = new HashSet<Integer>();
for (String s : items) {
blocks.add(getBlock(s).getID());
}
return blocks;
}
/**
* Checks to make sure that there are enough but not too many arguments.
*
@ -764,13 +777,13 @@ public class WorldEditListener extends PluginListener {
// Replace all blocks in the region
} else if(split[0].equalsIgnoreCase("//replace")) {
checkArgs(split, 1, 2, split[0]);
int from;
Set<Integer> from;
BaseBlock to;
if (split.length == 2) {
from = -1;
from = null;
to = getBlock(split[1], true);
} else {
from = getBlock(split[1]).getID();
from = getBlockIDs(split[1]);
to = getBlock(split[2]);
}
@ -1374,9 +1387,9 @@ public class WorldEditListener extends PluginListener {
} catch (IncompleteRegionException e2) {
ply.sendMessage(Colors.Rose + "The edit region has not been fully defined.");
} catch (UnknownItemException e3) {
ply.sendMessage(Colors.Rose + "Block name was not recognized.");
ply.sendMessage(Colors.Rose + "Block name '" + e3.getID() + "' was not recognized.");
} catch (DisallowedItemException e4) {
ply.sendMessage(Colors.Rose + "Block not allowed (see WorldEdit configuration).");
ply.sendMessage(Colors.Rose + "Block '" + e4.getID() + "' not allowed (see WorldEdit configuration).");
} catch (MaxChangedBlocksException e5) {
ply.sendMessage(Colors.Rose + "The maximum number of blocks changed ("
+ e5.getBlockLimit() + ") in an instance was reached.");

Datei anzeigen

@ -24,5 +24,13 @@ package com.sk89q.worldedit;
* @author sk89q
*/
public class DisallowedItemException extends WorldEditException {
private String type;
public DisallowedItemException(String type) {
this.type = type;
}
public String getID() {
return type;
}
}

Datei anzeigen

@ -25,5 +25,13 @@ package com.sk89q.worldedit;
* @author sk89q
*/
public class UnknownItemException extends WorldEditException {
private String type;
public UnknownItemException(String type) {
this.type = type;
}
public String getID() {
return type;
}
}