Removing all negative potion effects from player

Discussion in 'Plugin Development' started by 5chris100, Mar 29, 2014.

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

    5chris100

    Code: http://hastebin.com/nudiriceni.java

    I made an "onClick(PlayerInteractEvent event)" event where if you click with Lime Dye that is renamed "§aAntidote Crystal" you will be purged of all negative potion effects (via a bunch of "p.removePotionEffect(PotionEffectType.[harm, hunger, poison, etc.]" lines). However, I also want it to say what the player has been removed of. For example, if I have Poison, Speed, and Weakness, and I use an Antidote Crystal, I want it to remove my Poison and Weakness and say to me "Poison and Weakness has been removed!". The code I have so far only removes the first effect it finds, so I need to use it 8 times in order to remove all of the effects I listed. Is there any way I can merge them all together and output only the effects it removes? Thank you. :)
     
  2. Offline

    BeYkeRYkt

    You can use this:

    Code:java
    1. public enum NegativeEffects{
    2. CONFUSION, HARM, HUNGER,POISON, SLOW_DIGGING, SLOW, WEAKNESS, WITHER;
    3. }
    4.  
    5. public void removeAllNegativePotions(Player player){
    6. for(PotionEffect effects: player.getActivePotionEffects()){
    7. for(NegativeEffects bad: NegativeEffects.values()){
    8. if(effects.getType().getName().equalsIgnoreCase(bad.name())){
    9. player.removePotionEffect(effects.getType());
    10. }
    11. }
    12. }
    13. }
     
  3. Offline

    sara4012

    5chris100 This is untested, but try it:
    Code:java
    1. if (p.hasPotionEffect([potionEffectName])){
    2. p.removePotionEffect([potionEffectName]);
    3. p.sendMessage("[potionEffectName] has been removed");
    4. }
     
  4. Offline

    5chris100

    BeYkeRYkt sara4012 Thank you both for your ideas. Sara, I'm going to try yours first as yours looks simpler (no offense, BeYkeRYkt. ;) I'll report back when I test them both. EDIT: Sara's is the same as what I have now. BeYkeRYkt, looks like it's your time to shine. :p
     
Thread Status:
Not open for further replies.

Share This Page