IronMan

Discussion in 'Plugin Development' started by King_Amun_Ra, Apr 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    King_Amun_Ra

    I'm making a iron man plugin and I'm having some trouble with potion effects. Its only giving me the chestplate potion effect and also its not removing any of the effects.


    Code:
    @EventHandler
        public void onPlayerMoveEvent(PlayerMoveEvent e){
           
            String uuid = e.getPlayer().getUniqueId().toString();
            Player p = e.getPlayer();
            PlayerInventory pi = (PlayerInventory) p.getInventory();
           
           
            //If the have helmet
            if (helmet.contains(uuid)){
               
                if (pi.getHelmet().getType() == Material.LEATHER_HELMET){
                    p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 100 * 20, 0));
                }else{
                    // If they take the helmet off
                   
                    p.removePotionEffect(PotionEffectType.NIGHT_VISION);
                   
                }
               
            }
           
            //If the have chest
            if (chest.add(uuid)){
               
                if (pi.getChestplate().getType() == Material.LEATHER_CHESTPLATE){
                    p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 100 * 20, 0));
                    p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100 * 20, 0));
                }else{
                    // If they take the helmet off
                   
                    p.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
                    p.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
                   
                }
               
            }
           
            //If they have leggs
            if (legs.contains(uuid)){
                if (pi.getLeggings().getType() == Material.LEATHER_LEGGINGS){
                    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100 * 20, 1));
                }else{
                    // If they take the helmet off
                   
                    p.removePotionEffect(PotionEffectType.SPEED);
                   
                }
            }
           
           
            //If they have boots
            if (boots.contains(uuid)){
                if (pi.getBoots().getType() == Material.LEATHER_BOOTS){
                    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 100 * 20, 2));
                }else{
                    // If they take the helmet off
                   
                    p.removePotionEffect(PotionEffectType.JUMP);
                   
                }
            }
           
           
           
        }
     
  2. Offline

    2MBKindiegames

    Hi there,
    If the Armor is empty, it trows 'NullPointerExceptions'. IT WOULD BE HELPFULL IF YOU'D PUT THAT IN THE TOPIC!

    I changed the code a bit, so now it works. Just remodel it like this:
    Code:java
    1. if (pi.getHelmet() != null) {
    2. if (pi.getHelmet().getType() == Material.LEATHER_HELMET){
    3. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 100 * 20, 0));
    4. }
    5. } else {
    6. // If they take the helmet off
    7. p.removePotionEffect(PotionEffectType.NIGHT_VISION);
    8. }
     
Thread Status:
Not open for further replies.

Share This Page