Help. Remove a potion effect from a player.

Discussion in 'Plugin Development' started by Laserhog, Jan 25, 2012.

Thread Status:
Not open for further replies.
  1. I need help with removing a potion effect from a player.
    I found some code in another topic that looked like it would work, but didn't.
    Where the effectIDs were listed here.

    Any help is much appreciated.
    kahlilnc likes this.
  2. Code:java
    1. EntityPlayer ep=((CraftPlayer)player).getHandle();
    2. ep.netServerHandler.sendPacket(new Packet42RemoveMobEffect(,effect);

    This should work, but make sure you pass an effect to the constructor of Packet42RemoveMobEffect instead of the ID. Also if you don't know the imports:

    import net.minecraft.server.EntityPlayer;

    import net.minecraft.server.Packet42RemoveMobEffect;

    I hope this helps you! :)
    kahlilnc likes this.
  3. Thank you so much. However im not sure what the "effect" should be if its not the ID. Could you possibly give me an example of this? ie. the poison effect or the speed effect.

    EDIT: Actually i think i may have figured it out. So for poison it would be
    ep.netServerHandler.sendPacket(new Packet42RemoveMobEffect(,new MobEffect(19,0,0)));
    ANOTHER EDIT: Never mind,"new MobEffect(19,0,0)" didn't work....
  4. To remove an effect, you need to do three things:
    1. Remove the effect from the entity
    2. If it's a player, tell the player they no longer have the effect
    3. Remove the graphical particle effect

    This is what I currently use:
        public static void removeMobEffect(LivingEntity entity, int type) {
            try {
                // remove effect
                Field field = EntityLiving.class.getDeclaredField("effects");
                HashMap effects = (HashMap)field.get(((CraftLivingEntity)entity).getHandle());
                // alert player that effect is gone
                if (entity instanceof Player) {
                    EntityPlayer player = ((CraftPlayer)entity).getHandle();
                    player.netServerHandler.sendPacket(new Packet42RemoveMobEffect(, new MobEffect(type, 0, 0)));
                // remove graphical effect
                ((CraftLivingEntity)entity).getHandle().getDataWatcher().watch(8, Integer.valueOf(0));
            } catch (Exception e) {
  5. Thanks, but not sure what "type" should be. Is it possibly the effect ID? So poison would be 19? And replacing "type" with 19 would remove the poison effect?
  6. Correct.
  7. Works like a charm, cheers.
  8. You said you remove the particles with this line. I tried that but it doesn't work.
    Could please explain what you did in this line?
    And is it possible to remove the particle effect without removing the mobeffect?
  9. Offline


    Yes, it is possible to remove the particle and keep the effect.
  10. Ok but I still don't understand this line and how to get it working. Or do I need to use something else?
  11. It sets a specific data watcher value to 0.
  12. Ok now I got it. But it doesn't work still :
    cp.getHandle().addEffect(new MobEffect(2, 200, 5));
                            cp.getHandle().getDataWatcher().watch(8, Integer.valueOf(0));
  13. Sorry, I don't know why that is. You'll have to do some research on your own. When you choose to access server code directly like this, you have to accept the fact that sometimes you'll have to start digging through that code to see what's going on.
  14. What is "Field" ? Where do i import from?
  15. Why not just use
Thread Status:
Not open for further replies.

Share This Page