Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] Executing a command as server console [SOLVED]


Novality
 Share

Recommended Posts

I've looked far and wide across the internet for some sort of help, but I can't find any methods that allow me to send commands through console.

Not much more needs to be said, this is quite a simple post. If someone could give me something, anything, that would be nice.

Link to comment
Share on other sites

7 hours ago, diesieben07 said:

Some clarification is needed. Do you want to write a mod that executes a command as if it was entered in the server console? Do you want to write an external program that relays commands to the server console?

One that executes commands as if it was entered in the server console.

Link to comment
Share on other sites

1 hour ago, Novality said:

One that executes commands as if it was entered in the server console.

MinecraftServer#getCommands().performCommand(source, command).

command is the command you want to run, source is the CommandSource for it. To use the same one the console uses, use MinecraftServer#createCommandSourceStack.

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, diesieben07 said:

MinecraftServer#getCommands().performCommand(source, command).

command is the command you want to run, source is the CommandSource for it. To use the same one the console uses, use MinecraftServer#createCommandSourceStack.

Thanks, but I'm having an issue grabbing the MinecraftServer variable.
My code:

MinecraftServer source = MinecraftServer.getServer();
source.getCommands().performCommand(source.createCommandSourceStack(), "say hi");


It doesn't seem to recognize "getServer()"

Link to comment
Share on other sites

  • Novality changed the title to [1.16.5] Executing a command as server console [SOLVED]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.