Hit Potion Effects

Discussion in 'Plugin Development' started by Xocky, May 12, 2018.

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

    Xocky

    How to disable the potion effect on hit of a mob like when a cave spider hits you get poison i want to disable that
     
  2. Offline

    KarimAKL

    @Xocky I don't know if there is an easier and better way of doing this but maybe checking if the player was hit by a cave spider then wait a little(so that the player has the effect) and then check if the player has the potion effect and if the player does have it maybe remove it, not sure if it would work but it's just an idea i got, you could also try checking if the player got hit by a cave spider then cancel the event and damage the player(then the player would take damage without getting the effect from being hit by the cave spider)
    These were 2 ideas i got, i don't know if they would even work and i'm new to this so i can't help you any further, sorry.
     
  3. Offline

    MightyOne

    I would create a BukkitRunnable executed a tick after the the damage event. In there I would check if the player has the poison effect and then remove it. Do you know how to listen to the EnrityDamageByEntityEvent and how to create a BukkitRunnable?
     
  4. Offline

    KarimAKL

    @MightyOne But wouldn't that remove it if the player has the poison effect before the spider?
     
  5. Offline

    MightyOne

    @KarimAKL the also check if the player has the poison effect when the event fires. Or even save it's duration and compare it a tick later.

    xoq ǝɥʇ ǝpᴉsʇno ʞuᴉɥʇ
     
  6. Offline

    KarimAKL

    @MightyOne I don't know how i would save the duration and compare it later but thank you for the tips. :p Also did you copy and paste that "think outside the box" text? :p
     
  7. Offline

    MightyOne

    idk if I am allowed to promote websites here. There are many updside-down-text sites on the Internet. http://www.upsidedowntext.com/

    Code:
    PotionEffect effect;
    
    if(p.hasPotionEffect(PotionEffectType.POISON))
        effect = p.getPotionEffect(PotionEffectType.POISON);
    
    BukkitRunnable runnable = new BukkitRunnable() {
        @Override
        public void run() {
    
            if(p.hasPotionEffect(PotionEffectType.POISON)) {
                PotionEffect effect2 = p.getPotionEffect(PotionEffectType.POISON);
            
                if(effect != null && effect.getDuration() > effect2.getDuration())
                    return;
    
                p.removePotionEffect(PotionEffectType.POISON);
                p.addPotionEffect(effect);
            }
        }
    };
    
    runnable.runTask(*insert javaplugin reference*);
    ok i know spoon feeding is barbaric but I think I struggled with potion effects a lot and I'd have prefered someone feeding me like this xD If anybody wants so I will remove it
     
    Last edited: May 17, 2018
  8. Offline

    KarimAKL

Thread Status:
Not open for further replies.

Share This Page