From d0367bfd5c6065fa4232f5775e437953fd113fd7 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Tue, 6 Dec 2011 07:58:34 -0800 Subject: [PATCH] Small cleanup of chunk reading --- .../java/com/sk89q/worldedit/data/Chunk.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/data/Chunk.java b/src/main/java/com/sk89q/worldedit/data/Chunk.java index d2f411a58..90ee93cfc 100644 --- a/src/main/java/com/sk89q/worldedit/data/Chunk.java +++ b/src/main/java/com/sk89q/worldedit/data/Chunk.java @@ -48,14 +48,14 @@ public class Chunk { public Chunk(CompoundTag tag) throws DataException { rootTag = tag; - blocks = ((ByteArrayTag) getChildTag( - rootTag.getValue(), "Blocks", ByteArrayTag.class)).getValue(); - data = ((ByteArrayTag) getChildTag( - rootTag.getValue(), "Data", ByteArrayTag.class)).getValue(); - rootX = ((IntTag) getChildTag( - rootTag.getValue(), "xPos", IntTag.class)).getValue(); - rootZ = ((IntTag) getChildTag( - rootTag.getValue(), "zPos", IntTag.class)).getValue(); + blocks = getChildTag( + rootTag.getValue(), "Blocks", ByteArrayTag.class).getValue(); + data = getChildTag( + rootTag.getValue(), "Data", ByteArrayTag.class).getValue(); + rootX = getChildTag( + rootTag.getValue(), "xPos", IntTag.class).getValue(); + rootZ = getChildTag( + rootTag.getValue(), "zPos", IntTag.class).getValue(); if (blocks.length != 32768) { throw new InvalidFormatException("Chunk blocks byte array expected " @@ -120,8 +120,8 @@ public class Chunk { * @throws DataException */ private void populateTileEntities() throws DataException { - List tags = (List) ((ListTag) getChildTag( - rootTag.getValue(), "TileEntities", ListTag.class)) + List tags = getChildTag( + rootTag.getValue(), "TileEntities", ListTag.class) .getValue(); tileEntities = new HashMap>(); @@ -224,9 +224,8 @@ public class Chunk { * @return child tag * @throws InvalidFormatException */ - public static Tag getChildTag(Map items, String key, - Class expected) - throws InvalidFormatException { + public static T getChildTag(Map items, String key, + Class expected) throws InvalidFormatException { if (!items.containsKey(key)) { throw new InvalidFormatException("Missing a \"" + key + "\" tag"); } @@ -234,6 +233,6 @@ public class Chunk { if (!expected.isInstance(tag)) { throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName()); } - return tag; + return (T) tag; } }