Solved Teleporting a player, and recording X,Y,Z and World.

Discussion in 'Plugin Development' started by MineCrypt, Dec 30, 2012.

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

    MineCrypt

    Alright I had this problem for a while now and I need help. I need to set points with my plugin and have them be able to get on server reloads/restarts/etc. Now I can do this:
    Code:
                plugin.getConfig().set("X", player.getLocation().getBlockX());
                plugin.getConfig().set("Y", player.getLocation().getBlockY());
                plugin.getConfig().set("Z", player.getLocation().getBlockZ());
                plugin.getConfig().set("World", player.getLocation().getWorld());
                plugin.saveConfig();
    And then tp by:
    Code:
                int X = plugin.getConfig().getInt("X");
                int Y = plugin.getConfig().getInt("Y");
                int Z = plugin.getConfig().getInt("Z");
                World World = (org.bukkit.World) plugin.getConfig().get("World");
                player.teleport(new Location(World, X, Y, Z));
    And that will work fine but if I try to reload it gives an error of:
    http://pastebin.com/ELratihY
    And if i go into the config the World would be set as:

    World: !!org.bukkit.craftbukkit.v1_4_6.CraftWorld
    PVP: true
    ambientSpawnLimit: 15
    animalSpawnLimit: 15
    autoSave: true
    difficulty: NORMAL
    environment: NORMAL
    fullTime: 562056
    keepSpawnInMemory: true
    monsterSpawnLimit: 70
    thunderDuration: 570
    thundering: false
    time: 10056
    waterAnimalSpawnLimit: 5
    weatherDuration: 130346
    I dont want all that. Can someone please help me with my problem,rephrase code, anything Idc. I just need this done fast. Thanks MineCrypt
     
  2. Offline

    krazyswaggaO

    p.getConfig().set("World", player.getLocation().getWorld().getName());
    You want to get the name of the world, not the data.
     
  3. Offline

    MineCrypt

    Now this part gives me an error:
    Code:
                World World = (org.bukkit.World) plugin.getConfig().get("World");
                player.teleport(new Location(World, X, Y, Z));
    Error:
    http://pastebin.com/gWs3JfML

    Can you fix that?

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

    krazyswaggaO

    Try:
    World World = Bukkit.getWorld(plugin.getConfig().get("World"));
     
  5. Offline

    MineCrypt

    Perfect! No errors and works correctly! Thank you guys!
     
  6. Offline

    Ewe Loon

    i think your problem is here

    World World = (org.bukkit.World) plugin.getConfig().get("World");
    1) var and class are spelled the same
    2) as World is a complex class dont write it to a config, just use its name

    use

    World world = getServer().GetWorld(plugin.getConfig().getString("World"));

    also note, worlds may not be loaded when OnEnable is called,
    since you are doing this after a player has joined, the worlds should be loaded
    butt it pays to check

    if (world==null){
    PANIC();
    lol();
    return;
    }

    Since i typed this on the fly, expect an error in the spelling and case

    wow, beeten to it while i was typing

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

    krazyswaggaO

    Or or or!
    Use what I told him to and save a few letters from typing :eek:.
     
Thread Status:
Not open for further replies.

Share This Page