Solved Objects are sometimes not saving/loading

Discussion in 'Plugin Development' started by vildaberper, Dec 22, 2012.

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

    vildaberper

    When I save objects with:
    Code:
    public static boolean saveObject(Serializable object, File target){
        target.getParentFile().mkdirs();
        if(!(target.exists() && target.isFile()))
            try{
                target.createNewFile();
            }catch (Exception e){
                return false;
            }
        try{
            ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(target)));
     
            oos.writeObject(object);
            oos.flush();
            oos.close();
        }catch(Exception e){
            return false;
        }
        return true;
    }
    or load objects with:
    Code:
    public static Object loadObject(File source){
        Object object = null;
     
        try{
            ObjectInputStream ois = new ObjectInputStream (new BufferedInputStream(new FileInputStream(source)));
     
            object = ois.readObject();
            ois.close();
            return object;
        }catch(Exception e){
            return null;
        }
    }
    it somehow fails sometimes. I always check if the save went well so I don't think thats the problem.
    The only event that triggers a load is PlayerJoinEvent so it should by synced.

    The wierd thing is that it only happens on my host and not when I debug locally. Is there something wrong with the host?
     
  2. Offline

    vildaberper

    The problem was that itemstack.serialize does not implement Serializable if it has any enchantments.
     
Thread Status:
Not open for further replies.

Share This Page