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

Bukkit.createInventory() is weird #9892

Closed
Shesper opened this issue Oct 30, 2023 · 5 comments
Closed

Bukkit.createInventory() is weird #9892

Shesper opened this issue Oct 30, 2023 · 5 comments
Labels
mitigated Workaround found for this issue. resolution: duplicate Issue or Request is a copy of an existing ticket. type: bug Something doesn't work as it was intended to.

Comments

@Shesper
Copy link

Shesper commented Oct 30, 2023

Expected behavior

After creating an anvil inventory with the Bukkit.createInventory() method, PrepareAnvilEvent must be called when controlled after it is opened to the player.

Observed/Actual behavior

However, PrepareAnvilEvent is not actually called and the inventory behaves as if the InventoryClickEvent was cancelled, and the item disappears on SHIFT+LEFT click control.

Steps/models to reproduce

The code is like this:

image

111111111

22222222222222

Plugin and Datapack List

image

Paper version

image

Other

No response

@Shesper Shesper added status: needs triage type: bug Something doesn't work as it was intended to. labels Oct 30, 2023
@electronicboy
Copy link
Member

This is not a bug as much as it's long missing functionality from bukkit, not all createInventory method calls will end up creating a "real" inventory of a specific type, right now, you have an inventory that looks like an anvil, but has literally 0 of its functionality, the only reason you see anything happening otherwise is because the client has its own logic which "predicts" the outcome

@Sytm
Copy link
Contributor

Sytm commented Oct 31, 2023

You probably want to use this "family" of methods instead because it opens real inventories

@Lori3f6
Copy link
Contributor

Lori3f6 commented Jan 20, 2024

I have searched some posts and found the problem has been persisted for a long time, as discussed in this SpigotMC post.
The anvil inventory instance created by server.createInventory is a instance of CraftInventoryCustom, which as this post states, it is not a real AnvilInventory and can not cast as well. Additionally, it does not invoke PrepareAnvilEvent.
The biggest missed function of this is fake anvil inventory is the plugin unable to fetch the content inside its text bar.
It would be nice if paper add a implementation for it someway. For instance, maybe opening the UI from a real anvil created internally, not present in the world?

@Machine-Maker
Copy link
Member

It would be nice if paper add a implementation for it someway. For instance, maybe opening the UI from a real anvil created internally, not present in the world?

There is a way, the openAnvil method that was mentioned above your post. You can customize the title too with the InventoryOpenEvent title override.

@Warriorrrr Warriorrrr added resolution: duplicate Issue or Request is a copy of an existing ticket. mitigated Workaround found for this issue. and removed status: needs triage labels Feb 10, 2024
@Warriorrrr
Copy link
Member

Closing as a duplicate of #5825, use the openAnvil method instead as a workaround

@Warriorrrr Warriorrrr closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mitigated Workaround found for this issue. resolution: duplicate Issue or Request is a copy of an existing ticket. type: bug Something doesn't work as it was intended to.
Projects
Status: Invalid
Development

No branches or pull requests

6 participants