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); } } }
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 if (pi.getHelmet() != null) { 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); }