How can I catch commands run by commandblocks?

Discussion in 'CommandHelper' started by malon, Oct 3, 2017.

  1. malon

    malon Member

    I have a feeling this is really easy, but I'm stuck again.

    I thought that maybe I could listen for "player_command" event, and then run get_command_block() and check if null, but player_command doesnt fire when it's run by a commandblock.

    How else can I catch commands run by commandblocks?
  2. PseudoKnight

    PseudoKnight Well-Known Member

    Registered commands were always ran from commandblocks. Aliases could even be ran by commandblocks via /runalias command. Now in 1.12.2, aliases can even be ran without /runalias.

    But no, commandblocks won't trigger player_command. They trigger server_command. But unless you're filtering all commands for some reason, you don't need to use that.
  3. malon

    malon Member

    fyi, server_command is not listed in the event api

    Here's what I want to do:

    See, when you download maps online, they often come with commandblocks in them. I want those commandblocks to be "nullified". Now, I can't just remove all commandblocks because sometimes they are used in a texture pack as various objects. Instead, I want to set_block_command() to an empty string.

    So, I want to catch all commandblocks run in a given world (list of worlds, technically), cancel the command, catch the origin location of that command, and empty the commandblock out.

    Make sense? It's the only way I can figure how to be able to download maps and empty out commands in the commandblocks. It seems that server_command can probably accomplish this
  4. PseudoKnight

    PseudoKnight Well-Known Member

    server_command is not in the core API because LadyCailin thought it was too dangerous at the time (several years ago when extensions were first added). It's provided in the CHAdvanced extension. I'd support adding it to the core, though, as there's plenty of other ways of screwing things up in a similar manner.
  5. malon

    malon Member

    I installed CHAdvanced, but it seems that there's no way to tell if the command originated from a commandblock.

    PHP:
    bind(server_command,null,null,@e){
        @cb = get_command_block()
        console(@cb)
    }
    console always prints "null" no matter what.

    Any other ideas on how to detect if a command is run by commandblock?
  6. PseudoKnight

    PseudoKnight Well-Known Member

    I'd have to edit server_command to support get_command_block() since commandblocks only recently started triggering that event. You can just MCEdit all commandblocks out of the map if you don't want any of them.
  7. malon

    malon Member

    I've exhausted all possibilities. I've contacted the authors of NBTEdit, MCEdit, and posted multiple help threads on how to do this.

    The problem is I'm using them against large worlds, too large to handle. Both NBTEdit and MCEdit crash with OOM errors even though I have 12GB ram, the worlds are just too large.

    Is there any other way to do this? editing server_command to catch command blocks would really make my day, it's the only solution I know of.
  8. PseudoKnight

    PseudoKnight Well-Known Member

    With MCEdit, you can set a higher block buffer to actually use your memory. I'd also recommend disabling "Record Undo" at the top of the screen.

    I'd rather move server_command into core than edit the extension.
  9. malon

    malon Member

    Are you saying that if server_command was moved into core, it would have the functionality of "get_command_block()" by default? If so, how do I convince LadyCailin to please move it into core?
  10. PseudoKnight

    PseudoKnight Well-Known Member

    get_command_block() support could be added either way, but I'd rather it was moved into core. I don't think the reasoning behind leaving it out is valid, at least today.
  11. malon

    malon Member

    Okay, I'm abotu to give it another try, per your request, but I'll need your assistance.

    #1. Which MCEdit do I use? Original or Unified?
    #2. I'm not really sure how to just "empty out" command blocks. How would you do it with McEdit?
    #3. How do you recommend I adjust block buffer? (and where can I find it?)
  12. PseudoKnight

    PseudoKnight Well-Known Member

    I'm only familiar with the original. Your results may vary with other versions. It's just a find and replace function to set commandblocks to air in your selection.

    I never said that. I can't add it right now, though. You should realize that this simply wasn't possible AT ALL until [edit: 1.12.1]. We even only recently added full support for it a few days ago.

    [edit] I looked at all versions and it looks like MCEdit 1.x and MCEdit Unified are the interfaces familiar to me. Only the 2.0 beta is different and doesn't have the options I mentioned.
    Last edited: Oct 4, 2017
  13. malon

    malon Member

    I apologize, I actually had no idea this was recent to 1.12.2. I'll just be patient then. I'm sorry for pressing the issue.

    While that is true, I did mention I cannot simply turn them to air. They are also used decoratively, so they must be "emptied out".
  14. malon

    malon Member

    Okay, well, I do hope to have it added, but I really didn't know this was recent.

    @LadyCailin
    I know I'm a nobody, but I would like to see this feature added to server_command, whether it stays as an extension or gets integrated. I personally vouch for integration, if it matters at all. Thank you.
  15. PseudoKnight

    PseudoKnight Well-Known Member

    Unified has a feature (bottom left) to edit all commandblocks in a selection via a text file. It's pretty nice.
  16. malon

    malon Member

    I clicked the "CB" button 40 minutes ago, when i posted those 3 questions. I was trying my old way before you responded. It's still going. The problem is it creates a file that you're supposed to "edit and save" but its tens of thousands of lines long, and I was unable to edit all of them with surety.

    In fact, try it yourself.

    It's Broville. OPen it up, select all the chunks, and click CB commands and watch it take forever and end up with a giant file that's nigh impossible to edit and save.

    I've got reddit threads, github issues, and spigot forums going on and on about how to "empty out" command blocks. Would you like me to link you to how many times I've tried to do to this? I thought I found the holy grail with server_command and get_command_block(), which is why I got so excited. I've really been trying to do this for months. Almost a year.

    Also, I'm interested: what changed in 1.12.2 that allowed you to finally detect command blocks? I had always figured it was easy.
    Last edited: Oct 4, 2017
  17. PseudoKnight

    PseudoKnight Well-Known Member

    Bukkit never triggered a ServerCommandEvent for CommandBlocks until recently.
  18. PseudoKnight

    PseudoKnight Well-Known Member

    Might be too late, but for what it's worth I brought this up to LadyCailin yesterday and she said it sounds reasonable. So I worked on it some today. Debating how best to do this, but right now I'm creating a server_command and breaking off commandblock's off into block_command.
  19. malon

    malon Member

    @PseudoKnight

    I am not sure why you say it might be too late (fear of LadyCailin changing her mind?) but these new features sound amazing! I really hope to see at least block_command added, thank you very, very much.
  20. PseudoKnight

    PseudoKnight Well-Known Member

    You might have noticed, but I recently added server_command event and get_command_block() is supported in it.

    Small note: it is unlikely that command minecarts are used, but if they are, get_command_block() will return a location array with a yaw and pitch. You could also just catch the FormatException that would occur if you try and set_block_command().