Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void restoreRegion(final Arena arena) {
- final Clipboard clipboard = savedClipboards.removeWeak(arena.getName());
- final Region region = arena.getSettings().getRegion();
- final org.bukkit.World world = region.getWorld();
- for (final Player player : world.getPlayers())
- player.kickPlayer("The game has ended you should not be here.");
- processedWorlds.add(world);
- if (clipboard == null)
- return;
- try (EditSession editSession = WorldEdit.getInstance().newEditSession(new BukkitWorld(region.getWorld())/*EditSession editSession = createSession(new BukkitWorld(region.getWorld()))*/)) {
- final List<BlockVector3> vectors = Common.convert(region.getBlocks(), ArenaMapManager::toVector);
- new ChunkedTask(100_000) {
- /**
- * For each block in region find block stored in the clipboard,
- * if it exists, restore it back
- */
- @Override
- protected void onProcess(final int index) {
- final BlockVector3 vector = vectors.get(index);
- final BaseBlock copy = clipboard.getFullBlock(vector);
- if (copy != null)
- try {
- editSession.setBlock(vector, copy);
- } catch (final MaxChangedBlocksException e) {
- e.printStackTrace();
- }
- }
- /**
- * Flush the operation to make the blocks visible on finish
- */
- @Override
- protected void onFinish() {
- editSession.flushSession();
- processedWorlds.remove(world);
- Common.log("Finished restoring the arena (" + arena.getName() + ")");
- }
- /**
- * Return if we can pull more blocks from our region or we are finished
- */
- @Override
- protected boolean canContinue(final int index) {
- return index < vectors.size();
- }
- /**
- * Also show percentage how many blocks we have restored to finish
- */
- @Override
- protected String getProcessMessage(final long initialTime, final int processed) {
- final long progress = Math.round(((double) getCurrentIndex() / (double) vectors.size()) * 100);
- return "[" + progress + "%] " + super.getProcessMessage(initialTime, processed);
- }
- }.startChain();
- }
- }
Add Comment
Please, Sign In to add comment