Loading a serializable class from config... Help!

Discussion in 'Plugin Development' started by spoony_loony, Sep 8, 2013.

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

    spoony_loony

    Hello guys!

    I'v been making a plugin with a serializable location. So far it works great saving the location, but I can't load it. It throws an error added by the YML, so I have no clue what I'm doing wrong.

    Code:
    2013-09-08 08:53:53 [SEVERE] Cannot load plugins/MinegamesSigns/joinsigns.yml
    org.bukkit.configuration.InvalidConfigurationException: could not determine a constructor for the tag tag:yaml.org,2002:me.spoony.signs.SyncLocation
     in 'string', line 3, column 15:
            Location: !!me.spoony.signs.SyncLocation
                      ^
    
    Thanks in advanced!
     
  2. Offline

    remremrem

    You will have to show the code that saves and loads the joinsigns.yml file, plus the joinsigns.yml file itself.
     
  3. Offline

    Janmm14

  4. Offline

    dillyg10

    Simple,

    At the top of your serialized class add...

    @SerializableAs("Whatyouwanttobeinhere")

    Then, in your onEnable() before you load the config...

    ConfigurationSerialization.registerClass(YourClass.class, "Whatyouwanttobeinhere");
     
  5. Offline

    The_Doctor_123

    I made a class called "EasyConfig" in one of my projects for an easier yml configuration. One of the reasons for making it was for easy Location setting and getting from ymls. Here's some code(contains a bunch of stuff not shown, but you get the idea):

    Code:java
    1. public void setLocation(String ConfigPath, Location location)
    2. {
    3. ConfigPath = ConfigPath.replace('/', '.');
    4.  
    5. set(ConfigPath + ".x", location.getX());
    6. set(ConfigPath + ".y", location.getY());
    7. set(ConfigPath + ".z", location.getZ());
    8. set(ConfigPath + ".Yaw", location.getYaw());
    9. set(ConfigPath + ".Pitch", location.getPitch());
    10. set(ConfigPath + ".World", location.getWorld().getName());
    11. save();
    12. }
    13.  
    14. public Location getLocation(String ConfigPath)
    15. {
    16. ConfigPath = ConfigPath.replace('/', '.');
    17.  
    18. Location location = new Location(null, 0, 0, 0, 0, 0);
    19.  
    20. location.setX(getDouble(ConfigPath + ".x"));
    21. location.setY(getDouble(ConfigPath + ".y"));
    22. location.setZ(getDouble(ConfigPath + ".z"));
    23. location.setYaw(getFloat(ConfigPath + ".Yaw"));
    24. location.setPitch(getFloat(ConfigPath + ".Pitch"));
    25. location.setWorld(getWorld(ConfigPath + ".World"));
    26. return location;
    27. }
     
  6. Offline

    spoony_loony

Thread Status:
Not open for further replies.

Share This Page