Teleporting a player to other worlds?

Discussion in 'Plugin Development' started by techboy291, Aug 29, 2012.

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

    techboy291

    Hi,


    So I've been trying to make it so players can teleport to other worlds. I've seen all of the threads on the forums, but none of the answers seem to work for me. Here's the code:


    Code:
            if(cmd.getName().equalsIgnoreCase("worldtp")) {
                Location world = getServer().getWorld(args[0]).getSpawnLocation();
                loc = new Location(getServer().getWorld(args[0]), world.getX(), world.getY(), world.getZ());
                senderplayer.teleport(loc);
                return true;
            }
    Note: I declared the "loc" variable earlier in the code.


    Ideas?
     
  2. Offline

    V10lator

    if you create a new location you pass a world, x, y and z to it. So instead of giving it the first world (getServer().getWorld(args[0])) just give it another world, like this:
    Location to = new Location(getServer().getWorld("AnotherWorld", x, y, z);
    player.teleport(to);

    BTW: Why are you creating a new location with the exact same world, x, y and z as the previous location? In other worlds: Why not just:
    Location world = getServer().getWorld(args[0]).getSpawnLocation();
    senderplayer.teleport(world);
     
  3. Offline

    techboy291

    Okay, so I tried this:
    Code:
    if(cmd.getName().equalsIgnoreCase("worldtp")) {
                Location world = getServer().getWorld(args[0]).getSpawnLocation();
                senderplayer.teleport(world);
                return true;
            }
    But it still doesn't work.

    Also, I don't know if this helps, but the world I used to test out the plugin I put in the same directory as the jar that I use to run the server.
     
  4. Offline

    V10lator

    So you have a folder called worldtp in your server but you didn't load it? Then you have to load this world before you can tp to it. You could do this in your bukkit.yml, with a plugin like MultiVerse or with Java code in your plugin.
     
  5. Offline

    techboy291

    1. No, worldtp is the command. I named the test world "test_world" and typed "/worldtp test_world" into my server and it didn't work.

    2. How do I load a world?
     
  6. Offline

    V10lator

  7. Offline

    techboy291

    Yes! It's working! Thanks a bunch!
     
  8. Offline

    theCodeBro

    wait, I don't get it. i tried registering a world in the bukkit.yml, but it still doesn't work. here's my code:
    Code:
    if(cmd.equalsIgnoreCase("tpWorld")){
                    Location loc =  new Location(getServer().getWorld(args[0]),1, 1, 1);     
                    player.teleport(loc);
                }
    Code:
    # This is the main configuration file for Bukkit.
    # As you can see, there's actually not that much to configure without any plugins.
    # For a reference for any variable inside this file, check out the bukkit wiki at
    # http://wiki.bukkit.org/Bukkit.yml
    settings:
      allow-end: true
      warn-on-overload: true
      permissions-file: permissions.yml
      update-folder: update
      ping-packet-limit: 100
      use-exact-login-location: false
      plugin-profiling: false
      connection-throttle: 4000
      query-plugins: true
      deprecated-verbose: default
      shutdown-message: Server closed
    spawn-limits:
      monsters: 70
      animals: 15
      water-animals: 5
      ambient: 15
    chunk-gc:
      period-in-ticks: 600
      load-threshold: 0
    ticks-per:
      animal-spawns: 400
      monster-spawns: 1
      autosave: 0
    auto-updater:
      enabled: true
      on-broken:
      - warn-console
      - warn-ops
      on-update:
      - warn-console
      - warn-ops
      preferred-channel: rb
      host: dl.bukkit.org
      suggest-channels: true
    database:
      username: bukkit
      isolation: SERIALIZABLE
      driver: org.sqlite.JDBC
      password: walrus
      url: jdbc:sqlite:{DIR}{NAME}.db
     worlds:
       world1:
         generator: CleanroomGenerator
      url: jdbc:sqlite:{DIR}{NAME}.db
    
     
  9. Offline

    techboy291

    Yeah, using bukkit.yml for registering worlds didn't work for me, either. Try using the WorldCreator class, instead. It works for both creating worlds and loading worlds that have already been created (the only problem is that all worlds are unloaded every time the server stops). So you could do:

    Code:
    if(cmd.getName().equalsIgnoreCase("tpWorld") && args.length==1) {
    Location l;
    if(getServer().getWorld(args[0]) == null)
    l = new WorldCreator(args[0]).createWorld().getSpawnLocation();
    else
    l = getServer().getWorld(args[0]).getSpawnLocation();
    player.teleport(l);
    }
     
Thread Status:
Not open for further replies.

Share This Page