[Solved] PotionEffect Retrieval Issue

Sponge Build: 1.11.2-2227-6.0.0-BETA-2224
Forge Build: forge-1.11.2-13.20.0.2227-universal
**Java Version:**1.8.0_121-b13

I have the following code, which saves a player’s potion effects:

public static void saveOriginalPotionEffects(List<PotionEffect> potionEffects, String arenaName, String userName) throws ObjectMappingException {

	int i = 1;
	
	for(PotionEffect potionEffect: potionEffects){
		
		UnversalConfigs.getConfig(ArenaConfig).getNode("Arena", arenaName, "Contestants", userName, "Potion Effects","Effect "+i).setValue(TypeToken.of(PotionEffect.class),potionEffect);
		
		UnversalConfigs.saveConfig(ArenaConfig);
		
		i++;
	}
}

I have no issue with the code above, but when I try to retrieve the data with the code below, I receive a Could not translate DataSerializable of type: org.spongepowered.api.effect.potion.PotionEffect error. This might be a programmer end error, but I coudn’t get any further after troubleshoting the issue to line PotionEffect potionEffect = node.getNode("Effect "+i).getValue(TypeToken.of(PotionEffect.class)); Any help would be greatly appreciated. Thanks!

public static List<PotionEffect> fetchOriginalPotionEffects(String arenaName, String userName) throws ObjectMappingException{
	
	List<PotionEffect> potionEffects = Lists.newArrayList();
	
	CommentedConfigurationNode node = UnversalConfigs.getConfig(ArenaConfig).getNode("Arena", arenaName, "Contestants", userName, "Potion Effects");
	
	int NOPE = getNumOfPotionEffects(arenaName,userName);
	
	for(int i = 1; i<= NOPE;i++){
		
		PotionEffect potionEffect = node.getNode("Effect "+i).getValue(TypeToken.of(PotionEffect.class));
		
		potionEffects.add(potionEffect);

	}
	
	return potionEffects;
}

You should post the full stack trace you get

1 Like

[details=Log Details][17:39:00] [Server thread/INFO]: [STDERR]: ninja.leaping.configurate.objectmapping.ObjectMappingException: Could not translate DataSerializable of type: org.spongepowered.api.effect.potion.PotionEffect [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.common.config.DataSerializableTypeSerializer.lambda$deserialize$0(DataSerializableTypeSerializer.java:51) [17:39:00] [Server thread/INFO]: [STDERR]: at java.util.Optional.orElseThrow(Unknown Source) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.common.config.DataSerializableTypeSerializer.deserialize(DataSerializableTypeSerializer.java:51) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.common.config.DataSerializableTypeSerializer.deserialize(DataSerializableTypeSerializer.java:41) [17:39:00] [Server thread/INFO]: [STDERR]: at ninja.leaping.configurate.SimpleConfigurationNode.getValue(SimpleConfigurationNode.java:226) [17:39:00] [Server thread/INFO]: [STDERR]: at ninja.leaping.configurate.ConfigurationNode.getValue(ConfigurationNode.java:356) [17:39:00] [Server thread/INFO]: [STDERR]: at ConfigUtils.ContestantConfigUtils.fetchOriginalPotionEffects(ContestantConfigUtils.java:219) [17:39:00] [Server thread/INFO]: [STDERR]: at Executors.LeaveArena.execute(LeaveArena.java:65) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.api.command.args.ChildCommandElementExecutor.execute(ChildCommandElementExecutor.java:182) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.api.command.spec.CommandSpec.process(CommandSpec.java:359) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.api.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:336) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.common.command.SpongeCommandManager.process(SpongeCommandManager.java:295) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:1083) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:904) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:883) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:37) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:9) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.common.network.PacketUtil.lambda$onProcessPacket$0(PacketUtil.java:154) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.common.event.tracking.CauseTracker.switchToPhase(CauseTracker.java:156) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.common.network.PacketUtil.onProcessPacket(PacketUtil.java:153) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$zjh000(SourceFile:539) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) [17:39:00] [Server thread/INFO]: [STDERR]: at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [17:39:00] [Server thread/INFO]: [STDERR]: at java.util.concurrent.FutureTask.run(Unknown Source) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.util.Util.func_181617_a(SourceFile:46) [17:39:00] [Server thread/INFO]: [STDERR]: at org.spongepowered.common.SpongeImplHooks.onUtilRunTask(SpongeImplHooks.java:249) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.server.MinecraftServer.redirect$onRun$zhh000(MinecraftServer.java:3952) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:679) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:384) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:624) [17:39:00] [Server thread/INFO]: [STDERR]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [17:39:00] [Server thread/INFO]: [STDERR]: at java.lang.Thread.run(Unknown Source)[/details]

I can confirm there is an issue with deserializing a PotionEffect
The following code triggers the same exception that has been posted above

try {
    PotionEffect effect = PotionEffect.of(PotionEffectTypes.JUMP_BOOST, 1, 10);
    SimpleCommentedConfigurationNode node = SimpleCommentedConfigurationNode.root();
    node.getNode("test").setValue(TypeToken.of(PotionEffect.class), effect);
    PotionEffect effect2 = node.getNode("test").getValue(TypeToken.of(PotionEffect.class));
} catch (ObjectMappingException e) {
    e.printStackTrace();
}

I suggest you post an issue report on the SpongeCommon github https://github.com/SpongePowered/SpongeCommon/issues/new

1 Like

Thank you for taking the time to test this issue! I’ve submitted the report :slight_smile: