Serialize Vector3d/i in own class

Hello
I have the problem that I cannot serialize Objects of type Vector3d and Vector3i. I have a Object(Area.java)
which holds multiple chunks(Vector3i) and several locations (Vector3d). For these two I wrote serializer but I don’t know how to use them in the AreaSerializer. I know it would work if I would break them down to Double with the coordinates, but I think there is a clean way to do it which I don’t see. I could use some advise from you and maybe some code examples.

Thanks for your time
Regards
Randalf

Sponge Build: 1.12.1-2480-7.0.0-BETA-2643
Java Version: 1.8.0_111

Error

[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: java.lang.IllegalArgumentException: Configuration does not accept objects of type class com.flowpowered.math.vector.Vector3d
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at ninja.leaping.configurate.ScalarConfigValue.setValue(ScalarConfigValue.java:42)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at ninja.leaping.configurate.SimpleConfigurationNode.insertNewValue(SimpleConfigurationNode.java:274)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at ninja.leaping.configurate.SimpleConfigurationNode.setValue(SimpleConfigurationNode.java:201)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode.setValue(SimpleCommentedConfigurationNode.java:74)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode.setValue(SimpleCommentedConfigurationNode.java:32)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at io.github.randalf.project.serializer.AreaSerializer.serialize(AreaSerializer.java:25)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at io.github.randalf.project.manager.AreaConfigurationManager.save(AreaConfigurationManager.java:35)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at io.github.randalf.project.manager.AreaManager.createArea(AreaManager.java:49)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at io.github.randalf.project.commands.AreaCreateCommand.execute(AreaCreateCommand.java:22)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at org.spongepowered.api.command.spec.CommandSpec.process(CommandSpec.java:360)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at org.spongepowered.api.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:342)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at org.spongepowered.common.command.SpongeCommandManager.process(SpongeCommandManager.java:326)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:1083)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:950)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:929)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:37)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:9)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at org.spongepowered.common.network.PacketUtil.lambda$onProcessPacket$0(PacketUtil.java:149)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at org.spongepowered.common.event.tracking.CauseTracker.switchToPhase(CauseTracker.java:162)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at org.spongepowered.common.network.PacketUtil.onProcessPacket(PacketUtil.java:148)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$zkb000(SourceFile:539)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.util.Util.func_181617_a(SourceFile:46)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at org.spongepowered.common.SpongeImplHooks.onUtilRunTask(SpongeImplHooks.java:274)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.server.MinecraftServer.redirect$onRun$zid000(MinecraftServer.java:4013)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:721)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:396)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:666)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524)
[18:48:06] [Server thread/INFO] [STDERR]: [io.github.randalf.project.manager.AreaConfigurationManager:save:38]: at java.lang.Thread.run(Thread.java:745)

Plugin Source:

You have to include TypeTokens when setting the values.

1 Like