Deleting .mca (Region) files from world folder

Discussion in 'Spigot Plugin Development' started by GoRoK, Apr 22, 2017.

  1. Hey there,

    so currently im trying to delete a complete world folder, everything works, except the deletion of the mca files.

    I set them read / writeable, unloaded chunks and world. No errors, im not too sure where bukkit bound them.

    Here's my code so far:

    Code (Text):


    public void deleteWorld(){

        try{

            WorldReset.getInstance().worldReset = true;

            World w = Bukkit.getWorld("Farmwelt");

            File folder = w.getWorldFolder();

            for(Player p : w.getPlayers()){
                Location mainSpawn = Bukkit.getWorld("world").getSpawnLocation();

                p.teleport(mainSpawn);
                p.sendTitle("§4---ACHTUNG---","§cWorld-Reset");

            }

            for(Chunk c : w.getLoadedChunks()){

                boolean b = c.unload();

                if(b)
                    continue;


                c.unload();

            }


            boolean b = false;
            Bukkit.getServer().unloadWorld(w, b);

            System.out.println("World unloaded: " + b);

            if(b)
                folder.delete();
            else
                Bukkit.getServer().unloadWorld(w,b);

            if(b)
                folder.delete();


            for(File locked : folder.listFiles()){

                if(locked.getName().startsWith("session")){

                    locked.setWritable(true);
                    locked.setReadable(true);
                    locked.delete();
                    System.out.println("Deleted lock File: " + locked.getName());
                }
                continue;



            }


            for(File f : folder.listFiles()){



                if(f.getName().equalsIgnoreCase("region")){

                    File sessionFolder = f;

                    for(File sessions : f.listFiles()){

                        sessions.setWritable(true);
                        sessions.delete();

                        System.out.println("Deleted session: " + sessions.getName());


                    }

                }

                f.setWritable(true);
                f.delete();
                System.out.println("Removed file: " + f.getName());

            }



            System.out.println("Folder deleted: " + folder.exists() + " Unloaded: " + b);


        }catch(Exception ex){

            ex.printStackTrace();

        }





    }

     
     
  2. sothatsit

    Patron

    Code (Text):
    for(Chunk c : w.getLoadedChunks()){
      boolean b = c.unload();
      if(b)
         continue;
      c.unload();
    }
    This whole running it twice thing if it fails is rather primitive. There is no reason that if it failed the first time, it wouldn't fail the second. Additionally, if it fails twice, you carry on like it succeeded.

    Code (Text):
    boolean b = false;
    Bukkit.getServer().unloadWorld(w, b);
    "b" will always be false. You never set it.

    I'm going to stop there, because it will just be unproductive for me, as I will end up fixing your code for you. I think you need to brush up on your programming and/or Java. I would suggest TheNewBoston youtube channel, he has a very clear video tutorial series on learning Java.