Serialisation

Discussion in 'Plugin Development' started by TerroDoor, Mar 30, 2020.

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

    TerroDoor

    I have a player x,y,z stored in a double and put into a location, how can I serialise this location and save the xyz to config, thanks


    Sent from my iPhone using Tapatalk
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    TerroDoor

    Tried that, displays in config as “notnullx”
    Using a ConfigurationSection also which I don’t see a problem with


    Sent from my iPhone using Tapatalk
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    TerroDoor

    Solved, my path was in the wrong order. Thanks tho!


    Sent from my iPhone using Tapatalk
     
  6. Offline

    Strahan

    Location implements ConfigurationSerializable, so you're better off just writing the Location object itself to config instead of the X/Y/Z. You get more usable data that way.
     
  7. Offline

    TerroDoor

    @Strahan ConfigurationSeralizable? does this class do it automatically for me?
     
  8. Offline

    Strahan

    It's automatic. If you do something like getConfig().set("player.location", playerObject.getLocation()); it will write a Location object to the config. Then later you can do Location playerLocation = getConfig().getLocation("player.location");

    No manual serialization required.
     
    TerroDoor likes this.
  9. Offline

    TerroDoor

    Interesting, I’ll give this a go. Will it look similar to how I have it now or will it print every detail(yaw/pitcj/world/),




    Sent from my iPhone using Tapatalk
     
  10. Offline

    Strahan

    It's just a Location object, you do with it whatever you want. If you are using the stored location to teleport a player for example, you just playerObject.teleport(locationObject); It depends what you are trying to achieve. For something like teleportation, using a Location instead of X/Y/Z is far better as it stores those extra details so they can appear exactly where they were.
     
Thread Status:
Not open for further replies.

Share This Page