Solved Help needed with saving/reading a location from the config file

Discussion in 'Spigot Plugin Development' started by Ma100, Jan 15, 2020.

Thread Status:
Not open for further replies.
  1. I tried saving/reading a location from the config file with th following code:

    Code (Java):
    this.saveDefaultConfig();
            World wrld = Bukkit.getServer().getWorld(this.getConfig().getString("afkWarp.world"));
            //
            Bukkit.getLogger().info("[[[[[[[World read from config is " + wrld + "]]]]]]]");
            if (wrld != null) { WarpLocation.setWorld(wrld);} else { Bukkit.getLogger().info("[[[[[[[World read from config is null.]]]]]]]"); }
            WarpLocation.setX(this.getConfig().getDouble("afkWarp.x"));
            WarpLocation.setY(this.getConfig().getDouble("afkWarp.y"));
            WarpLocation.setZ(this.getConfig().getDouble("afkWarp.z"));
            WarpLocation.setYaw((float)this.getConfig().getDouble("afkWarp.yaw"));
            WarpLocation.setPitch((float)this.getConfig().getDouble("afkWarp.pitch"));
            Bukkit.getLogger().info("[[[[[[[Position of AFK warp read from the config is " + WarpLocation + "]]]]]]]");
            commands.loadedFromConfig = WarpLocation;

    My default config.yml
    Code (Text):
    #This is the default configuration file.
    #Please don't change values unless you know what you are doing.
    afkWarp:
      world: world
      x: 0.0
      y: 0.0
      z: 100.0
      pitch: 0.0
      yaw: 0.0
    For some reason,
    Code (Text):
    if (wrld != null) { WarpLocation.setWorld(wrld);} else { Bukkit.getLogger().info("[[[[[[[World read from config is null.]]]]]]]"); }
    gives an error. If I comment the line, the next line gives one.
    Please help. (Code samples appreciated)
    Thanks!
     
  2. To save a location:
    FileConfiguration#set("path", Location)
    To fetch a location:
    FileConfiguration#getLocation("path")
     
  3. What do I need to import? (
    Code (Java):
    using
    )
     
  4. The import is org.bukkit.configuration.file.FileConfiguration.
     
  5. I got these errors:
    Code (Text):
    Description    Resource    Path    Location    Type
    FileConfiguration cannot be resolved to a variable    Main.java    /AFKTP/src/me/Ma100/afktp    line 40    Java Problem
    Syntax error on token "Invalid Character", ; expected    Main.java    /AFKTP/src/me/Ma100/afktp    line 40    Java Problem
    The method getLocation(String) is undefined for the type Main    Main.java    /AFKTP/src/me/Ma100/afktp    line 40    Java Problem
     
     
    • Useful Useful x 1
  6. WarpLocation... Why are you using a WarpLocation class? Use Location instead.

    Give us the stacktrace

    That works too, but he can fix his system.

    Many IDEs have auto importing functions, like IntelliJ. They're useful if you don't know imports

    Well what is on line 40?
     
  7. WarpLocation is my Location variable. On line 40 is :
    Code (Java):
    WarpLocation = FileConfiguration#getLocation("afkWarp.position");
     
  8. Please learn basic Java. When I said FileConfiguration#whatever I didn't mean that you would have to litterally use it.. I meant that this is the method that you have to call on a FileConfiguration object that is returned by JavaPlugin#getConfig
     
    • Agree Agree x 1
  9. FileConfiguration is not a variable and # is not a valid character
    Again, learn Java
     
  10. Other developers can always tell when somebody knows a programming language well or not. You will find benefit from learning fundamentals of java before moving into spigot development.

    We are not here to spoon feed you answers.
     
  11. Ok, got it to work
     
Thread Status:
Not open for further replies.