[Question] Is there a way to intercept ALL commands from command block?

Discussion in 'Spigot Plugin Development' started by PikachuEXE, May 23, 2015.

  1. I have a server with command blocks placed randomly
    Sometimes they are activated (run command) ad hoc
    I want to find all command blocks triggered within a time period.
    I am trying to write a command block detector plugin but onCommand requires prefix registration, and PlayerCommandPreprocessEvent is not triggered for command block.
    Is there an event / method I am not aware of for this purpose?
  2. konsolas


    I believe there is ServerCommandEvent, (but I'm not sure)
  3. Thanks I will try that
    I thought it was for Console only o_0, not sure why I thought that
  4. I need to log the commands the command block & command minecart are executing, not trying to execute as command block
    It seems there is no way to do it with event. Now I am trying to execute some code after all plugins...
  5. there might be a wasy to see when redstone activates a command block then get the meta data for the command stored in the command block. once I get home I might see if its possible
  6. @PikachuEXE
    According to a Bukkit post, you can use onCommand, and check for the command block instance.


    Code (Text):
    public boolean onCommand(...) {
        if (!(sender instanceof BlockCommandSender)) {
            // we don't care about commands that weren't sent by a command block
            return true;
        // handle the command
    • Like Like x 1
  7. Finally done with BlockRedstoneEvent
    But that doesn't work with CommandMinecart, well...

    @MCAeolus onCommand is only useful when command is registered, it does not catch all command being executed
  8. could you detect the activator rail(And if its on) and get the command when the cart is above the rail? then get info from the cart?
  9. This is probably a bit of a hacky solution, but what if you create a new command, a sort of proxy command. It takes any amount of arguments greater than 0. When it is executed, all it does is make the sender execute the command that corresponds with it arguments, but before it does that it also notifies whatever part of your plugin needs to be notified of the command event. What you can now do is get all the needed command blocks and set their command to that new proxy command with arguments corresponding to the actual command they're gonna execute.

    For instance if the proxy command is called "proxy", for a CommandBlock assigned to the command "foo bar baz", you'd set its command to "proxy foo bar baz". The proxy command will notify your plugin that "foo bar baz" will be executed by said CommandBlock, and then it will make the CommandBlock execute "foo bar baz".

    Does this make sense?
  10. @dart2112 Using vehicle move event? I guess I can try that :)

    @Rocoty People (including me) will either forget to do so, or refuse to do so.
    I create this plugin to be "transparent" (not sure what word to use), bringing no extra effort for people not awareing the plugin.
  11. Do what exactly?
  12. Set command block's command to "proxy foo bar baz".
  13. I was thinking you could make your plugin do that automatically...
  14. 1. Is there an event for changing command of command block & command minecart?
    2. Too hacky