SLAPI problem!

Discussion in 'Plugin Development' started by gjosse, Jun 26, 2012.

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

    gjosse

    Hello I am having trouble loading with SLAPI from the wiki!

    This is the error i am getting
    Code:
    22:30:35 [SEVERE] java.io.EOFException
    22:30:35 [SEVERE]      at java.io.ObjectInputStream$PeekInputStream.readFully(UnknownSource)
    22:30:35 [SEVERE]      at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown
    Source)
    22:30:35 [SEVERE]      at java.io.ObjectInputStream.readStreamHeader(Unknown So
    urce)
    22:30:35 [SEVERE]      at java.io.ObjectInputStream.<init>(Unknown Source)
    22:30:35 [SEVERE]      at nl.gjosse.SLAPI.load(SLAPI.java:21)
    22:30:35 [SEVERE]      at nl.gjosse.Tester.onEnable(Tester.java:38)
    Line 21 of SLAPI is
    Code:
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));
    
    Thanks!

    PS, I am trying to save a ArrayList, and that worked!

    This is how i load it:
    Code:
    public void onEnable()
        {
            try {
                chestList = (ArrayList<Location>) SLAPI.load("chestList.dat");
                chestList2 = (ArrayList<Location>) SLAPI.load("chestList2.dat");
               
            } catch (Exception e1) {
                e1.printStackTrace();
            }
    Thanks
    Gjosse
     
  2. java.io.EOFException you are trying to read past the end of file
    because it happends at "ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));" I think its caused by an empty file
     
  3. Offline

    gjosse

    Thanks
    I found out saving did not work eather now i get this error:
    Code:
    22:51:45 [SEVERE] java.io.NotSerializableException: org.bukkit.Location
    22:51:45 [SEVERE]      at java.io.ObjectOutputStream.writeObject0(Unknown Sourc
    e)
    22:51:45 [SEVERE]      at java.io.ObjectOutputStream.writeObject(Unknown Source
    )
    22:51:45 [SEVERE]      at java.util.ArrayList.writeObject(Unknown Source)
    22:51:45 [SEVERE]      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M
    ethod)
    22:51:45 [SEVERE]      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown S
    ource)
    22:51:45 [SEVERE]      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkno
    wn Source)
    22:51:45 [SEVERE]      at java.lang.reflect.Method.invoke(Unknown Source)
    22:51:45 [SEVERE]      at java.io.ObjectStreamClass.invokeWriteObject(Unknown S
    ource)
    22:51:45 [SEVERE]      at java.io.ObjectOutputStream.writeSerialData(Unknown So
    urce)
    22:51:45 [SEVERE]      at java.io.ObjectOutputStream.writeOrdinaryObject(Unknow
    n Source)
    22:51:45 [SEVERE]      at java.io.ObjectOutputStream.writeObject0(Unknown Sourc
    I think its because in the arraylist i use Location witch is not Serializalbe?

    Thanks
    gjosse

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. Yes, location is not serializeable.
    You will have to make a wrapper class for location which only has primitive objects (double, int, etc.) or use YAML.
     
  5. Offline

    gjosse

    How do i wrapper it?

    Thanks
     
  6. Offline

    bitWolfy

    Wrong!

    Well, not QUITE wrong.

    location.toVector() is quite serializable.
     
  7. Offline

    evilmidget38

    If you wanted to save/load a list of locations you could use YAML, it's not that hard. The code below converts them to/from a string, so you could save them a List of Strings.

    Code:
        public Location parseLocation(String location){
            String[] coords = location.split(",");
            if (coords.length < 3){
                throw new IllegalArgumentException("Unable to Parse Location: " + location);
            }
            World world = this.getServer().getWorld(coords[0]);
            if (world == null){
                throw new IllegalArgumentException("Unable to find world: "+ coords[0]);
            }
            double x = Double.parseDouble(coords[1]);
            double y = Double.parseDouble(coords[2]);
            double z = Double.parseDouble(coords[3]);
            return new Location(world, x, y, z);
           
        }
        public String locationToString(Location location){
            StringBuilder s = new StringBuilder();
            s.append(location.getWorld().getName());
            s.append(",");
            s.append(location.getBlockX());
            s.append(",");
            s.append(location.getBlockY());
            s.append(",");
            s.append(location.getBlockZ());
            s.append(",");
            return s.toString();
        }
     
  8. Offline

    bitWolfy

    OR you could...

    To save:
    Code:
    this.getConfig().set("some.path.world", loc.getWorld().getName());
    this.getConfig().set("some.path.coord", loc.toVector());
    To retrieve:
    Code:
    World world = Bukkit.getServer().getWorld(this.getConfig.getString("some.path.world"));
    Location loc = this.getConfig.getVector("some.path.coord").toLocation(world);
    I did not test the code above, but it should work.
     
  9. Offline

    evilmidget38

    Oh, if there's a getVector, then that's probably an easier method. I didn't realize there was one.
     
Thread Status:
Not open for further replies.

Share This Page