Paper icon indicating copy to clipboard operation
Paper copied to clipboard

PlayerItemMendEvent#setRepairAmount(0) causes recursion

Open HexedHero opened this issue 2 years ago • 5 comments

Expected behavior

Unsure?

Observed/Actual behavior

Doing

    @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
    public void a(PlayerItemMendEvent event) {
        event.setRepairAmount(0);
    }

will cause a recursion and kick you.

I'm unsure if this should do this and if so I feel like there should be at least a note.

Steps/models to reproduce

Do the code above.

Plugin and Datapack List

N/A

Paper version

ver [03:44:05 INFO]: Checking version, please wait... [03:44:05 INFO]: This server is running Paper version git-Paper-333 (MC: 1.18.2) (Implementing API version 1.18.2-R0.1-SNAPSHOT) (Git: 9fd870d) You are running the latest version Previous version: git-Paper-331 (MC: 1.18.2)

Other

No response

Edit: https://hub.spigotmc.org/jira/browse/SPIGOT-6708 Related

HexedHero avatar May 13 '22 02:05 HexedHero

please include the stacktrace

MiniDigger avatar May 13 '22 10:05 MiniDigger

Ok i see the upstream JIRA and here.. the issue its related to the NMS try to run again the method because if you use 0 for repair the remain value of exp still then try again and again and again... like the JIRA issue its more easy if allow in the event edit the experience amount for make a think like

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void a(PlayerItemMendEvent event) {
    event.setRepairAmount(0);
    event.setRemainExperience(0);
}

for avoid this type of things...

Doc94 avatar May 14 '22 15:05 Doc94

ok i need search first... this issue can be solved by https://github.com/PaperMC/Paper/pull/7382

Doc94 avatar May 14 '22 15:05 Doc94

I think 7382 isn't the right fix for this. What about treating 0 as "cancelled". That will prevent the recursion stack overflow issue. You can still have event spam if you are sitting in xp orbs, but that was the case before and you cancelled it.

Machine-Maker avatar Jun 03 '22 18:06 Machine-Maker

I think 7382 isn't the right fix for this. What about treating 0 as "cancelled". That will prevent the recursion stack overflow issue. You can still have event spam if you are sitting in xp orbs, but that was the case before and you cancelled it.

Maybe be bettet my answer where you can set the remain for set this in 0 sounds a better cancel thing than only set the use experience to 0

Doc94 avatar Jun 03 '22 18:06 Doc94