Multiple commands in one string

Discussion in 'Plugin Development' started by TheRam, Dec 17, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    TheRam

    Hi guys im almost finished with my first plugin, and there is just one more function i want for it.

    I have already got it set up to execute a command via console with a string value retrieved from the config file.

    all i want to do now is be able to execute multiple commands with information taken from a single string variable.
    so the string could look like ("say this && say that && say this too") or maybe something similar.
    and output would be (in this case)
    [Server] this
    [Server] that
    [Server] this too

    I was wondering what would be the best/simplest way of achieving this?
     
  2. Offline

    Webbeh

    You don't need to use the "say" every time.

    Just "split" the message using a delimiter (can be &&, ;;, ...), and create a String array containing them. Then iterate through them and broadcast that line.

    The command would look like "/say this;;;that;;;that too;;;lol" and would output
    [Server] this
    [Server] that
    [Server] that too
    [Server] lol
     
  3. Offline

    Darkpicasa

    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String command);
     
  4. Offline

    TheRam

    @Webbeh Could this work in a way that could run different commands other than the "say" cmd? like say,tp,bal,ect?
    im looking for the ability to jump between commands as-well.
    "say this && tp that && nuke [xyz]"
     
  5. Offline

    Webbeh

    You technically could, using the dispatchCommand posted two posts above mine here. Read the javadoc, and try to implement it yourself, it's the only way to learn, and isn't that difficult.
     
  6. Offline

    567legodude

    You would need something to split the commands with. Ill use -- for example.
    Code:
    String c = yourcommands;
    String[] cmds = c.split(Pattern.quote("--"));
    for (String s : cmds) {
        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s);
    }
    So if your string was "say hi--tp player--nuke [xyz]"
    Then it would run each command.
     
Thread Status:
Not open for further replies.

Share This Page