Now firing events before changing durability#5071
Now firing events before changing durability#5071Mowstyl wants to merge 3 commits intomcMMO-Dev:masterfrom
Conversation
nossr50
left a comment
There was a problem hiding this comment.
I left some feedback, reply to it when you get a chance.
| } | ||
| } else if (damage < 0) { // Repaired item | ||
| damage = -damage; | ||
| ExperienceOrb auxOrb = (ExperienceOrb) player.getWorld().spawnEntity(player.getLocation(), EntityType.EXPERIENCE_ORB); |
There was a problem hiding this comment.
What's this experience orb stuff about? I don't get it.
Doesn't seem related to your PR.
There was a problem hiding this comment.
If the damage is negative, that means the item has been repaired. The PlayerItemMendEvent has an ExperienceOrb as an argument, so I needed to spawn one with the quantity of xp needed to repair the item for the specified amount if you had the mending enchantment. After the event has been called, the xp orb has to be despawned so no one can pick it up.
After your review I noticed I forgot to call the event, I just instantiate it and check if it has been canceled.
There was a problem hiding this comment.
I thought it would be better to call the mend event instead of the damage event when repairing an item, yet I think everything would also work with a damage event. I just did that for the sake of semantics.
There was a problem hiding this comment.
I see, thank you for the explanation, I will think on that some more.
By calling the PlayerItem(Damage|Mend)Event before setting the durability, plugins that handle the durability of items themselves (like any custom items plugin) won't break.