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();
logger.info("Potion effect event for: " + target.toString());
if(target instanceof Player) {
Player player = (Player) target;
PotionEffect effect = event.getPotionEffect();
logger.info("Effect Type: " + effect.getType());
logger.info("toString: " + effect.toString());
logger.info("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;
@Inject
public Logger logger;
@Listener
public void onServerStart(GameStartedServerEvent event) {
logger.info("PotionControl is loading...");
// Register the potion effect event handler
Sponge.getEventManager().registerListeners(this, new PotionEffectListener());
logger.info("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.