WesJD / AnvilGUI

Capture user input in Minecraft through an anvil GUI in under 20 lines of code
MIT License
466 stars 111 forks source link

Item disapper if drop or left in text area #296

Closed DavideTW closed 8 months ago

DavideTW commented 9 months ago

AnvilGui version: 1.9.0-SNAPSHOT Paper version: 1.20.1

Basically, if I have an AnvilGui opened and I try to drop an item or click with an item in the text area, the gui closes and the item disappear.

My code:

AnvilGUI.Builder builder = new AnvilGUI.Builder()
                .title(ChatColor.YELLOW + "Test gui")
                .text(" ")
                .itemLeft(new ItemStack(Material.STONE))
                .plugin(this)
                .onClick((slot, completion) -> {
                    Player player = completion.getPlayer();

                    if (!completion.getText().equals("test")) {
                        player.sendMessage("Insert test!");
                        return List.of(AnvilGUI.ResponseAction.close());
                    }

                    player.sendMessage("success");
                    return List.of(AnvilGUI.ResponseAction.close());
                });

// opens the gui to the player
WesJD commented 9 months ago

Could you provide a video of the issue?

DavideTW commented 9 months ago

Sure, here's a video.

https://github.com/WesJD/AnvilGUI/assets/64831836/e90989b1-77e2-4993-8364-c3442011c348

intersecato commented 9 months ago

@WesJD same problem

DavideTW commented 9 months ago

Tested in 1.19, same problem. Tested with AnvilGui 1.8.0, same problem. Tested with Player#closeInventory, same problem. Tested with return List.of(AnvilGUI.ResponseAction.close()), same problem

WesJD commented 9 months ago

Sorry, I really want to take a look at this but I'm swamped with life right now. I won't be able to take a look for a least another week or two.

Could someone give this a look if they have time? Calling in our awesome contributors like @mastercake10 and @Phoenix616, or anyone who can.

mastercake10 commented 9 months ago

Turns out when you click outside the GUI with an item, it still triggers the clickHandler, which should not happen. In this case, the rawSlot id is -999, which is invalid. Will submit a PR.

DavideTW commented 9 months ago

ok, drop outside inv fixed. Same problem if I click with an item on the left or right item.

DavideTW commented 9 months ago

@mastercake10 heres a video

https://github.com/WesJD/AnvilGUI/assets/64831836/fb26dbef-c28e-4c6c-bb50-abe347fc405a

DavideTW commented 9 months ago

Problems with new commit (idk if you have finished working on it @mastercake10):

I've found another bug (working with last master commit and last dev commit): If I open an anvilgui with an item on the cursor I lose the item. If you are wondering how I'm opening a anvilgui with an item on the cursor I've made an item in a gui (normal bukkit gui) that opens an anvil gui.

Notice that if I click on an item that open a normal gui the item it is not lost.

https://github.com/WesJD/AnvilGUI/assets/64831836/1891ab10-6d39-44ac-9116-ae3f1bfd680d

Code: https://pastebin.com/e5CELSJ4

mastercake10 commented 8 months ago

@DavideTW I think I've fixed all the bugs you mentioned.

I've found another bug (working with last master commit and last dev commit): If I open an anvilgui with an item on the cursor I lose the item. If you are wondering how I'm opening a anvilgui with an item on the cursor I've made an item in a gui (normal bukkit gui) that opens an anvil gui.

Working with your code example, I found out that vanilla calls an extra method for properly closing the previous container and putting back the cursor item into the player's inventory, EntityPlayer#doCloseContainer. Somehow this call was never added to AnvilGUI, so I've added this method for all version wrappers in my PR.

https://github.com/WesJD/AnvilGUI/assets/16278273/5176bc2d-cbb2-4026-a745-faf646b1fe49