Creating New World

Discussion in 'Plugin Development' started by Smeary_Subset, Mar 31, 2022.

  1. Offline

    Smeary_Subset

    When I try to create a new world or delete a world file from my server after unloading it, I get the following error:

    Code:
    Caused by: java.io.IOException: The process cannot access the file because another process has locked a portion of the file
            at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[?:?]
            at sun.nio.ch.FileDispatcherImpl.write(FileDispatcherImpl.java:68) ~[?:?]
            at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:132) ~[?:?]
            at sun.nio.ch.IOUtil.write(IOUtil.java:76) ~[?:?]
            at sun.nio.ch.IOUtil.write(IOUtil.java:67) ~[?:?]
            at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:285) ~[?:?]
            at net.minecraft.util.DirectoryLock.create(DirectoryLock.java:40) ~[?:?]
            at net.minecraft.world.level.storage.LevelStorageSource$LevelStorageAccess.<init>(LevelStorageSource.java:344) ~[?:?]
            at net.minecraft.world.level.storage.LevelStorageSource.createAccess(LevelStorageSource.java:314) ~[?:?]
            at org.bukkit.craftbukkit.v1_18_R2.CraftServer.createWorld(CraftServer.java:1178) ~[paper-1.18.2.jar:git-Paper-267]
            at me.smearysubset.arenabuilder.utilitycommand.generatenewworld.MyWorldCreator.createWorld(MyWorldCreator.java:42) ~[ArenaBuilder.jar:?]
            at me.smearysubset.arenabuilder.utilitycommand.generatenewworld.MyWorldCreator.run(MyWorldCreator.java:25) ~[ArenaBuilder.jar:?]
            at me.smearysubset.arenabuilder.utilitycommand.generatenewworld.CLI.onCommand(CLI.java:35) ~[ArenaBuilder.jar:?]        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            ... 9 more
    >
    To create the world, I am using Bukkit#getServer()#createWorld(WorldCreator wc). Oddly, sometimes the world is successfully created with no error while othertimes only the folder is created only containing a session.lock file (then the error is thrown).

    In terms of deleting the file, I first unload the world and remove it from the list of worlds in Bukkit#getWorlds(). Then I attempt to delete the folder in my server using FileUtils. Just like creating the world, sometimes it works while most of the time it leaves the folder undeleted and only with the session.lock file in it.

    I see the error, so I suppose my question it what is locking the file and is there a way to work around it? I think it is kind of peculiar that I can't use Bukkit.createWorld() without it throwing an error.
     
  2. Offline

    KarimAKL

  3. Offline

    Smeary_Subset

    I already tried that. I forgot to mention that but I already have that coded in my process.
     
  4. Offline

    KarimAKL

Share This Page