How to reset arena sate after every game?

Discussion in 'Plugin Development' started by andrik_golova, Jul 4, 2014.

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

    andrik_golova

    Hello, everybody!

    I'm developing a minigame plugin - Castle Siege. Players will be able to place/destroy the blocks, so I need to prepare arena for each game. I think, the best way is to save a "snapshot" of the region and load it after every game. How can I save a state of arena region and restore it? Is there anything like this in WorldGuard API?

    Thanks,
     
  2. Offline

    THEREDBARON24

    I believe that you can use schematics and whatnot as well, however, I would use an arraylist. get your event, and then get the block. store the block in the list, and then on completion, loop through the list and set type and material data to match that of the block. (Just a thought, probably the easiest solution that I could think of)
     
  3. Offline

    TheHandfish

    ^ Eh... that's a more complicated process than necessary.

    I'm thinking you could just use stock Java functions to copy a source World folder over the modified one, thus resetting it. If not, Commons IO by Apache might help.
     
  4. Offline

    xTigerRebornx

    TheHandfish It'd depend on what an 'Arena' is in order to be able to do that. If the 'arena' is its independent world, then that'd work, but if it was just a region of a world, it wouldn't.
    andrik_golova You could use WorldEdit's schematic features to save/load the Arena, or create your own way of doing this.
     
  5. THEREDBARON24 I would rather loop through all of the blocks and save the Material type and the location into a HashMap, and when he needs to reset it he will just loop through the map and set the type of every block. (I would recommend skipping air blocks, as it will shorten the process and will use less system resources.)
    Code:java
    1. HashMap<Material, Location> map = new HashMap<Material, Location>();
    2.  
    3. public void loopThrough(Location startLoc, Location endLoc, World w) {
    4.  
    5. int minx = Math.min(startLoc.getBlockX(), endLoc.getBlockX()),
    6. miny = Math.min(startLoc.getBlockY(), endLoc.getBlockY()),
    7. minz = Math.min(startLoc.getBlockZ(), endLoc.getBlockZ()),
    8. maxx = Math.max(startLoc.getBlockX(), endLoc.getBlockX()),
    9. maxy = Math.max(startLoc.getBlockY(), endLoc.getBlockY()),
    10. maxz = Math.max(startLoc.getBlockZ(), endLoc.getBlockZ());
    11. for(int x = minx; x<=maxx;x++){
    12. for(int y = miny; y<=maxy;y++){
    13. for(int z = minz; z<=maxz;z++){
    14. Block b = w.getBlockAt(x, y, z);
    15. map.put(b.getType(), b.getLocation());
    16. }
    17. }
    18. }
    19. }
     
  6. Offline

    xTigerRebornx

    TheBigSuperCraft Map is backwards (Should be Location, Material), and would break with anything that stores more then just Material (data value, chest contents, Directional, crops). User could use BlockState.
     
  7. Offline

    TheHandfish

    xTigerRebornx: Still, though, unless he plans to make this supportive of a server that has multiple worlds, not multiple servers, the idea would work. Not to mention you don't need to do any of that nasty looping through blocks.
     
  8. Offline

    pookeythekid

    TheBigSuperCraft I'd say skipping air blocks would allow players to place something in mid-air, then have the blocks stay there as the plugin restores the blocks that were broken off of the original map (not air blocks), instead of the blocks that were placed on top of the original map (originally air blocks).

    THEREDBARON24 I think your idea is half valid, considering (from the impression I'm getting) you've stored the block, and not the location of the block as well. Thus combining your idea and ThebigSuperCraft's idea would probably work: storing the broken and placed block IDs right before they're broken by using event listeners, then when the match is over restoring those broken/placed blocks.

    However, xTigerRebornx I'd say that the developers of WorldEdit have it all neatly laid out, to make it much easier than all this for the plugin developer using the API to use. So I'm going to nominate Tiger's solution: letting the pros do the work.

    I've actually learned a bit from this thread (I had no idea "BlockState" existed), thanks for the interesting conversation. Also apologies if most of this makes absolutely no sense; it's really late, and I am really tired.
     
  9. Offline

    dsouzamatt

    andrik_golova You can do this by hooking into Worldedit and creating a schematic of the area that you wish to restore. This thread explains everything.
     
  10. Offline

    THEREDBARON24

    Be aware that this will result in the loss of contents in items such as the chest and the removal of sign text. Still, this can be worked around.
     
  11. Offline

    Wizehh

    I apologize if this has already been suggested, but why not just turn world saving off? A bit "hacky" of a solution, but I don't see why it wouldn't work.
     
Thread Status:
Not open for further replies.

Share This Page