SLAPI and HashMaps throwing exceptions

Discussion in 'Plugin Development' started by billofbong, Dec 31, 2011.

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

    billofbong

    Hai,

    I have been working on a plugin that lets you adopt and abandon (:)) people, but when I try to reload the server with something stored in the HashMap, I get this exception:
    Code:
    18:52:52 [SEVERE] java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.bukkit.craftbukkit.entity.CraftPlayer
    18:52:52 [SEVERE]     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1332)
    18:52:52 [SEVERE]     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    18:52:52 [SEVERE]     at java.util.HashMap.readObject(HashMap.java:1029)
    18:52:52 [SEVERE]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    18:52:52 [SEVERE]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    18:52:52 [SEVERE]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    18:52:52 [SEVERE]     at java.lang.reflect.Method.invoke(Method.java:597)
    18:52:52 [SEVERE]     at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
    18:52:52 [SEVERE]     at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
    18:52:52 [SEVERE]     at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    18:52:52 [SEVERE]     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    18:52:52 [SEVERE]     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    18:52:52 [SEVERE]     at org.awesomecraft.plugins.orphanage.SLAPI.load(SLAPI.java:24)
    18:52:52 [SEVERE]     at org.awesomecraft.plugins.orphanage.Orphanage.onEnable(Orphanage.java:126)
    18:52:52 [SEVERE]     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:188)
    18:52:52 [SEVERE]     at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:968)
    18:52:52 [SEVERE]     at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
    18:52:52 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:186)
    18:52:52 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:169)
    18:52:52 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:436)
    18:52:52 [SEVERE]     at org.bukkit.Bukkit.reload(Bukkit.java:187)
    18:52:52 [SEVERE]     at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
    18:52:52 [SEVERE]     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:165)
    18:52:52 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:378)
    18:52:52 [SEVERE]     at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:757)
    18:52:52 [SEVERE]     at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:722)
    18:52:52 [SEVERE]     at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:715)
    18:52:52 [SEVERE]     at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:33)
    18:52:52 [SEVERE]     at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
    18:52:52 [SEVERE]     at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:93)
    18:52:52 [SEVERE]     at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
    18:52:52 [SEVERE]     at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:527)
    18:52:52 [SEVERE]     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
    18:52:52 [SEVERE]     at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    18:52:52 [SEVERE] Caused by: java.io.NotSerializableException: org.bukkit.craftbukkit.entity.CraftPlayer
    18:52:52 [SEVERE]     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
    18:52:52 [SEVERE]     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
    18:52:52 [SEVERE]     at java.util.HashMap.writeObject(HashMap.java:1000)
    18:52:52 [SEVERE]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    18:52:52 [SEVERE]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    18:52:52 [SEVERE]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    18:52:52 [SEVERE]     at java.lang.reflect.Method.invoke(Method.java:597)
    18:52:52 [SEVERE]     at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
    18:52:52 [SEVERE]     at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1469)
    18:52:52 [SEVERE]     at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
    18:52:52 [SEVERE]     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
    18:52:52 [SEVERE]     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
    18:52:52 [SEVERE]     at org.awesomecraft.plugins.orphanage.SLAPI.save(SLAPI.java:17)
    18:52:52 [SEVERE]     at org.awesomecraft.plugins.orphanage.Orphanage.onDisable(Orphanage.java:26)
    18:52:52 [SEVERE]     at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:190)
    18:52:52 [SEVERE]     at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:989)
    18:52:52 [SEVERE]     at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:296)
    18:52:52 [SEVERE]     at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:289)
    18:52:52 [SEVERE]     at org.bukkit.plugin.SimplePluginManager.clearPlugins(SimplePluginManager.java:317)
    18:52:52 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:407)
    18:52:52 [SEVERE]     ... 14 more
    
    I am using SLAPI.
    You can find my code at https://github.com/billofbong/Orphanage/tree/master/src/main/java/org/awesomecraft/plugins/orphanage.

    Many thanks,

    billofbong :D
     
  2. Offline

    Pandemoneus

    You are trying to save a HashMap that uses the Player object, which is not serializable (same as many other Bukkit objects). You should be saving the player's name instead.
     
  3. Offline

    billofbong

    I see... Thanks.
     
Thread Status:
Not open for further replies.

Share This Page