Jump to content

Recommended Posts

Posted

Essentially what I'm trying to do is create a GUI that can send vanilla commands and display the results of the commands.

 

Here's what I've tried:

  • Minecraft.getMinecraft().thePlayer.sendChatMessage(command)

    doesn't work because that sends the results of the commands to the

    GuiChat

    , not my custom

    GuiScreen

    .

  • ClientCommandHandler.instance.executeCommand(commandSender, command)

    doesn't work because

    CommandHandler

    's

    commandMap

    is empty, implying normal commands aren't sent that way.

  • In answers for 1.8 and before, people have said to use
    MinecraftServer.getServer().getCommandManager().executeCommand(commandSender, command)

    , but in 1.9

    getServer()

    is not static.

  • Minecraft.getMinecraft().thePlayer.getServer().getCommandManager().executeCommand(commandSender, command)

    also doesn't work because

    Minecraft.getMinecraft().thePlayer.getServer()

    is null.

I've ran out of ideas other than creating a new

EntityPlayerSP

and having that send commands, but I don't think that would work very well—if at all—and it's not a very elegant solution.

 

So, how can I either send commands with a custom

ICommandSender

or intercept/copy the text sent to the player if I use

Minecraft.getMinecraft().thePlayer.sendChatMessage(command)

?

Posted

Send a packet to the server with the information required to execute the command. This includes the command and some way to identify the

ICommandSender

you want to use.

 

On the server, get the

MinecraftServer

instance from the sending player's

World

(

World#getMinecraftServer

) and then use its

ICommandManager

to execute the command.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 5/9/2016 at 2:41 AM, Choonster said:

Send a packet to the server with the information required to execute the command. This includes the command and some way to identify the

ICommandSender

you want to use.

As far as I can tell, there is no way to directly do this.

 

  Quote

On the server, get the

MinecraftServer

instance from the sending player's

World

(

World#getMinecraftServer

) and then use its

ICommandManager

to execute the command.

That has the same problem as

Minecraft.getMinecraft().thePlayer.getServer()

: the server is null.

 

  Quote

Minecraft.getMinecraft().getNetHandler().addToSendQueue(new CPacketChatMessage("/help"))

will execute a command. This behaves exactly as if the player had typed it in chat: if they do not have permission they will receive an error.

That is just a more low-level way of saying

Minecraft.getMinecraft().thePlayer.sendChatMessage(command)

, which doesn't work because that sends the results of the commands to the GuiChat, not my custom GuiScreen.

 


 

I'm going to see how command blocks handle it; they might have what I'm looking for.

Posted
  On 5/9/2016 at 1:38 PM, TheGuywithTheHat said:

  Quote

Send a packet to the server with the information required to execute the command. This includes the command and some way to identify the

ICommandSender

you want to use.

As far as I can tell, there is no way to directly do this.

Use a custom packet.

 

  Quote

  Quote

On the server, get the

MinecraftServer

instance from the sending player's

World

(

World#getMinecraftServer

) and then use its

ICommandManager

to execute the command.

That has the same problem as

Minecraft.getMinecraft().thePlayer.getServer()

: the server is null.

It should never return

null

on a server-side

World

.

 

  Quote

I'm going to see how command blocks handle it; they might have what I'm looking for.

GuiCommandBlock#actionPerformed

sends a

CPacketCustomPayload

with the command and either the command block position or minecart entity ID. The server-side handler then retrieves the

TileEntity

or

Entity

from this data and saves the changes.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I've figured out that

Minecraft.getMinecraft().getIntegratedServer()

works in singleplayer.

 

Because I don't really intend for this to be a server mod, I think I'll just make it not work but not crash when attempting to execute a command on a server:

MinecraftServer server = Minecraft.getMinecraft().getIntegratedServer();
if(server == null) {
    parent.parent.out.println("You cannot run vanilla commands on a server!");
} else {
    server.getCommandManager().executeCommand(parent, command);
}

 

Thanks anyways for the help, Choonster and diesieben!

  • Thanks 1
Posted
  On 5/9/2016 at 3:46 PM, diesieben07 said:

This is a really bad idea. Executing server commands from the client thread will cause all kinds of problems.

 

Pardon my ignorance, but isn't that what I'm doing with

Minecraft.getMinecraft()[b].getIntegratedServer()[/b].getCommandManager().executeCommand(parent, command)

? And if there is not integrated server (i.e. I'm in multiplayer), I don't even attempt to run the command.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Good day, I know this is years later and I hate to necropost but I ran into this exact same issue today and yours was the only one that popped up in my search. Turns out my file system permissions were all kinds of messed up in my minecraft directory. Here's how I fixed it: 1. Open terminal 2. Navigate to the .minecraft directory using the cd command, it can be helpful to have your file explorer open next to your terminal if you're a more visual person like me 3. On my OS (PopOS) the folders with messed up permissions had a padlock on them 4. Ran the command  sudo chmod a+rwx [fileName] I also ran  sudo chmod 777 [fileName] and got the same results with both. However it turns out a lot of my sub folders were messed up too which meant I had to make the changes recursively, which in plain English means all of the sub-folders under the directory. So I ended up running the command  sudo chmod -R 777 [fileName] which then changed all of the subfolders and files and ended up saving me a LOT of time doing it one at a time like the first two commands do. 5. After fixing permissions in the various subfolders ran the installer with the command java -jar [latestForgeInstallerNameGoesHereWithoutSquareBrackets] 6. Installed and launched without a hitch! Hope this helps new Linux users as for most advanced users this breakdown isn't very helpful, I'm still learning a ton myself. Additional note that might clear up future confusion, do not include [ or ] in your commands that I've listed here, I just use [ and ] in my personal notes to denote that I need to put something from the file system in the command. If yours was anything like mine all of the files from /de/oceanlabs/mcp/mcp_config/1.18-20211130.085255/mcp_config-1.18-20211130.085255-mappings.txt all had the wrong permissions. -Zamorakphat
    • hi fellas I remember back when I was in high school and had way more time to develop mods, there were tons of active posts, and while the documentation wasn’t always super extensive, you could always find someone to help you out with your questions or see someone else’s threads that were really informative. But lately, I’ve noticed that the forum seems pretty empty compared to how it used to be. I’m wondering, is there a specific reason for this? Is it just that the community has moved to other platforms, like Discord? It feels like a lot of the knowledge base and conversations have shifted over there. I’m just curious to hear others’ thoughts on this, and if anyone knows why the forum has become quieter, I’d love to know! Thanks!
    • @TileEntity Here's the log, sorry for all the trouble and confusion  https://paste.ee/p/Ihi4VMVn
    • https://gist.github.com/StrikeAttack7/f638897b5ffb88cc6db6c21946e1a216 When I tried logging into the server client side this is the error I got
    • crash-report (google docs) lastest.log (google docs)
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.