Error in time get Location in config

Discussion in 'Plugin Development' started by @DriftCoder, Aug 18, 2015.

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

    @DriftCoder

    I changed the spigot version of my server to 1.7.10 and now my plugin not this longer able to take place this in the configuration file:

    Console error:

    My Config:

    What can it be?

    ===============================[Edit]=============================

    Now my configuration file this way:

    And this now generating a new error on the console!

     
    Last edited: Aug 19, 2015
  2. "Caused by: java.lang.ClassCastException: org.bukkit.configuration.MemorySection cannot be cast to org.bukkit.Location"
    Somewhere you try to cast config.get("path") or config.getConfigurationSection("path") to Location
     
  3. Offline

    MCMatters

    @@DriftCoder Instead of getting it make an instance of Location and grab x,y,z and world values from it.
     
  4. Offline

    Synapz

    @@DriftCoder when you store a raw location in a config it looks something like this,
    Code:
    Blue-Lobby:
          ==: org.bukkit.Location
          yaw: 97.19986
          pitch: 29.399996
          z: -262.666333779758
          y: 101.0
          world: world
          x: 205.94143219928873
    Your setting it to have its own format. Java cant adopt and suddenly change things. So it gets confused and reads it as a "MemorySection".

    When you use config.set("Lobby", player.getLocation()); the correct format is applied as shown above, as the location is in its raw state. I suggest you add the raw location to the file so you can easily extract it using,
    Code:
    public Location getLocation() {
        return (Location) config.get("Lobby");
    }
    In this case you can cast it because the location is in its raw state.

    If you dont want to do it that way, you can just store the x y and z in the config, then when you get the values add it to a new Location(x,y,z,world) manually (as @MCMatters said). However the other way is more precise
     
  5. Offline

    @DriftCoder

  6. Online

    CraftCreeper6

    @@DriftCoder
    What are you adding to the config? Show me. You can't add the Location class to a YAML file.
     
  7. You can use my LocationUtils class if you want. It's much simpler and has a few other features too!
    Use this to serialize/save it:
    Code:
    config.set("path", LocationUtils.serializeFully(location));
    Use this to deserialize/load it:
    Code:
    Location loc = LocationUtils.deserializeFully(config.getString("path"));
    EDIT: Added JavaDocs comments in the class
     
  8. Offline

    @DriftCoder

    @CraftCreeper6 I added the line

    to my configuration file, read more up on the topic

    @FisheyLP but because I'm getting this error only in version 1.7.10? before pulling back the version of the plugin, while still at version 1.8 worked perfectly ... I really need all this aew if so I will have to change all methods of using this plugin

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  9. Online

    CraftCreeper6

  10. Offline

    Synapz

    @CraftCreeper6
    I don't believe you have to serialize it (Ive added a raw location in one of my plugins and it worked fine).
    @@DriftCoder is having the issue on compatibility.

    I suggest maybe you update 2 versions of the plugin, one built along side 1.7.10 and build along side 1.8. Unless there is some sort of backwards compatibility or simple mistake Im missing.
     
  11.  
    Synapz likes this.
  12. Offline

    @DriftCoder

    Last edited by a moderator: Jun 11, 2016
Thread Status:
Not open for further replies.

Share This Page