Solved Configuration File Problem

Discussion in 'Plugin Development' started by oriamrm, Nov 8, 2016.

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

    oriamrm

    So I Created An Object Called "Mail", and from some reason I can't save it in a Yaml file.
    I have been working with Yaml files for quite a while, and I can save any other object. So I think the problem is in my Mail object.

    My Code:
    Code:
    public class Mail {
        public ItemStack message;
        public ItemStack icon;
      
        public Mail(){
    
        }
      
        public void setIcon(ItemStack newIcon){
            icon = newIcon;
        }
        public void setMessage(ItemStack newMail){
            message = newMail;
        }
        public ItemStack getIcon(){
            return icon;
        }
        public ItemStack getMessage(){
            return message;
        }
    }
    Code:
    PlayerData pd = new PlayerData(player.getName());
          
            ItemStack item = new ItemStack(Material.APPLE);
            ItemMeta itemM = item.getItemMeta();
            itemM.setDisplayName("ashdlkajhfsladjkf");
            item.setItemMeta(itemM);
          
            Mail mail = new Mail();
            mail.setIcon(item);
            mail.setMessage(new ItemStack(Material.APPLE));
            pd.sendMail(mail);
    Code:
    private File file = Main.CreateFile("PlayerData");
        private DataStorage Data = new DataStorage(file);
        private String playerName;
    public List<Mail> getMails(){
            return (List<Mail>) Data.getSecObj(playerName, "Mails");
        }
        public void sendMail(Mail mail){
            List<Mail> mails = getMails();
            mails.add(mail);
            Data.saveObjInSec(playerName, "Mails", mail);
        }
    
    Code:
    public Object getSecObj(String Section, String FieldName){
            return DataYAML.getConfigurationSection(Section).get(FieldName);
        }
    Error Code:
    Code:
    [18:15:27 WARN]: org.bukkit.configuration.InvalidConfigurationException: could not determine a constructor for the tag !oriamrm.economy.GUIs.Mail
    in 'string', line 8, column 10:
          Mails: !oriamrm.economy.GUIs.Mail
                 ^
    
    [18:15:27 WARN]:        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:56)
    [18:15:27 WARN]:        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:184)
    [18:15:27 WARN]:        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:130)
    [18:15:27 WARN]:        at oriamrm.economy.DataStorage.<init>(DataStorage.java:23)
    [18:15:27 WARN]:        at oriamrm.economy.property.PlayerData.<init>(PlayerData.java:21)
    [18:15:27 WARN]:        at oriamrm.economy.commands.op.TestCommand.onCommand(TestCommand.java:31)
    [18:15:27 WARN]:        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    [18:15:27 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
    [18:15:27 WARN]:        at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:646)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.PlayerConnection.handleCommand(PlayerConnection.java:1351)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1186)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(PacketPlayInChat.java:45)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.PacketPlayInChat.a(PacketPlayInChat.java:1)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13)
    [18:15:27 WARN]:        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    [18:15:27 WARN]:        at java.util.concurrent.FutureTask.run(Unknown Source)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:733)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:672)
    [18:15:27 WARN]:        at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:571)
    [18:15:27 WARN]:        at java.lang.Thread.run(Unknown Source)
    
    First time everything works properly, but at the second time it just delete all of the player's data and replaces it with the mail.
    Maybe It's something with JavaBeans compatibility (implements java.io.Serializable specifically)? I didn't really get how I'm supposed to do that...

    sorry for my bad English (And perhaps programming skills :))
     
    Last edited: Nov 8, 2016
  2. Offline

    Lolmewn

  3. Offline

    oriamrm

    @Lolmewn
    Works Great! Thanks!


    EDIT: Now everytime I use the sendMal() method it turnes all the values in the list to null and adds the mail. Can it be related to the Mail object?
    Updated Methods:
    Code:
    public List<Mail> getMails(){
            return (List<Mail>) Data.getSecObj(playerName, "Mails");
        }
        public void sendMail(Mail mail){
            List<Mail> mails = getMails();
            mails.add(mail);
            Data.saveObjInSec(playerName, "Mails", mails);
        }
     
    Last edited: Nov 8, 2016
  4. Offline

    Zombie_Striker

    @oriamrm
    Are you sure the Mail objects are serialized/deserialzed correctly? Have you tried seeing if getSecObj is the cause for all null objects? Have you debugged to see which method is causing the null values?
     
  5. Offline

    oriamrm

    Done All Of That, And Figured That I Just Had A Tipo In The New Constructor :)

    Thanks Guys!
     
Thread Status:
Not open for further replies.

Share This Page