ChangeEntityPotionEffectEvent not firing

According to the javadocs, there is an event called ChangeEntityPotionEffectEvent.

I’ve made a listener for it as follows:

    @Listener(order = Order.EARLY)
    public void potionEffectChange(ChangeEntityPotionEffectEvent event) {
        Logger logger = PotionControl.instance.logger;
        Entity target = event.getTargetEntity();"Potion effect event for: " + target.toString());
        if(target instanceof Player) {
            Player player = (Player) target;
            PotionEffect effect = event.getPotionEffect();
  "Effect Type: " + effect.getType());
  "toString: " + effect.toString());
  "Name and ID: " + effect.getType().getName() + ", " + effect.getType().getId());
            player.sendMessage(Text.builder("Effect received: " + effect.toString()).build());

The actions I performed in game that should cause this event to occur:

  • Drink a potion
  • Use a splash potion on myself
  • Use a splash potion on a mob
  • Manually add the effect to myself with a command

However it seems the event never reaches my plugin or these actions do not trigger it. Not even that first logger message is sent to the console.
Here is my main class where I register the event listener. The debug messages here are printed and there are no errors in the middle indicating an issue with my listener.

    public static PotionControl instance;

    public Logger logger;

    public void onServerStart(GameStartedServerEvent event) {"PotionControl is loading...");
        // Register the potion effect event handler
        Sponge.getEventManager().registerListeners(this, new PotionEffectListener());"PotionControl loaded!");

I also tried reacting to the .Gain event and this also did not work, and I also removed the order keyword in the annotation to no avail.

Any help would be appreciated.

Changed the logger to use a get method instead (thinking maybe it just didn’t work like that)
Also tried using a implementing class to handle the event like this:

public class PotionEffectChangeListener implements EventListener<ChangeEntityPotionEffectEvent.Gain> {
    public void handle(ChangeEntityPotionEffectEvent.Gain event) {
        Logger logger = PotionControl.instance.getLogger();
        Entity target = event.getTargetEntity(); + " recieved a potion effect: " + event.getPotionEffect().getType().getName());

and registering it like this:

EventListener<ChangeEntityPotionEffectEvent.Gain> listener = new PotionEffectChangeListener();
Sponge.getEventManager().registerListener(this, ChangeEntityPotionEffectEvent.Gain.class, listener);

but that did not work either.

Your first way is the correct way to register it.

Some events are not implemented as no one has noticed that they arnt implemented. If you report it in spongepowereds github then It should be implemented eventually

1 Like