Solved Restore from cubiod

Discussion in 'Plugin Development' started by shades161, Jul 27, 2015.

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

    shades161

    I am making a minigame plugin since I am still newish to java and bukkit, I thought it would test my skills.

    Anyway I have most things working, my issue here is that I want to regenerate (or restore) the arena after the game because it could get destroyed. When setting up the arena I set 2 points and they are saved to a file, using the cuboid class from this tutorial (https://bukkit.org/threads/protection-region-cuboid-creation.164161/) I create a cuboid.

    So here is my issue (and I am sorry that I was stupid enough to do this).
    Before the game started, I would save the original state (cuboid) of the arena in a HashMap (set up where the arena Id was the key) after the game ended (or was forced to end) it would call the arenaRegen method I made.

    What this did was, made a new cuboid of the arena's current state and would loop through all the blocks in that cuboid, if the block in the current cuboid did not match the type in the original cuboid, it would set it to that original block type.
    My issue came in when I realized that I could not cast a block to an arraylist (stupid I know, but I originally thought that would work).

    So, here is my arena regen method:
    Code:
        public void RegenArena(String Id) { //Regenerates the Arena.
            FileConfiguration cache = ArenaFiles.getArenaCacheYml(Id);
            File cacheFile = ArenaFiles.getArenaCacheFile(Id);
            cache.set("Status", "Regenerating Arena");
            plugin.saveCustomConfig(cache, cacheFile);
            Cuboid original = Main.plugin.arenaRegens.get(Id);
            Cuboid current = ArenaDataGetters.getArenaRegenArea(Id);
            Block originalBlock = (Block) original.getBlocks();
            for (Block currentBlock : current.getBlocks()) {
                if (!(currentBlock.getType() == originalBlock.getType())) {
                    currentBlock.setType(originalBlock.getType());
                }
            }
            cache.set("Status", "Empty");
            plugin.saveCustomConfig(cache, cacheFile);
        }
    I never got to testing if it would actually set the block to the right type, because of the cast.
    So, what I am asking here, is does anyone know how to properly regen/restore an area to before the arena was destroyed or possibly can link me to a tutorial for that?

    I am also aware (or so I have been told/seen a lot) that this would leave chests empty and signs blank, which I am fine with since I don't actually need that. However, it would be a nice plus if the way you suggest can do that, but it isn't necessary.

    Sidenote: I have been searching for answers on this for awhile, and looking at various API's that are built for minigames, but I haven't found anything that actually had a regen, or could support 1.8. I as well know that bukkit has a built in method to rollback and restore chunks, but that would remove anything a player has done, effectively deleting the arena.
    Also, if from there you find a major mistake with something else, please tell me, as this is my first time making a minigame plugin.
     
  2. Offline

    Ruptur

    @shades161
    What do you find wrong with what you are currently doing?
    Storing blocks to a map then putting them back to thier default state afterwards is what i wont do
     
  3. Offline

    shades161

    @Ruptur Nevermind. I fixed it, the issue seemed to be a syntax error when creating/saving the cuboid corners to a file and the issue with the block casting.
     
Thread Status:
Not open for further replies.

Share This Page