Advertisement
HaniiPuppy

run over all genned chunks

Jan 10th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. // To do: Break up and insert breaks so it freezes the server in smaller intervals.
  2.     public void RegisterAllUnregisteredChests(double value, int tier)
  3.     {
  4.         // Bukkit, y u no give me World.getGeneratedChunks(); ?
  5.  
  6.         World world = Misc.getWorldOverworld(); // Misc.getOverworld is from my library.
  7.         File regionDirectory = getRegionsLocation(world);
  8.  
  9.         if (regionDirectory == null)
  10.         {
  11.             SM.getPlugin().getLogger().severe("Unable to locate the region files for: " + world.getName());
  12.             return;
  13.         }
  14.  
  15.         File[] files = regionDirectory.listFiles(new FilenameFilter()
  16.         {
  17.             @Override
  18.             public boolean accept(File dir, String name)
  19.             { return name.toLowerCase().endsWith(".mca"); }
  20.         });
  21.  
  22.         Pattern coordinatePattern = Pattern.compile("r\\.(.+)\\.(.+)\\.mca");
  23.  
  24.         for(File file : files)
  25.         {
  26.             Matcher matcher = coordinatePattern.matcher(file.getName());
  27.  
  28.             int regionX = 0;
  29.             int regionZ = 0;
  30.  
  31.             if (matcher.find())
  32.             {
  33.                 regionX = Integer.parseInt(matcher.group(1));
  34.                 regionZ = Integer.parseInt(matcher.group(2));
  35.             }
  36.             else
  37.             {
  38.                 SM.getPlugin().getLogger().severe("Unable to handle region: " + file.getName()); // SM is a class I make for containing static references to things like the plugin.
  39.                 continue;
  40.             }
  41.  
  42.             regionX = regionX << 5;
  43.             regionZ = regionZ << 5;
  44.  
  45.             RegionFile region = new RegionFile(file);
  46.  
  47.             for(int chunkX = 0; chunkX < 32; chunkX++)
  48.             {
  49.                 for(int chunkZ = 0; chunkZ < 32; chunkZ++)
  50.                 {
  51.                     SM.print("Checking for existence of chunk: " + regionX + chunkX + ", " + regionZ + chunkZ);
  52.                     if(region.chunkExists(chunkX, chunkZ))
  53.                     {
  54.                         Chunk chunk = world.getChunkAt(regionX + chunkX, regionZ + chunkZ);
  55.  
  56.                         SM.print("Chunk exists: " + regionX + chunkX + ", " + regionZ + chunkZ);
  57.                         for(BlockState block : chunk.getTileEntities())
  58.                         {
  59.                             SM.print("Checking if " + block.getX() + ", " + block.getY() + ", " + block.getZ() + " is a chest.");
  60.                             if(block instanceof Chest)
  61.                             {
  62.                                 SM.print("Chest at " + block.getX() + ", " + block.getY() + ", " + block.getZ() + " is a chest, attmpting to register.");
  63.                                 CoOrdinate coord = new CoOrdinate(block.getLocation());
  64.  
  65.                                 if(!this.containsKey(coord))
  66.                                     this.addWithoutSorting(new ChestPosition(coord, tier, value));
  67.                             }
  68.                         }
  69.  
  70.                         chunk.unload(false, false);
  71.                     }
  72.                 }
  73.             }
  74.         }
  75.  
  76.         this.sort();
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement