Solved Removing Potion Effects & Armour

Discussion in 'Plugin Development' started by Pink__Slime, Apr 9, 2013.

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

    Pink__Slime

    Ok I know how to remove Inventory items but how do I remove all armour and existing potion effects?
     
  2. Offline

    Jamie Marks

    So to do the potion thing first you want to get the person in your command and check that they are on line

    Code:
    playerTarget = Bukkit.getServer().getPlayer(args[1]);
    replace args[1] with what ever arg your using. oh and set player target to your targeted player.


    then once you have that player,

    you can do something like this to remove all active potion effects.

    Code:
         if (playerTarget != null) {
           for(PotionEffect pe: playerTarget.getActivePotionEffects()) {
             playerTarget.removePotionEffect(pe.getType());
         }
    

    and this can be used to remove a specific effect

    Code:
     if(player.hasPotionEffect(PotionEffectType.INVISIBILITY)&&player.hasPotionEffect(PotionEffectType.SPEED));
    player.removePotionEffect(PotionEffectType.INVISIBILITY);
    player.removePotionEffect(PotionEffectType.SPEED); 

    if you know anything about coding this should be an easy implementation



    hope I helped :p


    -Jamie
     
  3. Offline

    KingFaris10

    Code:
    player.getInventory().setHelmet(null);
    player.getInventory().setChestplate(null);
    player.getInventory().setLeggings(null);
    player.getInventory().setBoots(null);
    
    That's to remove armour. I'm not sure if there's a few errors with where the methods are but it should be fine... I just used my head atm, I can't be bothered to use Eclipse..
     
  4. Offline

    Jamie Marks

  5. Offline

    kreashenz

    Pink__Slime you can use player.getInventory().setArmorContents(null);
     
  6. Offline

    KingFaris10

    Jamie Marks i realised that :p I removed it ;) kreashenz is right. I just typed my way because it's more specific.
     
  7. Offline

    Jamie Marks

    Tagged wrong person there
     
  8. Offline

    kreashenz

    HAHA, my bad :D LOLOL.
     
  9. Offline

    Pink__Slime

    Thank you all :)

    Out of all the code you gave me I only needed a bit but thanks, also I'm new to the whole potions thing.
     
  10. Offline

    Jamie Marks


    No worries hope it helped you out.
     
Thread Status:
Not open for further replies.

Share This Page