Solved Teleport Player to World

Discussion in 'Plugin Development' started by Loyal0713, Jun 15, 2023.

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

    Loyal0713

    Trying to teleport a player to a world which seems simple but nothing happens - errors or otherwise.

    What I've done:
    WorldManager class that, on plugin onEnable, iterates through worlds folder
    Code:
    private static String WORLDS_FOLDER = NoMansBlock.getInstance().getDataFolder().getPath().replace("\\", "/") + "/WORLDS/";
    public static void loadWorlds() {
        File f = new File(WORLDS_FOLDER);
        File[] files =f.listFiles();
        for (File file : files) {
            Bukkit.getLogger().info("Loading world: " + file.getPath().replace("\\", "/"));
            if (file.isDirectory()) {
                World wc = new WorldCreator(file.getPath().replace("\\", "/")).createWorld();  // read that this will load world so I do it
            }
        }
    }
    
    PlayerManager class, join gets called on PlayerJoinEvent
    Code:
    private static String WORLDS_FOLDER = NoMansBlock.getInstance().getDataFolder().getPath().replace("\\", "/") + "/WORLDS/";
    public static void join(Player player) throws IOException {
            // load player into hub
            String currentWorld = "hub";
            Location loc = new Location(Bukkit.getWorld(WORLDS_FOLDER + currentWorld), 0,0,0);
            player.teleport(loc);
    }
    
    I don't get any errors: I get loaded into the default "world", not the "hub" world. In the console I do see:
    Code:
    Loading world: plugins/Nmb/WORLDS/hub
    [00:18:51 INFO]: Preparing start region for dimension minecraft:plugins/nmb/worlds/hub
    
    so the world is there. Was going to look at Multiverse but I'm not seeing any releases for 1.20.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Loyal0713

    This gets printed when loadWorlds is called:
    Code:
    Loading world: plugins/Nmb/WORLDS/hub
    
    Also added the line under World wc = ...:
    Code:
    Bukkit.getLogger().info("wc.getName(): " + wc.getName());
    
    Console output:
    Code:
    wc.getName(): plugins/Nmb/WORLDS/hub
    
    This folder does exist and has all the files/folders like data, region, level.dat, etc.

    I've stripped my original plugin to just the classes that deal with the world loading and player teleporting which is working for some reason. At least now I can compare the stripped version vs the main version. Below is a link to a Github repo containing the source and a JAR for the latest compiled version.

    https://github.com/Loyal0713/NMB-Utility/tree/master

    EDIT: hey, professional dumbass here, in my main plugin, I had disabled portals by canceling the teleport event (except ender pearls). Obviously that's a conflict, changed code to:
    Code:
    player.getServer().getPlayer(player.getName()).teleport(loc, PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
    
    and this worked. Hopefully if someone runs into this, they won't have to struggle for as long as I did for such a simple fix.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Jun 15, 2023
Thread Status:
Not open for further replies.

Share This Page