Skip to content

Prevent dupe bug with recipe command#6455

Open
Golfing7 wants to merge 7 commits intoEssentialsX:2.xfrom
Golfing7:recipe-dupe-fix
Open

Prevent dupe bug with recipe command#6455
Golfing7 wants to merge 7 commits intoEssentialsX:2.xfrom
Golfing7:recipe-dupe-fix

Conversation

@Golfing7
Copy link
Contributor

@Golfing7 Golfing7 commented Mar 7, 2026

Information

This PR fixes #6450 .

Details

Proposed fix:
I added a check to make sure that items are only placed into the inventory when it successfully opens.

Environments tested:

OS: Linux Mint

Java version: 21

  • Most recent Paper version (1.XX.Y, git-Paper-BUILD)
  • CraftBukkit/Spigot/Paper 1.12.2
  • CraftBukkit 1.8.8

Demonstration:

In order to replicate the issue, I used the following code to test:

    @EventHandler
    public void onRecipeStop(InventoryOpenEvent event) {
        if (event.getPlayer().isSleeping()) {
            event.setCancelled(true);
        }
    }

@CullanP
Copy link

CullanP commented Mar 7, 2026

This also needs to be applied for shapeless recipes and recipesee would still be true here, closing inventory + setting recipeSee to false would be best so that if they have a previous recipe GUI open and cancels the GUI it wouldn't allow them to take items out

Copy link

@benediktjohannes benediktjohannes left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for addressing this! I think that (despite the concerns of @CullanP) this is a nice quick fix for the very first place. 👍

Copy link

@benediktjohannes benediktjohannes left a comment

Choose a reason for hiding this comment

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

Fix lint

JRoy and others added 2 commits March 8, 2026 14:52
…andrecipe.java

Co-authored-by: Benedikt Johannes <benedikt.johannes.hofer@gmail.com>
@JRoy
Copy link
Member

JRoy commented Mar 8, 2026

@benediktjohannes Can you please avoiding approving PRs or requesting changes unless you have a major feedback (not things already caught by checkstyle).

@Golfing7
Copy link
Contributor Author

Golfing7 commented Mar 8, 2026

Addressed the comments. Thank you! As far as I can tell, the only reason it works for the shaped recipes is because of the use of getTopInventory. The InventoryView is always a view of a crafting table when returned.

@benediktjohannes
Copy link

@benediktjohannes Can you please avoiding approving PRs or requesting changes unless you have a major feedback (not things already caught by checkstyle).

@JRoy yes, of course! Sorry for the approval, I just wanted to give some feedback. One question: Is it ok to comment with suggestions in order to help out and let other people fix things faster like the final comment so that the others can just click commit and then it‘s fixed?

@CullanP
Copy link

CullanP commented Mar 9, 2026

Addressed the comments. Thank you! As far as I can tell, the only reason it works for the shaped recipes is because of the use of getTopInventory. The InventoryView is always a view of a crafting table when returned.

The API docs are deceiving, you can still dupe using shapeless recipes, the API also states it returns null when the inventory is not opened but it doesn't return null, it returns your current view, that includes when in a bed.

Tested on latest paper 1.21.11 using this fork and you can still dupe shapeless recipes using /recipe magma_cream

tested with this eventhandler and running /recipe magma_cream, you'll see the items in your crafting slots, this did fix shaped recipes from duping though
@EventHandler public void onOpen(InventoryOpenEvent event) { event.setCancelled(true); }

@Golfing7
Copy link
Contributor Author

Golfing7 commented Mar 9, 2026

Addressed the comments. Thank you! As far as I can tell, the only reason it works for the shaped recipes is because of the use of getTopInventory. The InventoryView is always a view of a crafting table when returned.

The API docs are deceiving, you can still dupe using shapeless recipes, the API also states it returns null when the inventory is not opened but it doesn't return null, it returns your current view, that includes when in a bed.

Tested on latest paper 1.21.11 using this fork and you can still dupe shapeless recipes using /recipe magma_cream

tested with this eventhandler and running /recipe magma_cream, you'll see the items in your crafting slots, this did fix shaped recipes from duping though @EventHandler public void onOpen(InventoryOpenEvent event) { event.setCancelled(true); }

Addressed this by extracting the check into a helper method. Please re-test this for me as I was unable to test it myself.

@CullanP
Copy link

CullanP commented Mar 9, 2026

Addressed the comments. Thank you! As far as I can tell, the only reason it works for the shaped recipes is because of the use of getTopInventory. The InventoryView is always a view of a crafting table when returned.

The API docs are deceiving, you can still dupe using shapeless recipes, the API also states it returns null when the inventory is not opened but it doesn't return null, it returns your current view, that includes when in a bed.
Tested on latest paper 1.21.11 using this fork and you can still dupe shapeless recipes using /recipe magma_cream
tested with this eventhandler and running /recipe magma_cream, you'll see the items in your crafting slots, this did fix shaped recipes from duping though @EventHandler public void onOpen(InventoryOpenEvent event) { event.setCancelled(true); }

Addressed this by extracting the check into a helper method. Please re-test this for me as I was unable to test it myself.

There is an error now on line 53 and the shaped recipes dupe again with these changes, it needs to check WORKBENCH

@Golfing7
Copy link
Contributor Author

Golfing7 commented Mar 9, 2026

Addressed, thank you.

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.

/recipe dupe

4 participants