Magic defense
Blamo27 opened this issue ยท 26 comments
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 :/
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.
it's when a player equip his armor again
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 :(
I get this, with a magic missile
I'm not sure what you mean- equipping armor is triggering a damage event?
Yes
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.
Citizens, Essentials, PermissionsEx, TimeLock, EssentialsSpawn, WorldGuard, WorldEdit, Sentry, Lores, HolographicDisplays and my plugins :/
@NathanWolf Sorry the event was handled twice
Thanks for your help
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?
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.
That part is trickier, there is not an API way but there is a hacky way- check CompatilbilityUtils.isDamaging
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.
Is it a good way to check if the Caster have a wand in his hand ?
Instead of use the hacky way
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.
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)
Okey, so I'll not check if a player is holding a wand.
But I don't understood, how to use CompatilbilityUtils.isDamaging ?
if (CompatibilityUtils.isDamaging) { .. this damage came from a Magic spell ... }
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.