Advertisement
JackOUT

Untitled

Jan 15th, 2022
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1.     @SneakyThrows
  2.     public void restoreWorld(final Arena arena) {
  3.         checkApplicable(arena);
  4.  
  5.         final Region region = arena.getSettings().getRegion();
  6.         final World world = region.getWorld();
  7.  
  8.         for (final Player player : world.getPlayers())
  9.             player.kickPlayer("World is getting restored.");
  10.  
  11.         processedWorlds.add(world);
  12.  
  13.         final List<Block> blocks = region.getBlocks();
  14.  
  15.         new ChunkedTask(100_000) {
  16.  
  17.             final Set<Chunk> chunks = new HashSet<>();
  18.  
  19.             @Override
  20.             protected void onProcess(final int index) {
  21.                 final Block block = blocks.get(index);
  22.  
  23.                 chunks.add(block.getChunk());
  24.             }
  25.  
  26.             @Override
  27.             protected boolean canContinue(final int index) {
  28.                 return index < blocks.size();
  29.             }
  30.  
  31.             @Override
  32.             protected String getLabel() {
  33.                 return "blocks";
  34.             }
  35.  
  36.             @Override
  37.             protected void onFinish() {
  38.                 Common.log("Arena " + arena.getName() + " finished converting blocks to chunks.");
  39.  
  40.                 System.out.println("Auto save: " + world.isAutoSave());
  41.  
  42.                 new ChunkedTask(50) {
  43.  
  44.                     final List<Chunk> chunksCopy = new ArrayList<>(chunks);
  45.  
  46.                     @Override
  47.                     protected void onProcess(final int index) {
  48.                         final Chunk chunk = chunksCopy.get(index);
  49.  
  50.                         System.out.println("Auto save: " + world.isAutoSave());
  51.  
  52.                         chunk.unload(false);
  53.                         chunk.load(false);
  54.                     }
  55.  
  56.                     @Override
  57.                     protected boolean canContinue(final int index) {
  58.                         return index < chunksCopy.size();
  59.                     }
  60.  
  61.                     @Override
  62.                     protected String getLabel() {
  63.                         return "chunks";
  64.                     }
  65.  
  66.                     @Override
  67.                     protected void onFinish() {
  68.                         Common.log("Arena " + arena.getName() + " finished resetting world " + world.getName() + ".");
  69.  
  70.                         processedWorlds.remove(world);
  71.  
  72.                         System.out.println("Auto save: " + world.isAutoSave());
  73.                     }
  74.                 }.startChain();
  75.             }
  76.         }.startChain();
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement