Restoring Blocks?

Discussion in 'Plugin Development' started by belven000, Jul 23, 2014.

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

    belven000

    Ok so I have this which is a collection of blocks between 2 points, using world edit:

    Code:java
    1.  
    2. public List<Block> arenaArea = new ArrayList<Block>();
    3.  


    This works fine and save all the blocks.
    I currently don't understand much about Blocks so here's how I think it can be done:
    • Are these stored blocks static i.e. won't change as the block changes if so can i just do getWorld().getBlock(block.getLoction()) to then set it, i.e. loop through arenaArea and set current block to = the original block
    • if not then would I have to store the location and block type and update later i.e. HashMap<Location, BlockState>
    • Otherwise how can this be done?
    Any help would be great thanks, I'm sure this is easier than I think.
     
  2. Offline

    xmarinusx

    belven000
    If the block changes, the block object changes as well. Storing the location in combination with the BlockState in a HashMap looks like the best option to me.
     
  3. Offline

    belven000

    xmarinusx So I've got this:

    Code:java
    1. public class SavedBlock
    2. {
    3. public BlockState bs;
    4. public Location l;
    5.  
    6. public SavedBlock(Block b)
    7. {
    8. l = b.getLocation();
    9. bs = b.getState();
    10. }
    11. }

    And i'm trying something like this but I don't think it will work 100%

    Code:java
    1. for (SavedBlock sb : originalBlocks)
    2. {
    3. Block b = sb.l.getBlock();
    4. b.setType(sb.bs.getType());
    5. }

    As setType isn't really the whole block so I need something better.
     
  4. Offline

    xmarinusx

  5. Offline

    belven000

    xmarinusx Thanks I've now got this:

    Code:java
    1. for (SavedBlock sb : originalBlocks)
    2. {
    3. sb.bs.update(true);
    4. }


    see was easier than I thought :D
     
  6. Offline

    xmarinusx

    belven000
    I'm glad you've fixed it:). Please put your thread on solved if it is.
     
Thread Status:
Not open for further replies.

Share This Page