HaniiPuppy

RegisterAllUnregisteredChests

Dec 30th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. public void RegisterAllUnregisteredChests(double value, int tier)
  2.     {
  3.         // Bukkit, y u no give me World.getGeneratedChunks(); ?
  4.  
  5.         World world = Misc.getWorldOverworld(); // Misc.getOverworld is from my library.
  6.         File regionDirectory = getRegionsLocation(world);
  7.  
  8.         if (regionDirectory == null)
  9.         {
  10.             SM.getPlugin().getLogger().severe("Unable to locate the region files for: " + world.getName());
  11.             return;
  12.         }
  13.  
  14.         File[] files = regionDirectory.listFiles(new FilenameFilter()
  15.         {
  16.             @Override
  17.             public boolean accept(File dir, String name)
  18.             { return name.toLowerCase().endsWith(".mca"); }
  19.         });
  20.  
  21.         Pattern coordinatePattern = Pattern.compile("r\\.(.+)\\.(.+)\\.mca");
  22.  
  23.         for(File file : files)
  24.         {
  25.             Matcher matcher = coordinatePattern.matcher(file.getName());
  26.  
  27.             int regionX = 0;
  28.             int regionZ = 0;
  29.  
  30.             if (matcher.find())
  31.             {
  32.                 regionX = Integer.parseInt(matcher.group(1));
  33.                 regionZ = Integer.parseInt(matcher.group(2));
  34.             }
  35.             else
  36.             {
  37.                 SM.getPlugin().getLogger().severe("Unable to handle region: " + file.getName()); // SM is a class containing static references to things like the plugin.
  38.                 continue;
  39.             }
  40.  
  41.             regionX = regionX << 5;
  42.             regionZ = regionZ << 5;
  43.  
  44.             RegionFile region = new RegionFile(file);
  45.  
  46.             for(int chunkX = 0; chunkX < 32; chunkX++)
  47.             {
  48.                 for(int chunkZ = 0; chunkZ < 32; chunkZ++)
  49.                 {
  50.                     if(region.chunkExists(regionX + chunkX, regionZ + chunkZ))
  51.                     {
  52.                         for(BlockState block : world.getChunkAt(regionX + chunkX, regionZ + chunkZ).getTileEntities())
  53.                         {
  54.                             CoOrdinate coord = new CoOrdinate(block.getLocation());
  55.  
  56.                             if(!this.containsKey(coord))
  57.                                 this.addWithoutSorting(new ChestPosition(coord, tier, value));
  58.                         }
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.  
  64.         this.sort();
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment