Loading and regen region

Discussion in 'Spigot Plugin Development' started by CodingPig, Jun 26, 2018.

  1. Hi i want to load the region and after finish the game i could regen it back
    The code works great but when it comes to the door and trapdoor stuff its got like this and sometimes its got an error when the door places the wrong location (theres nothing under it so it break)
    Code (Text):
    Caused by: java.lang.IllegalArgumentException: Provided data is not of type org.bukkit.material.MaterialData, found org.bukkit.material.TrapDoor

    Heres my code:
    Code (Text):

    public class BlockData {
        public Material mat;
        public MaterialData data;
        public BlockData(Material mat, MaterialData data){
            this.mat = mat;
            this.data = data;

    public HashMap<Location,BlockData> block;
    for (Block b : cuboid.getBlocks())
                block.put(b.getLocation(), new BlockData(b.getType(), b.getState().getData()));

    public void regen() {
            for (int x = cuboid.x1; x <= cuboid.x2; ++x) {
                for (int y = cuboid.y1; y <= cuboid.y2; ++y) {
                    for (int z = cuboid.z1; z <= cuboid.z2; ++z) {
                        Location loc = new Location(cuboid.getWorld(), x, y, z);
                        Block b = loc.getBlock();
                        if(b.getType() != block.get(loc).mat) {
  2. Why not just store the BlockState and then update that instead of storing a BlockData class. BlockStates retain their captured information and you only need to use BlockState#update() to "reset" the block back to its original captured state.
    • Like Like x 1
  3. but how can i set the block's blockstate?
  4. You don't.
    • Winner Winner x 1
  5. ohhh god im so dumb i get it now thanks <3
  6. Can't, heres my code

    Code (Text):
        public void regen() {
            for(BlockState b : block) b.update();
    for (Block b : cuboid.getBlocks()) {
                BlockState blockstate = b.getState();
  7. I fix the b.update() to b.update(true), its work but some door still break
  8. Would you consider using schematics? Then you would save yourself quite a bit of work, why reinvent the wheel? If you work on a larger scale I would suggest loading everything async (and maybe use FAWE to update the world.)