This is my first tutorial, so bear with me. Have you ever wanted to restore whole areas of blocks? Weather it be from griefers, to minigame arena, it is easier than you think! In this (very basic) I will show you how to do that! First off, your going to have to create a list of BlockState's and store it for later (you can even save it to a config file, but I'll leave that out for now). We do that with this simple code: Code:java public List<BlockState> blocklist = new ArrayList<BlockState>(); This will create a new variable called "blocklist" and will be able to store blocks, and their location. Now we need to populate the list. To do that, we need to add a BlockState whenever a block is broken (it can really be whenever you want, as long as you can get a BlockState). Code:java @EventHandlerpublic void onBlockBreak(BlockBreakEvent event){blocklist.add(event.getBlock().getState());} This will add the BlockState to our list whenever a block is broken. If we were doing this in a minigame, we would first check if the player who broke the block is in the minigame. Now to get to the meat and potatoes of our lesson, we will restore the blocks. It is really up to you on when you want to restore the blocks, just as long as you can some way access our blocklist variable. This loop will iterate through each one of our BlockStates in our variable, get the location, and set the location to our block. Code:java for (BlockState block: blocklist){block.update(true);}blocklist.clear(); This code will update the blocks to the BlockState. The "true" paramater forces the block to update, no matter what. NOTE: This code doesn't restore MetaData (ie. Sign text, Wool colors, Chest contents) Found a way that restores everything, thanks to a certain Troll I know.... If we want to store this data in a configuration file, we would simply save the blocklist to the config and when we need it, restore the blocks and clear the config and list (there is no use in storing the data anymore, it was already restored). If you have any problems with the code, feel free to Thag me for help
mattrick If you plan on serializing BlockStates, you may need to store the fields of CraftBlockState as BlockState is A) an interface and B) not ConfigurationSerializable
TryB4 Oh, didn't see that...like xTrollxDudex said, you should just use update, not reset the data and block. I think my code is easier to understand than yours though. HariHD No, when you set the block to air, add the block you set to air to the blocklist.
mattrick Code:java @EventHandler public void onPlayerMove2(PlayerMoveEvent e) { final Block block = e.getTo().getBlock().getLocation().add(new Vector(0,-1,0)).getBlock(); if(changeblock == true) { if (block.getType().equals(Material.GRAVEL)) { this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { blocklist.add(block.getState()); block.setType(Material.AIR); } },10L); } } } mattrick ?? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
mattrick What you said about. Code:java for (BlockState block: blocklist) { block.update(true);}blocklist.clear();
mattrick Send me your code? I can compare because my code is a minigame and there is a lot of classes and code.
HariHD I don't have access to it right now. You can try the link TryB4 posted above to his tutorial if you want.
Plugers11 It's actually not the same. I tried it my self when restoring when someone builds. It doesn't,