Problems with loading my config.yml

Discussion in 'Plugin Development' started by Patrick Wrobel, Dec 18, 2011.

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

    Patrick Wrobel

    I've been having problems with saving/loading a serializable class of mine to the config.yml. Saving to seems to work fine but when I load it, I get an exception when reading - !!com.gmail.craptik.containerclasses.Forge

    So here is my class
    Code:
    package com.gmail.craptik.containerclasses;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.configuration.serialization.ConfigurationSerializable;
    import org.bukkit.enchantments.Enchantment;
    
    import com.gmail.craptik.Properties;
    
    public class Forge implements ConfigurationSerializable
    {
        private int x = 0, y = 0, z = 0;
        private int diamondStrength = 0, goldStrength = 0, ironStrength = 0;
        private String worldName = "UnitializedString";
        private String owner = "UnitializedString";
        private List<String> users = new ArrayList<String>();
        private Map<Enchantment, Integer> itemEnchantment = new HashMap<Enchantment, Integer>();
    
        public Forge()
        {
    
        }
    
        public Forge(Block block)
        {
            x = block.getX();
            y = block.getY();
            z = block.getZ();
            worldName = block.getWorld().getName();
        }
    
        public Forge(Location location)
        {
            x = location.getBlockX();
            y = location.getBlockY();
            z = location.getBlockZ();
            worldName = location.getWorld().getName();
        }
    
        @SuppressWarnings("unchecked")
        public Forge(Map <String,Object> map)
        {
            setX((Integer)map.get("x"));
            setY((Integer)map.get("y"));
            setZ((Integer)map.get("z"));
    
            setDiamondStrength((Integer)map.get("diamondStrength"));
            setGoldStrength((Integer)map.get("goldStrength"));
            setIronStrength((Integer)map.get("ironStrength"));
    
            setWorldName((String)map.get("world"));
    
            setOwner((String)map.get("owner"));
            setUsers((List<String>)map.get("users"));
    
            setItemEnchantment((Map<Enchantment, Integer>)map.get("enchant"));
        }
    
        public Map<String, Object> serialize()
        {
            Map<String, Object> map = new HashMap<String, Object>();
    
            map.put("x", getX());
            map.put("y", getY());
            map.put("z", getZ());
            map.put("diamondStrength", getDiamondStrength());
            map.put("goldStrength", getGoldStrength());
            map.put("ironStrength", getIronStrength());
            map.put("world", getWorldName());
            map.put("owner", getOwner());
            map.put("users", getUsers());
            map.put("enchant", getItemEnchantment());
    
            return map;
        }
    
        public static Forge deserialize(Map <String,Object> map)
        {
            Forge forge = new Forge(map);
            return forge;
        }
    }
    here is my config.yml
    Code:
    AllowJoining: false
    Forges:
    - !!com.gmail.craptik.containerclasses.Forge #get the error here
      diamondStrength: 0
      goldStrength: 0
      ironStrength: 0
      itemEnchantment: {}
      owner: PeteyPii
      users: []
      worldName: world
      x: 131
      y: 78
      z: 173
    - !!com.gmail.craptik.containerclasses.Forge
      diamondStrength: 0
      goldStrength: 0
      ironStrength: 0
      itemEnchantment: {}
      owner: PeteyPii
      users: []
      worldName: world
      x: 131
      y: 78
      z: 168
    
    also, when there is an item enchantment, i get the same type of string starting with !!, so I probably need to fix that as well
     
  2. Offline

    Sagacious_Zed Bukkit Docs

  3. Offline

    Patrick Wrobel

    ALright, I assume you're talking about my constructors that don't set all of the values. I fixed them, so that they set all the default values, however, it still doesn't work. I'm saving and loading the same way as your plugin, but I'm saving a List<Forge>. Any other ideas?

    EDIT: heres the error:
    Code:
    2011-12-18 19:56:50 [SEVERE] Error occurred while enabling ForgeRepair v0.1 (Is it up to date?): null; could not determine a constructor for the tag tag:yaml.org,2002:com.gmail.craptik.containerclasses.Forge
    could not determine a constructor for the tag tag:yaml.org,2002:com.gmail.craptik.containerclasses.Forge
     in "<string>", line 3, column 3:
        - !!com.gmail.craptik.containercla ...
          ^
    
        at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructUndefined.construct(SafeConstructor.java:475)
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183)
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2(BaseConstructor.java:277)
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequence(BaseConstructor.java:248)
        at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlSeq.construct(SafeConstructor.java:440)
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183)
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:326)
        at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:143)
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:307)
        at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:459)
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183)
        at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:142)
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:128)
        at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:59)
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:143)
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:109)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:235)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:131)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:125)
        at com.gmail.craptik.Properties.addAllDefaults(Properties.java:25)
        at com.gmail.craptik.Properties.loadProperties(Properties.java:17)
        at com.gmail.craptik.ForgeRepair.onEnable(ForgeRepair.java:41)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:188)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:968)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:186)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:169)
        at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:348)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:335)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:165)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:399)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    @Patrick Wrobel
    DId you register the class in your main class file?
     
Thread Status:
Not open for further replies.

Share This Page