Java Code Examples for cn.nukkit.nbt.tag.CompoundTag#getCompound()

The following examples show how to use cn.nukkit.nbt.tag.CompoundTag#getCompound() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseLevelProvider.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public BaseLevelProvider(Level level, String path) throws IOException {
    this.level = level;
    this.path = path;
    File file_path = new File(this.path);
    if (!file_path.exists()) {
        file_path.mkdirs();
    }
    CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN);
    if (levelData.get("Data") instanceof CompoundTag) {
        this.levelData = levelData.getCompound("Data");
    } else {
        throw new LevelException("Invalid level.dat");
    }

    if (!this.levelData.contains("generatorName")) {
        this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase());
    }

    if (!this.levelData.contains("generatorOptions")) {
        this.levelData.putString("generatorOptions", "");
    }

}
 
Example 2
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public BaseLevelProvider(Level level, String path) throws IOException {
    this.level = level;
    this.path = path;
    File file_path = new File(this.path);
    if (!file_path.exists()) {
        file_path.mkdirs();
    }
    CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN);
    if (levelData.get("Data") instanceof CompoundTag) {
        this.levelData = levelData.getCompound("Data");
    } else {
        throw new LevelException("Invalid level.dat");
    }

    if (!this.levelData.contains("generatorName")) {
        this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase());
    }

    if (!this.levelData.contains("generatorOptions")) {
        this.levelData.putString("generatorOptions", "");
    }

    this.spawn = new Vector3(this.levelData.getInt("SpawnX"), this.levelData.getInt("SpawnY"), this.levelData.getInt("SpawnZ"));
}
 
Example 3
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public BaseLevelProvider(Level level, String path) throws IOException {
    this.level = level;
    this.path = path;
    File file_path = new File(this.path);
    if (!file_path.exists()) {
        file_path.mkdirs();
    }
    CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN);
    if (levelData.get("Data") instanceof CompoundTag) {
        this.levelData = levelData.getCompound("Data");
    } else {
        throw new LevelException("Invalid level.dat");
    }

    if (!this.levelData.contains("generatorName")) {
        this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase());
    }

    if (!this.levelData.contains("generatorOptions")) {
        this.levelData.putString("generatorOptions", "");
    }

    this.spawn = new Vector3(this.levelData.getInt("SpawnX"), this.levelData.getInt("SpawnY"), this.levelData.getInt("SpawnZ"));
}
 
Example 4
Source File: Chunk.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static Chunk fromBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN);

        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }
        return new Chunk(provider != null ? provider : McRegion.class.newInstance(), chunk.getCompound("Level"));
    } catch (Exception e) {
        return null;
    }
}
 
Example 5
Source File: Chunk.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static Chunk fromBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN);

        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }

        return new Chunk(provider, chunk.getCompound("Level"));
    } catch (Exception e) {
        Server.getInstance().getLogger().logException(e);
        return null;
    }
}
 
Example 6
Source File: Chunk.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new DataInputStream(new ByteArrayInputStream(data)), ByteOrder.BIG_ENDIAN);
        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }

        return new Chunk(provider, chunk.getCompound("Level"));
    } catch (Exception e) {
        return null;
    }
}
 
Example 7
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static Chunk fromBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN);

        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }
        return new Chunk(provider != null ? provider : McRegion.class.newInstance(), chunk.getCompound("Level"));
    } catch (Exception e) {
        return null;
    }
}
 
Example 8
Source File: Chunk.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static Chunk fromBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new ByteArrayInputStream(Zlib.inflate(data)), ByteOrder.BIG_ENDIAN);

        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }
        return new Chunk(provider != null ? provider : McRegion.class.newInstance(), chunk.getCompound("Level"));
    } catch (Exception e) {
        return null;
    }
}