Reduced indentation level in some methods in WorldEdit.java and made WorldEdit.getBlock less confusing.

This commit is contained in:
TomyLobo 2013-11-29 23:35:06 +01:00
parent 3acc82e97b
commit 8dbabe344d

View File

@ -391,10 +391,13 @@ public class WorldEdit {
String[] blockAndExtraData = arg.split("\\|");
String[] typeAndData = blockAndExtraData[0].split(":", 2);
String testID = typeAndData[0];
int blockId = -1;
int data = -1;
boolean parseDataValue = true;
// Attempt to parse the item ID or otherwise resolve an item/block
// name to its numeric ID
try {
@ -414,13 +417,15 @@ public class WorldEdit {
if (blockId == -1 && blockType == null) {
// Maybe it's a cloth
ClothColor col = ClothColor.lookup(testID);
if (col != null) {
blockType = BlockType.CLOTH;
data = col.getID();
} else {
if (col == null) {
throw new UnknownItemException(arg);
}
blockType = BlockType.CLOTH;
data = col.getID();
// Prevent overriding the data value
parseDataValue = false;
}
// Read block ID
@ -432,33 +437,50 @@ public class WorldEdit {
throw new UnknownItemException(arg);
}
if (data == -1) { // Block data not yet detected
if (!allowNoData && data == -1) {
// No wildcards allowed => eliminate them.
data = 0;
}
if (parseDataValue) { // Block data not yet detected
// Parse the block data (optional)
try {
data = (typeAndData.length > 1 && typeAndData[1].length() > 0) ? Integer.parseInt(typeAndData[1]) : (allowNoData ? -1 : 0);
if (data > 15 || (data < 0 && !(allAllowed && data == -1))) {
if (typeAndData.length > 1 && typeAndData[1].length() > 0) {
data = Integer.parseInt(typeAndData[1]);
}
if (data > 15) {
throw new InvalidItemException(arg, "Unknown invalid data value '" + typeAndData[1] + "'");
}
if (data < 0 && !(allAllowed && data == -1)) {
data = 0;
}
} catch (NumberFormatException e) {
if (blockType != null) {
if (blockType == null) {
throw new InvalidItemException(arg, "Unknown data value '" + typeAndData[1] + "'");
}
switch (blockType) {
case CLOTH:
case STAINED_CLAY:
case CARPET:
ClothColor col = ClothColor.lookup(typeAndData[1]);
if (col != null) {
data = col.getID();
} else {
if (col == null) {
throw new InvalidItemException(arg, "Unknown cloth color '" + typeAndData[1] + "'");
}
data = col.getID();
break;
case STEP:
case DOUBLE_STEP:
BlockType dataType = BlockType.lookup(typeAndData[1]);
if (dataType != null) {
if (dataType == null) {
throw new InvalidItemException(arg, "Unknown step type '" + typeAndData[1] + "'");
}
switch (dataType) {
case STONE:
data = 0;
@ -488,23 +510,23 @@ public class WorldEdit {
default:
throw new InvalidItemException(arg, "Invalid step type '" + typeAndData[1] + "'");
}
} else {
throw new InvalidItemException(arg, "Unknown step type '" + typeAndData[1] + "'");
}
break;
default:
throw new InvalidItemException(arg, "Unknown data value '" + typeAndData[1] + "'");
}
} else {
throw new InvalidItemException(arg, "Unknown data value '" + typeAndData[1] + "'");
}
}
}
// Check if the item is allowed
if (allAllowed || player.hasPermission("worldedit.anyblock") || !config.disallowedBlocks.contains(blockId)) {
if (blockType != null) {
if (!allAllowed && !player.hasPermission("worldedit.anyblock") && config.disallowedBlocks.contains(blockId)) {
throw new DisallowedItemException(arg);
}
if (blockType == null) {
return new BaseBlock(blockId, data);
}
switch (blockType) {
case SIGN_POST:
case WALL_SIGN:
@ -536,21 +558,23 @@ public class WorldEdit {
case NOTE_BLOCK:
// Allow setting note
if (blockAndExtraData.length > 1) {
byte note = Byte.parseByte(blockAndExtraData[1]);
if (note < 0 || note > 24) {
throw new InvalidItemException(arg, "Out of range note value: '" + blockAndExtraData[1] + "'");
} else {
return new NoteBlock(data, note);
}
} else {
if (blockAndExtraData.length <= 1) {
return new NoteBlock(data, (byte) 0);
}
byte note = Byte.parseByte(blockAndExtraData[1]);
if (note < 0 || note > 24) {
throw new InvalidItemException(arg, "Out of range note value: '" + blockAndExtraData[1] + "'");
}
return new NoteBlock(data, note);
case HEAD:
// allow setting type/player/rotation
if (blockAndExtraData.length > 1) {
// and thus, the format shall be "|type|rotation" or "|type" or "|rotation"
if (blockAndExtraData.length <= 1) {
return new SkullBlock(data);
}
byte rot = 0;
String type = "";
try {
@ -580,19 +604,10 @@ public class WorldEdit {
} else {
return new SkullBlock(data, skullType, rot);
}
} else {
return new SkullBlock(data);
}
default:
return new BaseBlock(blockId, data);
}
} else {
return new BaseBlock(blockId, data);
}
}
throw new DisallowedItemException(arg);
}
/**
@ -646,21 +661,18 @@ public class WorldEdit {
// Handle special block pattern types
if (patternString.charAt(0) == '#') {
if (patternString.equals("#clipboard") || patternString.equals("#copy")) {
if (!patternString.equals("#clipboard") && !patternString.equals("#copy")) {
throw new UnknownItemException(patternString);
}
LocalSession session = getSession(player);
CuboidClipboard clipboard;
try {
clipboard = session.getClipboard();
return new ClipboardPattern(session.getClipboard());
} catch (EmptyClipboardException e) {
player.printError("Copy a selection first with //copy.");
throw new UnknownItemException("#clipboard");
}
return new ClipboardPattern(clipboard);
} else {
throw new UnknownItemException(patternString);
}
}
// If it's only one block, then just return that single one
@ -902,25 +914,25 @@ public class WorldEdit {
public int getMaximumPolygonalPoints(LocalPlayer player) {
if (player.hasPermission("worldedit.limit.unrestricted") || config.maxPolygonalPoints < 0) {
return config.defaultMaxPolygonalPoints;
} else {
}
if (config.defaultMaxPolygonalPoints < 0) {
return config.maxPolygonalPoints;
}
return Math.min(config.defaultMaxPolygonalPoints,
config.maxPolygonalPoints);
}
return Math.min(config.defaultMaxPolygonalPoints, config.maxPolygonalPoints);
}
public int getMaximumPolyhedronPoints(LocalPlayer player) {
if (player.hasPermission("worldedit.limit.unrestricted") || config.maxPolyhedronPoints < 0) {
return config.defaultMaxPolyhedronPoints;
} else {
}
if (config.defaultMaxPolyhedronPoints < 0) {
return config.maxPolyhedronPoints;
}
return Math.min(config.defaultMaxPolyhedronPoints,
config.maxPolyhedronPoints);
}
return Math.min(config.defaultMaxPolyhedronPoints, config.maxPolyhedronPoints);
}
/**
@ -958,9 +970,9 @@ public class WorldEdit {
File f = new File(path);
if (f.isAbsolute()) {
return f;
} else {
return new File(config.getWorkingDirectory(), path);
}
return new File(config.getWorkingDirectory(), path);
}
/**