Solved Can't set a command in command block?!

Discussion in 'Spigot Plugin Development' started by MrAndeos, Dec 9, 2018.

  1. Hello.
    So, I have this code:
    Code (Java):
    Material type = block.getType();
    if (type == Material.COMMAND || type == Material.COMMAND_CHAIN || type == Material.COMMAND_REPEATING) {
        CommandBlock commandBlock = (CommandBlock)block.getState();
        String command = commandBlock.getCommand();
        command = command.replace(replace, replaceTo);
    And the problem is that the command in this block doesn't get changed at all, and yes, I checked that my "replace" and "replaceTo" variables are different, and existing command does contain "replace". Why this doesn't work?
    I'am using latest Spigot 1.12.2.
  2. Try calling the set state method on the block
  3. But... There is no such method.
  4. There's no block.setState(commandBlock)?

    EDIT: Yep checked javadocs, my bad, it's commandBlock.update()
  5. Yep, now it works, thanks for help :)