Can you run a command already in Minecraft through your plugin?

I’m trying to develop a plugin that runs a command when a command from my own plugin is executed.

For example, say I add the command /g when running, I’d like to run /give

I looked into Click Action Run Command http://spongepowered.github.io/SpongeAPI/org/spongepowered/api/text/action/ClickAction.RunCommand.html

but that doesn’t work.

Any ideas?

Thanks!

I wouldn’t recommend doing so, but if you have to, here you go.

Game.getCommandDispatcher().process(game.getServer().getConsole(), “command and it’s params”);

Anyway, inventory will be implemented soon, so this will become a bad way of doing that.

2 Likes

Thanks a bunch! Was having trouble finding it in the JAVA DOC. Didn’t realize it was a method in the Game class.

No problem. :smile:

1 Like

You can also run the command “as the player”:

cmdService.process(player, "msg Notch hi notch!");

More info: https://docs.spongepowered.org/en/plugin/basics/commands.html#the-command-service

2 Likes