WesJD / AnvilGUI

Capture user input in Minecraft through an anvil GUI in under 20 lines of code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Item disapper if drop or left in text area

DavideTW opened this issue · comments

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

Could you provide a video of the issue?

Sure, here's a video.

Base.Profile.2023.10.10.-.23.12.35.05.mp4

@WesJD same problem

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

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.

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.

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

@mastercake10 heres a video

Base.Profile.2023.10.22.-.19.58.24.03.mp4

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.

Base.Profile.2023.10.23.-.23.06.21.04.mp4

Code: https://pastebin.com/e5CELSJ4

@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.

Peek.2023-10-25.02-04.mp4