Solved Potion Effect Amplifier does not work from variable

Discussion in 'Plugin Development' started by TGamingStudio, Aug 4, 2019.

  1. Offline

    TGamingStudio

    Hello, Im trying to create armour which will give player potion effects. If player has more armour parts, I want the Amplifier to be higher.
    So i created map for each effect. HashMap<PotionEffectType, Integer>

    Code:
    p.addPotionEffect( new PotionEffect(PotionEffectType.FAST_DIGGING, 40, (int) level.get(PotionEffectType.FAST_DIGGING)));

    Returns Haste 0 (1 Ingame)

    Code:
    p.addPotionEffect( new PotionEffect(PotionEffectType.FAST_DIGGING, 40, 1);
    Returns Haste 1 (2 Ingame)

    Whole code :

    Code (open)

    Code:
    HashMap<PotionEffectType, Integer> level = new HashMap<PotionEffectType, Integer>();
                        for(ItemStack item : items) {
                            if(item.getItemMeta() != null) {
                                if(item.getItemMeta().getLore() != null) {
                                    List<String> lore = item.getItemMeta().getLore();
                                    for(String l : lore) {
                                        if(l.equals("haste")) {
                                            if(level.get(PotionEffectType.FAST_DIGGING) == null) {
                                                level.put(PotionEffectType.FAST_DIGGING, 0);
                                            }else {                                           
                                                level.put(PotionEffectType.FAST_DIGGING, level.get(PotionEffectType.FAST_DIGGING) + 1);
                                            }
                                            p.addPotionEffect( new PotionEffect(PotionEffectType.FAST_DIGGING, 40, (int) level.get(PotionEffectType.FAST_DIGGING)));
                                        }
                                    }
                                }
                            }
                        }
     
  2. Offline

    Kars

    So what's your question?
     
  3. Offline

    The_Xman249

    If the question is 'Why isn't this amplifying my hast in game, if i have more armour on' , the answer would be:

    You are setting the potion effect on the lore loop, not after the item loop finishes.

    If the question is 'Why isn't this amplifying my hast in game, if i have more 'hast' in my lore ', the answer would be:

    You are setting the potion effect on the lore loop , not after the lore loop finishes.

    Hope this fixes the issue , if you haven't already fixed it.
     
    TGamingStudio likes this.

Share This Page