Config to World

Discussion in 'Plugin Development' started by A5H73Y, Dec 3, 2012.

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

    A5H73Y

    So I am trying to teleport the player to the world which they set in the config.

    Code:
    Double posx = config.getDouble("Lobby.X");
    Double posy = config.getDouble("Lobby.Y");
    Double posz = config.getDouble("Lobby.Z");
    int posyaw = config.getInt("Lobby.Yaw");
    int pospitch = config.getInt("Lobby.Pitch");
                               
    World world = config.get("Lobby.World");
                                   
    Location lobby = world, posx, posy, posz, posyaw, pospitch);
                                     
    player.teleport(lobby);
    Please help :)
     
  2. Offline

    Haribo98

    You need to check the World is a real world and then to create the Location.
    Location lobby = new Location(world, posx, posy, posz, posyaw, pospitch);
     
  3. Offline

    A5H73Y

    There is nothing wrong with the statement, except the world part:
    Location lobby = new Location(player.getWorld(), posx, posy, posz, posyaw, pospitch);
    Works fine...
     
  4. Offline

    Haribo98

    You need to CHECK the world exits
    Here is some example code, change it to your needs.
    Code:
            String wN = plugin.getConfig("map").getString( map + "." + team + ".spawn.world");
            double lX = plugin.getConfig("map").getDouble( map + "." + team + ".spawn.x");
            double lY = plugin.getConfig("map").getDouble( map + "." + team + ".spawn.y");
            double lZ = plugin.getConfig("map").getDouble( map + "." + team + ".spawn.z");
            float p = plugin.getConfig("map").getInt( map + "." + team + ".spawn.pitch");
            float y = plugin.getConfig("map").getInt( map + "." + team + ".spawn.yaw");
            List<World> worlds = Bukkit.getWorlds();
            World w = null;
            for (World world : worlds) {
                if (world.getName().equals(wN)) {
                    w = world;
                    Location l = new Location(w, lX, lY, lZ, p, y);
                    player.teleport(l);
                }
            }
    Oh, and Pitch and Yaws are floats. The location creation will only work, with floats.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
    A5H73Y likes this.
  5. Offline

    A5H73Y

    List<World> worlds = Bukkit.getWorlds();
    Wants to be changed to
    List<org.bukkit.World> worlds = Bukkit.getWorlds();
    ?
     
  6. Offline

    Haribo98

    Nope. If you're using Eclipse or NetBeans, you can import the "World"
     
  7. Offline

    A5H73Y

    Im using Eclipse classic, I have imported "import net.minecraft.server.World;"?

    OMG i love you. I deleted the old one and added org.bukkit.world and its worked. Thats been the problem, thanks :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  8. Offline

    Haribo98

    No Problem ;)
    Bukkit really should implement a more simpler way of doing this. At least I don't know of any faster way :p
     
  9. Offline

    Sagacious_Zed Bukkit Docs

    You can keep yourself out of trouble by only depending on bukkit.jar
     
  10. Offline

    Haribo98

    And any other plugins you need. Or if you want to use NBTTags, you need the craftbukkit.jar
     
Thread Status:
Not open for further replies.

Share This Page