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

Doesn't work

vortexthedev opened this issue · comments

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);

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

    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.

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

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

Add me to Discord please: @vortex2252