好的,所以我在存储在文件中并从中重新加载的 HashMap 中使用 Bukkit 的 ItemStack,但我发现 org.bukkit.craftbukkit.v1_4_6.inventory.CraftMetaItem 用于由 ItemStack.serialize( ) 没有实现可序列化。有没有办法解决这个问题?谢谢!
编辑:
这是我的插件中的代码片段。这是引发错误的部分。
public void onEnable(
{
public Map<NewItem, List<ItemStack>> items = new HashMap<NewItem, List<ItemStack>>();
//Add content to items...
}
public void onDisable()
{
try
{
Map<List<Map<String, Object>>, NewItem> smap = new HashMap<List<Map<String, Object>>, NewItem>();
for(NewItem item : items.keySet())
{
List<ItemStack> stacks = items.get(item);
List<Map<String, Object>> stacks2 = new ArrayList<Map<String, Object>>();
for(ItemStack stack : stacks)
{
stacks2.add(stack.serialize());
}
smap.put(stacks2, item);
}
SaveLoadAPI.save(smap, this.getDataFolder().getPath()+"\\Items.data");
}
catch (Exception e)
{
getLogger().severe("Was unable to save the items file to the default path of: "+this.getDataFolder().getPath()+"\\Items.data");
e.printStackTrace();
}
}
最后但肯定最不重要的是,这里是错误!
16:08:52 [SEVERE] java.io.NotSerializableException: org.bukkit.craftbukkit.v1_4_
6.inventory.CraftMetaItem
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeObject0(Unknown Sourc
e)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeObject(Unknown Source
)
16:08:52 [SEVERE] at java.util.HashMap.writeObject(Unknown Source)
16:08:52 [SEVERE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M
ethod)
16:08:52 [SEVERE] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown S
ource)
16:08:52 [SEVERE] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkno
wn Source)
16:08:52 [SEVERE] at java.lang.reflect.Method.invoke(Unknown Source)
16:08:52 [SEVERE] at java.io.ObjectStreamClass.invokeWriteObject(Unknown S
ource)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeSerialData(Unknown So
urce)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeOrdinaryObject(Unknow
n Source)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeObject0(Unknown Sourc
e)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeObject(Unknown Source
)
16:08:52 [SEVERE] at java.util.ArrayList.writeObject(Unknown Source)
16:08:52 [SEVERE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M
ethod)
16:08:52 [SEVERE] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown S
ource)
16:08:52 [SEVERE] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkno
wn Source)
16:08:52 [SEVERE] at java.lang.reflect.Method.invoke(Unknown Source)
16:08:52 [SEVERE] at java.io.ObjectStreamClass.invokeWriteObject(Unknown S
ource)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeSerialData(Unknown So
urce)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeOrdinaryObject(Unknow
n Source)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeObject0(Unknown Sourc
e)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeObject(Unknown Source
)
16:08:52 [SEVERE] at java.util.HashMap.writeObject(Unknown Source)
16:08:52 [SEVERE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M
ethod)
16:08:52 [SEVERE] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown S
ource)
16:08:52 [SEVERE] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkno
wn Source)
16:08:52 [SEVERE] at java.lang.reflect.Method.invoke(Unknown Source)
16:08:52 [SEVERE] at java.io.ObjectStreamClass.invokeWriteObject(Unknown S
ource)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeSerialData(Unknown So
urce)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeOrdinaryObject(Unknow
n Source)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeObject0(Unknown Sourc
e)
16:08:52 [SEVERE] at java.io.ObjectOutputStream.writeObject(Unknown Source
)
16:08:52 [SEVERE] at com.tommy3244.plugins.MakeYourOwnBlocks.SaveLoadAPI.s
ave(SaveLoadAPI.java:16)
16:08:52 [SEVERE] at com.tommy3244.plugins.MakeYourOwnBlocks.MakeYourOwnBl
ocks.onDisable(MakeYourOwnBlocks.java:86)
16:08:52 [SEVERE] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
in.java:219)
16:08:52 [SEVERE] at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin
(JavaPluginLoader.java:481)
16:08:52 [SEVERE] at org.bukkit.plugin.SimplePluginManager.disablePlugin(S
implePluginManager.java:400)
16:08:52 [SEVERE] at org.bukkit.plugin.SimplePluginManager.disablePlugins(
SimplePluginManager.java:393)
16:08:52 [SEVERE] at org.bukkit.plugin.SimplePluginManager.clearPlugins(Si
mplePluginManager.java:434)
16:08:52 [SEVERE] at org.bukkit.craftbukkit.v1_4_6.CraftServer.reload(Craf
tServer.java:563)
16:08:52 [SEVERE] at org.bukkit.Bukkit.reload(Bukkit.java:184)
16:08:52 [SEVERE] at org.bukkit.command.defaults.ReloadCommand.execute(Rel
oadCommand.java:23)
16:08:52 [SEVERE] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
mmandMap.java:186)
16:08:52 [SEVERE] at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchCom
mand(CraftServer.java:514)
16:08:52 [SEVERE] at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchSer
verCommand(CraftServer.java:506)
16:08:52 [SEVERE] at net.minecraft.server.v1_4_6.DedicatedServer.al(Dedica
tedServer.java:260)
16:08:52 [SEVERE] at net.minecraft.server.v1_4_6.DedicatedServer.r(Dedicat
edServer.java:225)
16:08:52 [SEVERE] at net.minecraft.server.v1_4_6.MinecraftServer.q(Minecra
ftServer.java:494)
16:08:52 [SEVERE] at net.minecraft.server.v1_4_6.MinecraftServer.run(Minec
raftServer.java:427)
16:08:52 [SEVERE] at net.minecraft.server.v1_4_6.ThreadServerApplication.r
un(SourceFile:849)