TogAr2 / MinestomPvP

Combat library for Minestom
Apache License 2.0
77 stars 32 forks source link

EntityDamageEvent is always cancelled #3

Closed RealGatt closed 2 years ago

RealGatt commented 2 years ago

Line 134 of the DamageListener.java class will consistently cancel the DamageEvent.


    @Override
    public void setCancelled(boolean cancel) {
        StackFrame frame = StackWalker.getInstance().walk(stream -> stream.skip(1).findFirst().get());
        System.out.println("DamageEvent Cancellation changed by "
                + frame.getFileName() + ":" + frame.getLineNumber() + " to "
                + cancel);
        this.cancelled = cancel;
    }

During testing, I compiled a custom Minestom version that changes the setCancelled function of the EntityDamageEvent to the above code- effectively printing out whenever the value was changed, and by what.

In my own code, I listened to the EntityDamageEvent with a priority of -1 to run this;

System.out.println("Damage event " + event.getDamage() + " Cancelled? " + event.isCancelled()
                    + " Tracker Invuln " + Tracker.invulnerableTime.get(event.getEntity().getUuid())
                    + " Last Dmg " + Tracker.lastDamageTaken.getOrDefault(event.getEntity().getUuid(), -1f) + "");

This gives the following output; (using a Diamond Sword against another player)

Damage event 1.61024 Cancelled? false Tracker Invuln 20 Last Dmg 10.525438

DamageEvent Cancellation changed by DamageListener.java:134 to true

PvP code is started as so, and MinestomPvP is used as an extension, compiled from Jitpack's Maven Repo. Happy to attach anything else that is needed/debug further.

GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
EventNode<EntityEvent> pvpEvents = PvpExtension.events();
globalEventHandler.addChild(pvpEvents);

Feel free to DM on Discord- Gatt#0010

RealGatt commented 2 years ago

As it turns out, it was just an error on my end. I took a look back at your code and noticed that you were already registering the events- which I had not realised that you changed since the prior version. Apologies :)