WesJD / AnvilGUI

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

Doesn't work #297

Closed vortexthedev closed 11 months ago

vortexthedev commented 11 months ago

Doesn`t work at all for me using 1.19.4, 1.20.1, 1.20.2 versions. My code:

        new AnvilGUI.Builder().
                onClick((slot, state) -> {
                    if(slot != AnvilGUI.Slot.OUTPUT)
                        return Collections.emptyList();

                    return List.of(
                            AnvilGUI.ResponseAction.run(() -> player.performCommand("friend add " + state.getText()),
                            AnvilGUI.ResponseAction.close()
                    );
                }).
                title(ChatColor.GREEN + "Enter username").
                text("User").
                plugin(plugin).
                open(player);
vortexthedev commented 11 months ago

https://gyazo.com/e0a95ad4b19a79edb322ea07011ad94f

mastercake10 commented 11 months ago

I was not able to reproduce your issue.

A few thoughts:

  1. Your List of ResponseAction is invalid, you are missing a ): AnvilGUI.ResponseAction.run(() -> player.performCommand("friend add " + state.getText()), -> AnvilGUI.ResponseAction.run(() -> player.performCommand("friend add " + state.getText())),, so it won't compile. Even with this fix your code works as expected.
  2. Where does player come from? You should use state.getPlayer() here.
  3. Your recording shows a GUI with a nether star and some foreign characters, so your code differs from the recording. Maybe this is relevant to resolve your issue.

Please provide the full source code to look into this further

vortexthedev commented 11 months ago
    public void action(Player player, String text, String command) {
        player.closeInventory();
        new AnvilGUI.Builder().
                onClick((slot, state) -> {
                    if(slot != AnvilGUI.Slot.OUTPUT)
                        return Collections.emptyList();

                    return List.of(
                            AnvilGUI.ResponseAction.run(() -> player.performCommand(command + " " + state.getText())),
                            AnvilGUI.ResponseAction.close()
                    );
                }).
                itemLeft(new ItemStack(Material.NETHER_STAR)).
                title(ChatColor.GREEN + "Enter " + text).
                text("Answer").
                plugin(YourPlugin.getInstance()).
                open(player);
    }

There is the code I'm using to open the anvil GUI on the gif which is not working, basically I've copied it from the example that you have provided in the readme.

WesJD commented 11 months ago

Have you tried this with only anvilgui running on the server? Looks like a classic conflicting plugin.

vortexthedev commented 11 months ago

image

WesJD commented 11 months ago

So no, you didn't do that? You sent a picture with 15 plugins loaded.

vortexthedev commented 10 months ago

Add me to Discord please: @vortex2252