Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // To do: Break up and insert breaks so it freezes the server in smaller intervals.
- public void RegisterAllUnregisteredChests(double value, int tier)
- {
- // Bukkit, y u no give me World.getGeneratedChunks(); ?
- World world = Misc.getWorldOverworld(); // Misc.getOverworld is from my library.
- File regionDirectory = getRegionsLocation(world);
- if (regionDirectory == null)
- {
- SM.getPlugin().getLogger().severe("Unable to locate the region files for: " + world.getName());
- return;
- }
- File[] files = regionDirectory.listFiles(new FilenameFilter()
- {
- @Override
- public boolean accept(File dir, String name)
- { return name.toLowerCase().endsWith(".mca"); }
- });
- Pattern coordinatePattern = Pattern.compile("r\\.(.+)\\.(.+)\\.mca");
- for(File file : files)
- {
- Matcher matcher = coordinatePattern.matcher(file.getName());
- int regionX = 0;
- int regionZ = 0;
- if (matcher.find())
- {
- regionX = Integer.parseInt(matcher.group(1));
- regionZ = Integer.parseInt(matcher.group(2));
- }
- else
- {
- 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.
- continue;
- }
- regionX = regionX << 5;
- regionZ = regionZ << 5;
- RegionFile region = new RegionFile(file);
- for(int chunkX = 0; chunkX < 32; chunkX++)
- {
- for(int chunkZ = 0; chunkZ < 32; chunkZ++)
- {
- SM.print("Checking for existence of chunk: " + regionX + chunkX + ", " + regionZ + chunkZ);
- if(region.chunkExists(chunkX, chunkZ))
- {
- Chunk chunk = world.getChunkAt(regionX + chunkX, regionZ + chunkZ);
- SM.print("Chunk exists: " + regionX + chunkX + ", " + regionZ + chunkZ);
- for(BlockState block : chunk.getTileEntities())
- {
- SM.print("Checking if " + block.getX() + ", " + block.getY() + ", " + block.getZ() + " is a chest.");
- if(block instanceof Chest)
- {
- SM.print("Chest at " + block.getX() + ", " + block.getY() + ", " + block.getZ() + " is a chest, attmpting to register.");
- CoOrdinate coord = new CoOrdinate(block.getLocation());
- if(!this.containsKey(coord))
- this.addWithoutSorting(new ChestPosition(coord, tier, value));
- }
- }
- chunk.unload(false, false);
- }
- }
- }
- }
- this.sort();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement