Solved How can I set an XYZ location in Config.YML ?

Discussion in 'Plugin Development' started by ZeusAllMighty11, Jul 16, 2012.

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

    ZeusAllMighty11

    I need to be able to set XYZ coordinates in the config, so I can teleport to them. How can I do this?

    I have my config class created already
     
  2. Offline

    Kodfod

    If i'm not mistaken this should work:

    Code:JAVA
    1.  
    2. //if command
    3. Player player = (Player) sender;
    4. //Or if in an event:
    5. Player player = event.getPlayer();
    6. //define Location
    7. Location loc = player.getLocation();
    8. //Add location to file
    9. getCustomConfig().add(player.getName() + ".home", loc);
    10. //Save the file
    11. saveCustomConfig();
    12.  
     
  3. Offline

    ZeusAllMighty11


    What if I don't want to get coords of a player? I just want to out-of-the-blue set some coords?
     
  4. Offline

    Kodfod

    Code:Java
    1.  
    2. config.addDefault("Teleport.x", 64);
    3. confid.addDefault("Teleport,y", 72);
    4. config.addDefault("Teleport.z", 168);
    5.  


    Call them as needed
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    Don't use addDefault if you expect them to be edited.
     
  6. Offline

    Kodfod

    He said he already made his own config class, i'm assuming he is only calling that when the file is null
     
  7. Offline

    ZeusAllMighty11

    No, I want to be able to edit the coords :p
     
  8. Offline

    Kodfod

    okay then change "addDefault" too "add"

    what i do is this:

    where i put my plugin.yml i make a config.yml

    then type this:

    [Syantax=Java]
    @Override
    public void onEnable() {
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();
    }
    [/syantax]

    My Config.yml:
    Code:YMAL
    1.  
    2. Diamond:
    3. Pickaxe:
    4. Use: 5
    5. Axe:
    6. Use: 5
    7. Shovel:
    8. Use: 5
    9. Hoe:
    10. Use: 5
    11. //and on and on
    12. [/syantx]
    13.  
    14. Then when the plugin is enabled, if the file is null or if the default section does not exsist, it writes it. No Overwriting.
    15.  
    16. [Syantx=Java]
    17. @Override
    18. public void onDisable() {
    19. this.saveConfig();
    20. }
    21. //Just saves any changes that may have happened
    22.  
     
  9. you dont need to insert at your plugin.yml that your plugin is making a config.yml
     
  10. Offline

    Kodfod

    no what i mean is if i put my plugin.yml in /src i put my config.yml in /src
     
  11. Offline

    spiner00

    How would I teleport to that saved location?

    would it be:
    Code:
    player.teleport(loc)
    Plz help
     
  12. Offline

    RealDope

    spiner00

    Code:JAVA
    1.  
    2. Location loc = new Location(world, x ,y ,z)
    3. player.teleport(loc);
    4.  


    Kodfod
    I don't think you can just straight up store a location in a file.. You have to break it down into world, x, y, z.
     
  13. Offline

    ZeusAllMighty11

    RealDope

    Yep that's how I did it. I found a better way now I'll share it at some point.
     
  14. Offline

    RealDope

    Oh wow didn't realize this was such an old post lol, just saw it on the top of the forum and replied to spiner haha
     
  15. Offline

    robertobobbym

    Could you share it now?
     
  16. Offline

    Woobie

    Storing location in config:
    Code:
    Location loc = e.getPlayer().getLocation();
                    config.addDefault("your.path.x", loc.getX());
                    config.addDefault("your.path.y", loc.getY());
                    config.addDefault("your.path.z", loc.getZ());
    If your config already contains these locations, replace addDefault with set
    config.set("your.path", loc.getX());
    etc...

    Teleporting to the location:
    Code:
    double x = config.getInt("your.path.x");
                double y = config.getInt("your.path.y");
                double z = config.getInt("your.path.z");
                Location lobby = new Location(p.getServer().getWorld(config.getString("your.path.world")), x, y, z);
                whoever.teleport(lobby);
    This is how I do it.
     
  17. Offline

    ZeusAllMighty11

    Since I commonly track player locations in this plugin I made, I just make 1 standard method of getting and setting a player's coords. But I can't find the source now :S
     
Thread Status:
Not open for further replies.

Share This Page