Magic

Magic

190k Downloads

Magic defense

Blamo27 opened this issue ยท 26 comments

commented

Hello : )

I want to know how I should create an event which decrease damage.
CastEvent cannot get the TargetEntity :

@eventhandler
public void cast(CastEvent event) {

    Bukkit.broadcastMessage(""+event.getSpellResult());

    if (event.getSpellResult().toString() == "CAST" ) {

        event.getSpell().getTargetEntity(); // Doesn't work
        Bukkit.broadcastMessage("getSpellResult() ==> CAST");

    }
   }

And use EntityDamageByEntityEvent event is buggy :/

commented

So the damage are negative sometimes :/

event.getDamage()

commented

Is there any chance you have some plugins doing weird stuff with damage? I don't think that should ever be true, damage events don't fire for healing as far as I know.

commented

it's when a player equip his armor again

http://pastebin.com/sCqg76fF

commented

I'm not sure what you mean- equipping armor is triggering a damage event? And that first debug print prints a negative number?

None of that makes much sense to me, sorry :(

commented

commented

I get this, with a magic missile

I'm not sure what you mean- equipping armor is triggering a damage event?
Yes

commented

Can you reproduce this with no other plugins present?

I honestly don't know, feels like it has to be something like mcmmo or some other damage-preventing type of plugin.

commented

Citizens, Essentials, PermissionsEx, TimeLock, EssentialsSpawn, WorldGuard, WorldEdit, Sentry, Lores, HolographicDisplays and my plugins :/

commented

@NathanWolf Sorry the event was handled twice
Thanks for your help

commented

The vanilla damage events are the only way to do this, Magic doesn't fire any special events on damage since it is already handled by Spigot.

How is it buggy?

commented

The event.getDamage() is very low (E-5) with the EntityDamageByEntityEvent

commented

That seems very strange to me.. if that were true I think a lot of plugins would break, including Magic's own damage protection.

I would suggest maybe adding some more logging- what type of entities are being damaged and what type of damage would all be very interesting to know.

commented

How I can detect if the player has been targeted by a spell ?

commented

Yes, I will

commented

That part is trickier, there is not an API way but there is a hacky way- check CompatilbilityUtils.isDamaging

https://github.com/elBukkit/MagicPlugin/blob/master/Magic/src/main/java/com/elmakers/mine/bukkit/utility/CompatibilityUtils.java#L82

Magic sets that static variable while it is damaging entities. This is used internally because the damage event will actually trigger a spell cast (when you whack something with a wand), and we need to prevent infinite recursion on damaging spells.

commented

Is it a good way to check if the Caster have a wand in his hand ?
Instead of use the hacky way

commented

That could maybe work, but I can think of some exceptions- like casting with a wand in the alt-hand, or throwing a potion with the alt-hand, thorns armor... there are probably more.

commented

I'm still on 1.8.9

commented

Then thorns are maybe your only concern :)

commented

Why thorns ?

commented

If you're wearing thorns armor and an entity hits you, they take damage. If you're just checking for player holding a wand, you'll count thorns damage as damage from the wand.

You can just check the damage type to skip that case... thoughhhhh for weird reasons wands apply thorns damage to the ender dragon (it won't take damage otherwise, bug in Spigot/MC)

commented

Okey, so I'll not check if a player is holding a wand.
But I don't understood, how to use CompatilbilityUtils.isDamaging ?

commented

if (CompatibilityUtils.isDamaging) { .. this damage came from a Magic spell ... }

commented

How to import CompatibilityUtils ?

commented

You'll need to build against the Magic jar. Easy with Maven:

https://github.com/elBukkit/MagicPlugin/blob/master/Magic/pom.xml#L6

Otherwise just add Magic.jar to your build path.

commented

Yes, thanks .. ^^'