EntityPotionEffectEvent doesn't get cancelled

llllll0zym

New member
Nov 18, 2023
1
0
1
Java:
public class EffectRemover implements Listener {
    @EventHandler(priority = EventPriority.HIGHEST)
    public void onEffect(EntityPotionEffectEvent event) {
        if (event.getAction() != EntityPotionEffectEvent.Action.ADDED) return;
        if (!(event.getEntity() instanceof Player player)) return;

        Bukkit.getConsoleSender().sendMessage("NewEffect: " + Objects.requireNonNull(event.getNewEffect()));
        Bukkit.getConsoleSender().sendMessage("NewEffect().getType():  " + Objects.requireNonNull(event.getNewEffect().getType()));

        if (event.getNewEffect().getType() == PotionEffectType.DAMAGE_RESISTANCE
                //&& event.getNewEffect().getAmplifier() <= 3
        ) {
            event.setCancelled(true);
            Bukkit.getConsoleSender().sendMessage("Cancelled event");
        } else Bukkit.getConsoleSender().sendMessage("Failed to cancel event"); //<--- we always arrive here

        if ((Objects.requireNonNull(event.getNewEffect().getType()) == PotionEffectType.DAMAGE_RESISTANCE)
          && (Objects.requireNonNull(event.getNewEffect()).getAmplifier() <= 3)
         ) {
            player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
            player.removePotionEffect(PotionEffectType.SLOW);
            event.setCancelled(true);

            Bukkit.getConsoleSender().sendMessage(player + " tried drinking Turtle Master potion");
            } else {Bukkit.getConsoleSender().sendMessage("Conditions failed for some reason");} //<--- and here
    }
}
 
Logs
https://paste.gg/p/anonymous/2ed93380326242909e3ebf10e251fdc5
Version Output
Paper version git-Paper-292 (MC: 1.20.2) (Implementing API version 1.20.2-R0.1-SNAPSHOT) (Git: 0a8c873)