java.lang.ClassCastException: java.lang.String cannot be cast to org.spongepowered.api.effect.potion.PotionEffect


#1

Hello, I can not apply a potion:

                 List<PotionEffect> potions = null;

                    try {
                        potions = conf.getConfig().getNode("conf", "MagicShield", "Armor", "Helmet").getValue(new TypeToken<List<PotionEffect>>() {});
                    } catch (ObjectMappingException e) {
                        e.printStackTrace();
                    }

                    if(potions != null) {

                        if(!player.get(Keys.POTION_EFFECTS).isPresent()) {
                            player.offer(Keys.POTION_EFFECTS, potions);
                        }
                    }

En conf:
[{ContentVersion=2, PotionType=minecraft:night_vision, Duration=6000, Amplifier=0, Ambiance=false, ShowsParticles=false}, {ContentVersion=2, PotionType=minecraft:water_breathing, Duration=6000, Amplifier=0, Ambiance=false, ShowsParticles=false}]


#2

Sadly you can not just create a new instance of TypeToken. Thankfully Sponge has got your back.

.getValue(TypeTokens.LIST_POTION_TOKEN):

Also make sure your saving the value with the same TypeTokens.


#3

thank you!!! thank you!!! thank you!!!