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

StackOverflow when trying to re-enable a previously overidden command in the knownCommands map. #11890

Open
sovdeeth opened this issue Jan 3, 2025 · 0 comments
Labels

Comments

@sovdeeth
Copy link

sovdeeth commented Jan 3, 2025

Stack trace

https://mclo.gs/J5xbSNU

Plugin and Datapack List

PaperTestPlugin (for reproducing, provided as attachment)

Actions to reproduce (if known)

PaperTestPlugin-1.0-SNAPSHOT.zip
Start a server with this plugin, join the game, and attempt to tab complete the first argument of /give. The server should crash.
The code for the plugin's onEnable is as follows:

public void onEnable() {
        // Plugin startup logic

        Command command = new Command("give") {
            @Override
            public boolean execute(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String @NotNull [] strings) {
                getLogger().info("give command executed");
                return true;
            }
        };

        Command overridden = null;
        String label = "give";
        String prefix = "skript";

        CommandMap commandMap = Bukkit.getCommandMap();
        var knownCommands = commandMap.getKnownCommands();

        overridden = knownCommands.put(label, command);
        commandMap.register(prefix, command);
        getLogger().info("registered command");

        knownCommands.remove(label);
        knownCommands.remove(prefix + ":" + label);
        command.unregister(commandMap);

        // this is the issue
        if (overridden != null) {
            knownCommands.put(label, overridden);
        }

        getLogger().info("unregistered command");
    }

Paper version

version
[19:06:32 INFO]: This server is running Paper version 1.21.3-27-master@661839e (2024-11-11T19:22:47Z) (Implementing API version 1.21.3-R0.1-SNAPSHOT)
You are 55 version(s) behind
Download the new version at: https://papermc.io/downloads/paper
Previous version: 1.21.4-71-83995d7e (MC: 1.21.4)

I also replicated this on 1.21.4-71 and 1.20.6-148, however, 1.20.1-196 worked fine with this method, properly re-enabling the vanilla /give command.

Other

I don't think it's safe to be re-adding the vanilla command to the known commands map like this, but I'm unsure of any better way to approach it. Let me know if this is a bug, intentional, or if I'm doing this in a very unsafe manner and there's a better option.

@papermc-sniffer papermc-sniffer bot added the version: 1.21.3 Game version 1.21.3 label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant