Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PotionEffect Retrieval Bug #1276

Closed
SjsolisZXA opened this issue Mar 29, 2017 · 7 comments
Closed

PotionEffect Retrieval Bug #1276

SjsolisZXA opened this issue Mar 29, 2017 · 7 comments
Labels
status: pr pending A PR was opened to fix this issue system: data type: bug Something isn't working

Comments

@SjsolisZXA
Copy link

SjsolisZXA commented Mar 29, 2017

Sponge API: 6.0.0-20170323.180311-60
Sponge Forge Build: spongeforge-1.11.2-2227-6.0.0-BETA-2244
Forge Build: forge-1.11.2-13.20.0.2227-universal
Java Version: 1.8.0_121-b13

I've seem to have found a bug, which simon816 has confirmed on the forums, with the with DataSerializable in regards to PotiotionEffects.

Here is the original post:

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 troubleshooting 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;
}

simon816's bug replication code:

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();
}
@stephan-gh stephan-gh added system: data type: bug Something isn't working labels Apr 24, 2017
@BrainStone
Copy link
Contributor

BrainStone commented May 7, 2017

I think I accidentally managed to find the core issue.

When trying to to get a PotionEffect from a DataContainer with this code:

PotionEffect effect = PotionEffect.of(PotionEffectTypes.ABSORPTION, 0, 100);
PotionEffect.builder().build(effect.toContainer());

I get this error:

[17:11:12 ERROR] [STDERR]: org.spongepowered.api.data.persistence.InvalidDataException: Could not deserialize something correctly, likely due to bad type data.
[17:11:12 ERROR] [STDERR]:      at org.spongepowered.api.data.persistence.AbstractDataBuilder.build(AbstractDataBuilder.java:89)
[17:11:12 ERROR] [STDERR]:      at test.code.Main.main(Main.java:2)
[17:11:13 ERROR] [STDERR]: Caused by: org.spongepowered.api.data.persistence.InvalidDataException: The container has an invalid potion type name: effect.absorption
[17:11:13 ERROR] [STDERR]:      at org.spongepowered.common.effect.potion.SpongePotionBuilder.buildContent(SpongePotionBuilder.java:75)
[17:11:13 ERROR] [STDERR]:      at org.spongepowered.api.data.persistence.AbstractDataBuilder.build(AbstractDataBuilder.java:87)
[17:11:13 ERROR] [STDERR]:      ... 2 more

(Stacktrace shortened and simplified)

Not sure what format SpongePotionBuilder expects but it's not effect.absorbtion.

@SjsolisZXA
Copy link
Author

If so, that's great! Thank you for taking the time to test this :D

@BrainStone
Copy link
Contributor

As I said I accidentally stumbled over it. I was trying to bypass the issue that container.getSerializableList(POTION_EFFECTS, PotionEffect.class) did always return Optional.empty() and resorted to getting it as a DataView list and using streams to convert it to PotionEffects. Where I called PotionEffect.builder().build(potionContainer) and it crashed.

@SjsolisZXA
Copy link
Author

Bumping up report.

ImMorpheus added a commit to ImMorpheus/SpongeCommon that referenced this issue Jan 14, 2018
@ryantheleach ryantheleach added the status: pr pending A PR was opened to fix this issue label Jan 26, 2018
ImMorpheus added a commit to ImMorpheus/SpongeCommon that referenced this issue Feb 3, 2018
parlough pushed a commit that referenced this issue Feb 4, 2018
Uses a DataContentUpdater to update the outdated data containers
(Closes #1276)
parlough pushed a commit to parlough/SpongeCommon that referenced this issue Feb 4, 2018
Uses a DataContentUpdater to update the outdated data containers
(Closes SpongePowered#1276)
@BrainStone
Copy link
Contributor

I'd like to point out, that in SF 1.12.2-2586-7.1.0-BETA-2900 the following code still returns Optional.empty()

DataContainer container = DataContainer.createNew(SafetyMode.ALL_DATA_CLONED);
container.set("potions", player.get(Keys.POTION_EFFECTS).orElse(Collections.emptyList()));
container.getSerializableList("potions", PotionEffect.class); // = Optional.empty()

While the container contains all potion data!

@ryantheleach ryantheleach reopened this Feb 11, 2018
@phit phit removed the status: pr pending A PR was opened to fix this issue label Apr 19, 2018
@ImMorpheus
Copy link
Contributor

Updated code:

DataContainer container = DataContainer.createNew(DataView.SafetyMode.ALL_DATA_CLONED);
DataQuery pot = DataQuery.of("PotionType");
container.set(pot, player.get(Keys.POTION_EFFECTS).orElse(Collections.emptyList()));
container.getSerializableList(pot, PotionEffect.class);

@phit phit added the status: pr pending A PR was opened to fix this issue label Jul 2, 2018
@Aaron1011
Copy link
Contributor

Fixed in #1969.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pr pending A PR was opened to fix this issue system: data type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants