Improved handling of valid blocks not in BlockType and added dragon egg to BlockType

Dieser Commit ist enthalten in:
zml2008 2011-11-27 15:29:26 -08:00
Ursprung 5d59dd764e
Commit 51dd7a0c9c
4 geänderte Dateien mit 89 neuen und 78 gelöschten Zeilen

Datei anzeigen

@ -321,53 +321,57 @@ public class WorldEdit {
data = 0; data = 0;
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
switch (blockType) { if (blockType != null) {
case CLOTH: switch (blockType) {
ClothColor col = ClothColor.lookup(typeAndData[1]); case CLOTH:
ClothColor col = ClothColor.lookup(typeAndData[1]);
if (col != null) { if (col != null) {
data = col.getID(); data = col.getID();
} else { } else {
throw new InvalidItemException(arg, "Unknown cloth color '" + typeAndData[1] + "'"); throw new InvalidItemException(arg, "Unknown cloth color '" + typeAndData[1] + "'");
} }
break;
case STEP:
case DOUBLE_STEP:
BlockType dataType = BlockType.lookup(typeAndData[1]);
if (dataType != null) {
switch (dataType) {
case STONE:
data = 0;
break; break;
case SANDSTONE: case STEP:
data = 1; case DOUBLE_STEP:
break; BlockType dataType = BlockType.lookup(typeAndData[1]);
case WOOD: if (dataType != null) {
data = 2; switch (dataType) {
break; case STONE:
data = 0;
break;
case COBBLESTONE: case SANDSTONE:
data = 3; data = 1;
break;
case WOOD:
data = 2;
break;
case COBBLESTONE:
data = 3;
break;
case BRICK:
data = 4;
break;
case STONE_BRICK:
data = 5;
default:
throw new InvalidItemException(arg, "Invalid step type '" + typeAndData[1] + "'");
}
} else {
throw new InvalidItemException(arg, "Unknown step type '" + typeAndData[1] + "'");
}
break; break;
case BRICK:
data = 4;
break;
case STONE_BRICK:
data = 5;
default: default:
throw new InvalidItemException(arg, "Invalid step type '" + typeAndData[1] + "'"); throw new InvalidItemException(arg, "Unknown data value '" + typeAndData[1] + "'");
}
} else {
throw new InvalidItemException(arg, "Unknown step type '" + typeAndData[1] + "'");
} }
break; } else {
default:
throw new InvalidItemException(arg, "Unknown data value '" + typeAndData[1] + "'"); throw new InvalidItemException(arg, "Unknown data value '" + typeAndData[1] + "'");
} }
} }
@ -375,49 +379,53 @@ public class WorldEdit {
// Check if the item is allowed // Check if the item is allowed
if (allAllowed || player.hasPermission("worldedit.anyblock") || !config.disallowedBlocks.contains(blockId)) { if (allAllowed || player.hasPermission("worldedit.anyblock") || !config.disallowedBlocks.contains(blockId)) {
switch (blockType) { if (blockType != null) {
case SIGN_POST: switch (blockType) {
case WALL_SIGN: case SIGN_POST:
// Allow special sign text syntax case WALL_SIGN:
String[] text = new String[4]; // Allow special sign text syntax
text[0] = blockAndExtraData.length > 1 ? blockAndExtraData[1] : ""; String[] text = new String[4];
text[1] = blockAndExtraData.length > 2 ? blockAndExtraData[2] : ""; text[0] = blockAndExtraData.length > 1 ? blockAndExtraData[1] : "";
text[2] = blockAndExtraData.length > 3 ? blockAndExtraData[3] : ""; text[1] = blockAndExtraData.length > 2 ? blockAndExtraData[2] : "";
text[3] = blockAndExtraData.length > 4 ? blockAndExtraData[4] : ""; text[2] = blockAndExtraData.length > 3 ? blockAndExtraData[3] : "";
return new SignBlock(blockType.getID(), data, text); text[3] = blockAndExtraData.length > 4 ? blockAndExtraData[4] : "";
return new SignBlock(blockType.getID(), data, text);
case MOB_SPAWNER: case MOB_SPAWNER:
// Allow setting mob spawn type // Allow setting mob spawn type
if (blockAndExtraData.length > 1) { if (blockAndExtraData.length > 1) {
String mobName = blockAndExtraData[1]; String mobName = blockAndExtraData[1];
for (MobType mobType : MobType.values()) { for (MobType mobType : MobType.values()) {
if (mobType.getName().toLowerCase().equals(mobName.toLowerCase())) { if (mobType.getName().toLowerCase().equals(mobName.toLowerCase())) {
mobName = mobType.getName(); mobName = mobType.getName();
break; break;
}
}
if (!server.isValidMobType(mobName)) {
throw new InvalidItemException(arg, "Unknown mob type '" + mobName + "'");
}
return new MobSpawnerBlock(data, mobName);
} else {
return new MobSpawnerBlock(data, MobType.PIG.getName());
} }
}
if (!server.isValidMobType(mobName)) {
throw new InvalidItemException(arg, "Unknown mob type '" + mobName + "'");
}
return new MobSpawnerBlock(data, mobName);
} else {
return new MobSpawnerBlock(data, MobType.PIG.getName());
}
case NOTE_BLOCK: case NOTE_BLOCK:
// Allow setting note // Allow setting note
if (blockAndExtraData.length > 1) { if (blockAndExtraData.length > 1) {
byte note = Byte.parseByte(blockAndExtraData[1]); byte note = Byte.parseByte(blockAndExtraData[1]);
if (note < 0 || note > 24) { if (note < 0 || note > 24) {
throw new InvalidItemException(arg, "Out of range note value: '" + blockAndExtraData[1] + "'"); throw new InvalidItemException(arg, "Out of range note value: '" + blockAndExtraData[1] + "'");
} else { } else {
return new NoteBlock(data, note); return new NoteBlock(data, note);
} }
} else { } else {
return new NoteBlock(data, (byte) 0); return new NoteBlock(data, (byte) 0);
} }
default: default:
return new BaseBlock(blockId, data);
}
} else {
return new BaseBlock(blockId, data); return new BaseBlock(blockId, data);
} }
} }

Datei anzeigen

@ -148,4 +148,5 @@ public final class BlockID {
public static final int END_PORTAL = 119; public static final int END_PORTAL = 119;
public static final int END_PORTAL_FRAME = 120; public static final int END_PORTAL_FRAME = 120;
public static final int END_STONE = 121; public static final int END_STONE = 121;
public static final int DRAGON_EGG = 122;
} }

