Keep blocks on map but remove them on restart

Discussion in 'Plugin Development' started by Quackster, Jul 24, 2014.

Thread Status:
Not open for further replies.
  1. Offline



    So I'm working on a plugin which will spawn helicopter crash sites, like DayZ does here

    And I'm using code to paste the blocks in as a schematic without using any API (so I have full control where blocks go and where they're placed).

    So I'd like to be able to spawn a crashed helicopter using a schematic and when the server restarts, where the helicopter crash site was will be fully gone and you'd never know it was ever there.

    I'm assuming I'd have to save existing block data where I paste over the new block and reload it when the server starts back up again but is this the best way to approach it?

    public void pasteSchematic(Location loc) {
    try {
    byte[] blocks = this.blocks;
    byte[] blockData =;
    short length = this.length;
    short width = this.width;
    short height = this.height;
    for (int x = 0; x < width; ++x) {
    for (int y = 0; y < height; y++) {
    for (int z = 0; z < length; ++z) {
    int index = y * width * length + z * width + x;
    Block block = new Location(loc.getWorld(), x + loc.getX(), loc.getY() + y, z + loc.getZ()).getBlock();
    block.setTypeId(blocks[index] < 0 ? Material.AIR.getId() : blocks[index]);
    block.setData(blockData[index], true);
    } catch (Exception e) {
    // TODO Auto-generated catch block
  2. Offline


    I guess you would have to loop and get all of the blocks before the helicopter spawns, then save them in a map or whatever. When onDisable fires, you would loop through the blocks and fill the area again.
  3. Offline


    Yeah that would be the best way. I guess I should save the block states and reset them when server closes.
    jimbo8 likes this.
Thread Status:
Not open for further replies.

Share This Page