saving a location in a config

Discussion in 'Plugin Development' started by nitrousspark, Jun 16, 2012.

  1. Offline

    nitrousspark

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    how would i save a location in the config. like if somebody types /setlocation it will save that location in a .yml
  2. Offline

    kumpelblase2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    When you would use the search you probably will already find about twenty threads about the exact same question.
  3. Offline

    iKeirNez

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Save it using this:

    Code:
    config.set("something.location.X" + player.getLocation.getX());
    config.set("location.World" + player.getLocation.getWorld());
    config.set("location.Y" + player.getLocation.getY());
    config.set("location.Z" + player.getLocation.getZ());
    config.set("location.Yaw" + player.getLocation.getYaw());
    config.set("location.Pitch" + player.getLocation.getPitch());
    and then to get it and store it as a location use this:

    Code:
    Location newloc = new Location(config.get("location.World"), config.getDouble("location.X"), config.getDouble("location.Y"), config.getDouble("location.Z"), config.getFloat("location.Yaw"), config.getPitch("location.Pitch"));
    I am doing that from memory so it may not be 100% correct.
    hawkfalcon likes this.
  4. Offline

    iKeirNez

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Wow never realised how badly I messed up there, should be

    Code:
    config.set("location.World" + player.getLocation.getWorld());
    config.set("location.X" + player.getLocation.getX());
    config.set("location.Y" + player.getLocation.getY());
    config.set("location.Z" + player.getLocation.getZ());
    config.set("location.Yaw" + player.getLocation.getYaw());
    config.set("location.Pitch" + player.getLocation.getPitch());
    
  5. Offline

    Gawdzahh

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Close but you did something wrong, player.getLocation needs to be a Location. So instead do this
    Code:
    Location loc = player.getLocation();
    config.set("location.World" + loc.getWorld());
    config.set("location.X" + loc.getX());
    config.set("location.Y" + loc.getY());
    config.set("location.Z" + loc.getZ());
    config.set("location.Yaw" + loc.getYaw());
    config.set("location.Pitch" + .loc.getPitch());
    :) Hope it helps

    This post has been edited 1 time. It was last edited by Gawdzahh Jul 18, 2012.
  6. Offline

    WarmakerT

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Nope!
    Code:
    Location loc = player.getLocation();
    config.set("location.World" , loc.getWorld());
    config.set("location.X" , loc.getX());
    config.set("location.Y" , loc.getY());
    config.set("location.Z" , loc.getZ());
    config.set("location.Yaw" , loc.getYaw());
    config.set("location.Pitch" , loc.getPitch());
  7. Offline

    Gawdzahh

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    True, haha

Share This Page