mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-15 04:41:37 +08:00
Added support for replacing a list of blocks with one block with //replace.
This commit is contained in:
parent
cd16ca3abb
commit
01340152e3
@ -546,7 +546,7 @@ public int setBlocks(Region region, BaseBlock block)
|
|||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int replaceBlocks(Region region, int fromBlockType, BaseBlock toBlock)
|
public int replaceBlocks(Region region, Set<Integer> fromBlockTypes, BaseBlock toBlock)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
|
|
||||||
@ -561,8 +561,8 @@ public int replaceBlocks(Region region, int fromBlockType, BaseBlock toBlock)
|
|||||||
Vector pt = new Vector(x, y, z);
|
Vector pt = new Vector(x, y, z);
|
||||||
int curBlockType = getBlock(pt).getID();
|
int curBlockType = getBlock(pt).getID();
|
||||||
|
|
||||||
if (fromBlockType == -1 && curBlockType != 0 ||
|
if (fromBlockTypes == null && curBlockType != 0 ||
|
||||||
curBlockType == fromBlockType) {
|
fromBlockTypes.contains(curBlockType)) {
|
||||||
if (setBlock(pt, toBlock)) {
|
if (setBlock(pt, toBlock)) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
@ -574,8 +574,8 @@ public int replaceBlocks(Region region, int fromBlockType, BaseBlock toBlock)
|
|||||||
for (Vector pt : region) {
|
for (Vector pt : region) {
|
||||||
int curBlockType = getBlock(pt).getID();
|
int curBlockType = getBlock(pt).getID();
|
||||||
|
|
||||||
if (fromBlockType == -1 && curBlockType != 0 ||
|
if (fromBlockTypes == null && curBlockType != 0 ||
|
||||||
curBlockType == fromBlockType) {
|
fromBlockTypes.contains(curBlockType)) {
|
||||||
if (setBlock(pt, toBlock)) {
|
if (setBlock(pt, toBlock)) {
|
||||||
affected++;
|
affected++;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ public BaseBlock getBlock(String arg, boolean allAllowed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (blockType == null) {
|
if (blockType == null) {
|
||||||
throw new UnknownItemException();
|
throw new UnknownItemException(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the item is allowed
|
// Check if the item is allowed
|
||||||
@ -245,7 +245,7 @@ public BaseBlock getBlock(String arg, boolean allAllowed)
|
|||||||
return new BaseBlock(blockType.getID(), data);
|
return new BaseBlock(blockType.getID(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new DisallowedItemException();
|
throw new DisallowedItemException(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -257,10 +257,23 @@ public BaseBlock getBlock(String arg, boolean allAllowed)
|
|||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public BaseBlock getBlock(String id) throws UnknownItemException,
|
public BaseBlock getBlock(String id) throws UnknownItemException,
|
||||||
DisallowedItemException {
|
DisallowedItemException {
|
||||||
return getBlock(id, false);
|
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.
|
* Checks to make sure that there are enough but not too many arguments.
|
||||||
*
|
*
|
||||||
@ -764,13 +777,13 @@ public boolean performCommand(WorldEditPlayer player,
|
|||||||
// Replace all blocks in the region
|
// Replace all blocks in the region
|
||||||
} else if(split[0].equalsIgnoreCase("//replace")) {
|
} else if(split[0].equalsIgnoreCase("//replace")) {
|
||||||
checkArgs(split, 1, 2, split[0]);
|
checkArgs(split, 1, 2, split[0]);
|
||||||
int from;
|
Set<Integer> from;
|
||||||
BaseBlock to;
|
BaseBlock to;
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
from = -1;
|
from = null;
|
||||||
to = getBlock(split[1], true);
|
to = getBlock(split[1], true);
|
||||||
} else {
|
} else {
|
||||||
from = getBlock(split[1]).getID();
|
from = getBlockIDs(split[1]);
|
||||||
to = getBlock(split[2]);
|
to = getBlock(split[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1374,9 +1387,9 @@ public boolean onCommand(Player ply, String[] split) {
|
|||||||
} catch (IncompleteRegionException e2) {
|
} catch (IncompleteRegionException e2) {
|
||||||
ply.sendMessage(Colors.Rose + "The edit region has not been fully defined.");
|
ply.sendMessage(Colors.Rose + "The edit region has not been fully defined.");
|
||||||
} catch (UnknownItemException e3) {
|
} 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) {
|
} 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) {
|
} catch (MaxChangedBlocksException e5) {
|
||||||
ply.sendMessage(Colors.Rose + "The maximum number of blocks changed ("
|
ply.sendMessage(Colors.Rose + "The maximum number of blocks changed ("
|
||||||
+ e5.getBlockLimit() + ") in an instance was reached.");
|
+ e5.getBlockLimit() + ") in an instance was reached.");
|
||||||
|
@ -24,5 +24,13 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class DisallowedItemException extends WorldEditException {
|
public class DisallowedItemException extends WorldEditException {
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public DisallowedItemException(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getID() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,13 @@
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class UnknownItemException extends WorldEditException {
|
public class UnknownItemException extends WorldEditException {
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public UnknownItemException(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getID() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user