Datei anzeigen

@ -157,7 +157,8 @@ public enum BlockType {
CAULDRON(BlockID.CAULDRON, "Cauldron"), CAULDRON(BlockID.CAULDRON, "Cauldron"),
END_PORTAL(BlockID.END_PORTAL, "End Portal", "endportal", "blackstuff", "airportal", "weirdblackstuff"), END_PORTAL(BlockID.END_PORTAL, "End Portal", "endportal", "blackstuff", "airportal", "weirdblackstuff"),
END_PORTAL_FRAME(BlockID.END_PORTAL_FRAME, "End Portal Frame", "endportalframe", "airportalframe", "crystalblock"), END_PORTAL_FRAME(BlockID.END_PORTAL_FRAME, "End Portal Frame", "endportalframe", "airportalframe", "crystalblock"),
END_STONE(BlockID.END_STONE, "End Stone", "endstone", "enderstone", "endersand"); END_STONE(BlockID.END_STONE, "End Stone", "endstone", "enderstone", "endersand"),
DRAGON_EGG(BlockID.DRAGON_EGG, "Dragon Egg", "dragonegg", "dragons");
/** /**
* Stores a map of the IDs for fast access. * Stores a map of the IDs for fast access.

Datei anzeigen

@ -158,6 +158,7 @@ public enum ItemType {
END_PORTAL(BlockID.END_PORTAL, "End Portal", "endportal", "blackstuff", "airportal", "weirdblackstuff"), END_PORTAL(BlockID.END_PORTAL, "End Portal", "endportal", "blackstuff", "airportal", "weirdblackstuff"),
END_PORTAL_FRAME(BlockID.END_PORTAL_FRAME, "End Portal Frame", "endportalframe", "airportalframe", "crystalblock"), END_PORTAL_FRAME(BlockID.END_PORTAL_FRAME, "End Portal Frame", "endportalframe", "airportalframe", "crystalblock"),
END_STONE(BlockID.END_STONE, "End Stone", "endstone", "enderstone", "endersand"), END_STONE(BlockID.END_STONE, "End Stone", "endstone", "enderstone", "endersand"),
DRAGON_EGG(BlockID.DRAGON_EGG, "Dragon Egg", "dragonegg", "dragons"),
// Items // Items
IRON_SHOVEL(ItemID.IRON_SHOVEL, "Iron shovel", "ironshovel"), IRON_SHOVEL(ItemID.IRON_SHOVEL, "Iron shovel", "ironshovel"),