Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now firing events before changing durability #5071

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Mowstyl
Copy link

@Mowstyl Mowstyl commented Aug 16, 2024

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.

Copy link
Member

@nossr50 nossr50 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this experience orb stuff about? I don't get it.
Doesn't seem related to your PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you for the explanation, I will think on that some more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants