GC-spigot / AdvancedEnchantments

Superior Custom Enchantments Creator for Minecraft And Spigot platform
141 stars 61 forks source link

[API] EffetcsActivate returns wrong LivingEntity #4252

Closed timderspieler closed 1 month ago

timderspieler commented 2 months ago

Describe the bug

Following the advice mentioned in following issue on github: https://github.com/GC-spigot/AdvancedEnchantments/issues/4184 I've switched from the EnchantActivateEvent to the EffectsActivateEvent.

While testing the new code, I noticed that event.getMainEntity() and event.getOtherEntity() both return the same LivingEntity object.

The expected behaviour would be that event.getMainEntity() returns the object of the LivingEntity that holds the enchanted item / activated the effect and event.getOtherEntity() returns the object of the LivingEntity that the effect gets activated on (target).

How to reproduce

Enchant a weapon with e.g the poison enchantment. Hit another player. The LivingEntity event.getMainEntity() will return the attacker, event.getOtherEntity() will also return the attacker.

Following code:

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onEffectsActivate(EffectsActivateEvent e) {
        LivingEntity mainEntity = e.getMainEntity();
        LivingEntity otherEntity = e.getOtherEntity();
        List<LivingEntity> otherTargets = e.getOtherTargets();

        Bukkit.broadcastMessage("EffectsActivateEvent: %s activated an effect on %s with %s other targets"
                .formatted(mainEntity.getName(), otherEntity.getName(), otherTargets.size()));
    }

will print out the message seen in the screenshots section.

Screenshots / Videos

grafik

"/ae plinfo" link

Not needed.

Server Log

No response

ThomasWega commented 2 months ago

it depends on what effect you are listening to. Debug and see what effect this was for. Having both main and other entity the same could be valid in a lot of cases

timderspieler commented 2 months ago

@ThomasWega as mentioned this was tested with the poison enchantment.

ThomasWega commented 1 month ago

Now, this might be super confusing that it even got me, but I don't think it's actually a bug. You can get the entities with getAttacker and getVictim as well. That should work just fine for most cases. I'd like to fix this and make it cleaner, but that would break compatibility, which we want to avoid unless really necessary. Hopefully this answer is enough for you