mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-16 17:16:11 +00: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 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++;
|
||||
}
|
||||
|
@ -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.");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user