Search in sources :

Example 1 with InvalidFormatException

use of com.sk89q.worldedit.world.storage.InvalidFormatException in project FastAsyncWorldEdit by IntellectualSites.

the class MobSpawnerBlock method setNbtData.

@Override
public void setNbtData(CompoundTag rootTag) {
    if (rootTag == null) {
        return;
    }
    Map<String, Tag> values = rootTag.getValue();
    Tag t = values.get("id");
    if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals(getNbtId())) {
        throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId()));
    }
    CompoundTag spawnDataTag;
    String mobType;
    ShortTag delayTag;
    try {
        spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class);
        mobType = spawnDataTag.getString("id");
        if (mobType.equals("")) {
            throw new InvalidFormatException("No spawn id.");
        }
        this.mobType = mobType;
        this.spawnData = spawnDataTag;
    } catch (InvalidFormatException ignored) {
        throw new RuntimeException("Invalid mob spawner data: no SpawnData and/or no Delay");
    }
    try {
        delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class);
        this.delay = delayTag.getValue();
    } catch (InvalidFormatException ignored) {
        this.delay = -1;
    }
    ShortTag spawnCountTag = null;
    ShortTag spawnRangeTag = null;
    ShortTag minSpawnDelayTag = null;
    ShortTag maxSpawnDelayTag = null;
    ShortTag maxNearbyEntitiesTag = null;
    ShortTag requiredPlayerRangeTag = null;
    ListTag spawnPotentialsTag = null;
    try {
        spawnCountTag = NBTUtils.getChildTag(values, "SpawnCount", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        spawnRangeTag = NBTUtils.getChildTag(values, "SpawnRange", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        minSpawnDelayTag = NBTUtils.getChildTag(values, "MinSpawnDelay", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        maxSpawnDelayTag = NBTUtils.getChildTag(values, "MaxSpawnDelay", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        maxNearbyEntitiesTag = NBTUtils.getChildTag(values, "MaxNearbyEntities", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        requiredPlayerRangeTag = NBTUtils.getChildTag(values, "RequiredPlayerRange", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        spawnPotentialsTag = NBTUtils.getChildTag(values, "SpawnPotentials", ListTag.class);
    } catch (InvalidFormatException ignored) {
    }
    if (spawnCountTag != null) {
        this.spawnCount = spawnCountTag.getValue();
    }
    if (spawnRangeTag != null) {
        this.spawnRange = spawnRangeTag.getValue();
    }
    if (minSpawnDelayTag != null) {
        this.minSpawnDelay = minSpawnDelayTag.getValue();
    }
    if (maxSpawnDelayTag != null) {
        this.maxSpawnDelay = maxSpawnDelayTag.getValue();
    }
    if (maxNearbyEntitiesTag != null) {
        this.maxNearbyEntities = maxNearbyEntitiesTag.getValue();
    }
    if (requiredPlayerRangeTag != null) {
        this.requiredPlayerRange = requiredPlayerRangeTag.getValue();
    }
    if (spawnPotentialsTag != null) {
        this.spawnPotentials = new ListTag(CompoundTag.class, spawnPotentialsTag.getValue());
    }
}
Also used : StringTag(com.sk89q.jnbt.StringTag) ListTag(com.sk89q.jnbt.ListTag) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) ListTag(com.sk89q.jnbt.ListTag) CompoundTag(com.sk89q.jnbt.CompoundTag) ShortTag(com.sk89q.jnbt.ShortTag)

Example 2 with InvalidFormatException

use of com.sk89q.worldedit.world.storage.InvalidFormatException in project FastAsyncWorldEdit by IntellectualSites.

the class NbtUtils method getInt.

/**
 * Get an integer from a tag.
 *
 * @param tag the tag to read from
 * @param key the key to look for
 * @return child tag
 * @throws InvalidFormatException if the format of the items is invalid
 * @since TODO
 */
public static int getInt(CompoundBinaryTag tag, String key) throws InvalidFormatException {
    BinaryTag childTag = tag.get(key);
    if (childTag == null) {
        throw new InvalidFormatException("Missing a \"" + key + "\" tag");
    }
    BinaryTagType<?> type = childTag.type();
    if (type == BinaryTagTypes.INT) {
        return ((IntBinaryTag) childTag).intValue();
    }
    if (type == BinaryTagTypes.BYTE) {
        return ((ByteBinaryTag) childTag).intValue();
    }
    if (type == BinaryTagTypes.SHORT) {
        return ((ShortBinaryTag) childTag).intValue();
    }
    throw new InvalidFormatException(key + " tag is not of int, short or byte tag type.");
}
Also used : ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException)

Example 3 with InvalidFormatException

use of com.sk89q.worldedit.world.storage.InvalidFormatException in project FastAsyncWorldEdit by IntellectualSites.

the class AnvilChunk13 method populateEntities.

/**
 * Used to load the biomes.
 */
private void populateEntities() throws DataException {
    entities = new ArrayList<>();
    if (rootTag.get("Entities") == null) {
        return;
    }
    ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "Entities", BinaryTagTypes.LIST);
    for (BinaryTag tag : tags) {
        if (!(tag instanceof CompoundBinaryTag)) {
            throw new InvalidFormatException("CompoundTag expected in Entities");
        }
        CompoundBinaryTag t = (CompoundBinaryTag) tag;
        entities.add(new BaseEntity(EntityTypes.get(t.getString("id")), LazyReference.computed(t)));
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Example 4 with InvalidFormatException

use of com.sk89q.worldedit.world.storage.InvalidFormatException in project FastAsyncWorldEdit by IntellectualSites.

the class OldChunk method populateTileEntities.

/**
 * Used to load the tile entities.
 *
 * @throws DataException if there is an error getting the chunk data
 */
private void populateTileEntities() throws DataException {
    ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "TileEntities", BinaryTagTypes.LIST);
    tileEntities = new HashMap<>();
    for (BinaryTag tag : tags) {
        if (!(tag instanceof CompoundBinaryTag)) {
            throw new InvalidFormatException("CompoundTag expected in TileEntities");
        }
        CompoundBinaryTag t = (CompoundBinaryTag) tag;
        int x = 0;
        int y = 0;
        int z = 0;
        CompoundBinaryTag.Builder values = CompoundBinaryTag.builder();
        for (String key : t.keySet()) {
            BinaryTag value = t.get(key);
            switch(key) {
                case "x":
                    if (value instanceof IntBinaryTag) {
                        x = ((IntBinaryTag) value).value();
                    }
                    break;
                case "y":
                    if (value instanceof IntBinaryTag) {
                        y = ((IntBinaryTag) value).value();
                    }
                    break;
                case "z":
                    if (value instanceof IntBinaryTag) {
                        z = ((IntBinaryTag) value).value();
                    }
                    break;
                default:
                    break;
            }
            values.put(key, value);
        }
        BlockVector3 vec = BlockVector3.at(x, y, z);
        tileEntities.put(vec, values.build());
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Example 5 with InvalidFormatException

use of com.sk89q.worldedit.world.storage.InvalidFormatException in project FastAsyncWorldEdit by IntellectualSites.

the class AnvilChunk method populateTileEntities.

/**
 * Used to load the tile entities.
 */
private void populateTileEntities() throws DataException {
    ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "TileEntities", BinaryTagTypes.LIST);
    tileEntities = new HashMap<>();
    for (BinaryTag tag : tags) {
        if (!(tag instanceof CompoundBinaryTag)) {
            throw new InvalidFormatException("CompoundTag expected in TileEntities");
        }
        CompoundBinaryTag t = (CompoundBinaryTag) tag;
        int x = 0;
        int y = 0;
        int z = 0;
        CompoundBinaryTag.Builder values = CompoundBinaryTag.builder();
        for (String key : t.keySet()) {
            BinaryTag value = t.get(key);
            switch(key) {
                case "x":
                    if (value instanceof IntBinaryTag) {
                        x = ((IntBinaryTag) value).value();
                    }
                    break;
                case "y":
                    if (value instanceof IntBinaryTag) {
                        y = ((IntBinaryTag) value).value();
                    }
                    break;
                case "z":
                    if (value instanceof IntBinaryTag) {
                        z = ((IntBinaryTag) value).value();
                    }
                    break;
                default:
                    break;
            }
            values.put(key, value);
        }
        BlockVector3 vec = BlockVector3.at(x, y, z);
        tileEntities.put(vec, values.build());
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Aggregations

InvalidFormatException (com.sk89q.worldedit.world.storage.InvalidFormatException)7 BinaryTag (com.sk89q.worldedit.util.nbt.BinaryTag)6 CompoundBinaryTag (com.sk89q.worldedit.util.nbt.CompoundBinaryTag)6 IntBinaryTag (com.sk89q.worldedit.util.nbt.IntBinaryTag)6 ListBinaryTag (com.sk89q.worldedit.util.nbt.ListBinaryTag)4 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 ByteBinaryTag (com.sk89q.worldedit.util.nbt.ByteBinaryTag)2 ShortBinaryTag (com.sk89q.worldedit.util.nbt.ShortBinaryTag)2 CompoundTag (com.sk89q.jnbt.CompoundTag)1 IntTag (com.sk89q.jnbt.IntTag)1 ListTag (com.sk89q.jnbt.ListTag)1 ShortTag (com.sk89q.jnbt.ShortTag)1 StringTag (com.sk89q.jnbt.StringTag)1 Tag (com.sk89q.jnbt.Tag)1 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)1