Save Waypoints/Coordinates in .yml

Discussion in 'Plugin Development' started by Alias_Me, Jan 14, 2019.

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


    Im making a Waypoint plugin where players can build a specific structure (Guideposts) which can then be accessed as fast travel points, but only from other Guideposts.
    Ive got the events for when a Guidepost is created/destroyed all set, all I need to do now is write them to a file on creation and deletes them when a Guidepost is destroyed, but I`ve got no Idea how to do that in an efficient manner.

    EDIT: All Guardposts have to have a Name (which is written on a sign) to be valid
    Last edited: Jan 14, 2019
  2. Offline


    @Alias_Me Do you want 1 file with all the information or do you want a file for every guardpost?
  3. Offline


    @KarimAKL Preferrably a single File, but if its easier one for every post wouldnt be a problem
  4. Online

    timtower Ninja on the waves Moderator

    @Alias_Me Set the location based on the name as key, and the x,y,z,world as value. (might want to split it in 4 values)
    Then set the section to null when it gets destroyed.
  5. Offline


    In that case i would create the file onEnable and then write to it later.
    To write to the file you can do something like this:
    1. File file = new File("path/to/file");
    2. FileConfiguration config = YamlConfiguration.load(file);
    4. Player player = Bukkit.getPlayer("name");
    5. Location location = player.getLocation();
    6. config.set("", location.getWorld().getName());
    7. config.set("", location.getX());
    8. //etc
    9.; //This line will need a try catch.

    Delete by doing 'config.set("", null);' etc.
    torpkev likes this.
  6. Offline


    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page