Solved World not loading from custom folder

Discussion in 'Plugin Development' started by voltywolty, Oct 27, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    voltywolty

    I've created a custom folder called maps in my plugins/DvZ/ directory. I put two maps in there, tell the plugin to grab a random world from the folder and load it, which it does, however, it is not loading the actual world files from the maps folder, just a new world with the folder name being the map name. What do I need to do?

    A snippet of my code is below, the code provided is in my onEnable.

    Code:
    if (!(mapsFolder.exists())) {
                System.out.println("Maps folder not found! Creating maps folder...");
                mapsFolder.mkdir();
            }
            else {
                System.out.println("Maps folder found!");
            }
    
            for (File file : mapsFolder.listFiles()) {
                if (file.isDirectory()) {
                    worldNames.add(file.getName());
                }
            }
    
            randomWorld = random.nextInt(worldNames.size());
            world = this.getServer().createWorld(new WorldCreator(worldNames.get(randomWorld)));
            this.getServer().unloadWorld("world", false);
            this.getLogger().info("Loaded map: " + worldNames.get(randomWorld));
     
  2. Online

    KarimAKL

    @voltywolty You are creating a new world from the file, not loading it.
     
  3. Offline

    voltywolty

    I thought createWorld will also load a world if it’s there. How can I load a world from custom folder?
     
  4. Online

    KarimAKL

    Yes, from the server directory, not your plugin's directory.

    I don't think you can do that with the Bukkit API, but you might be able to do something using NMS.
     
  5. Offline

    voltywolty

    Sorry, what’s NMS?
     
  6. Online

    KarimAKL

    NMS is an abbreviation of "net.minecraft.server" and is the source code of the Minecraft server.
    Bukkit is an API for NMS, but it doesn't allow you to do everything you can do with pure NMS.
     
  7. Offline

    voltywolty

    Was told to not use NMS. Any other options anyone?
     
  8. Online

    KarimAKL

    If NMS cannot do it, then it's impossible. Bukkit is just an API for NMS.
     
  9. Offline

    voltywolty

    What about it not being in a custom directory? Could I still get the world names from the world folders inside the normal directory and have it get loaded randomly?
     
  10. Online

    KarimAKL

    @voltywolty So you just want to load a random world? If that's the case, then yeah, you don't need a custom directory at all.
     
  11. Offline

    voltywolty

    I’ll just do that instead. How do I get the directory of the folder with the server.jar
     
  12. Online

    KarimAKL

    @voltywolty There is a pretty useful method for that. Here is the Javadoc link.
     
  13. Offline

    voltywolty

    Ah okay, I got it. The thing is, it isn't teleporting the player to the current world.

    Code:
    @EventHandler
        private void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            player.teleport(newWorld.getSpawnLocation());
        }
     
  14. Online

    KarimAKL

    @voltywolty You might have to delay it by a tick. Use a BukkitRunnable for that.
     
Thread Status:
Not open for further replies.

Share This Page