Run a console command in a plugin?

Discussion in 'Plugin Development' started by Tauryuu, Jan 7, 2012.

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

    Tauryuu

    I couldn't find anything about running a command as console through a plugin. Is there an easy way to do it?

    Thanks in advance. :)
     
  2. Offline

    Technius

    getSever().dispatchCommand(getServer().getConsoleSender, "command goes here");
     
    htmlman1, hammale and tomjw64 like this.
  3. Offline

    tomjw64

    Oh, that's quicker! I've been using PluginCommand to execute commands up until now. Thanks for the quicker and better way of doing that, Technius!
     
  4. I know, this thread is old, and I hope that you will read this:

    I wanna use this console command too, and how I can make, that in the command, theres the Playername of the player, who sent the command. Example:

    Code:
           
            if (sender instanceof Player)  {
           
                Player player = (Player) sender;
               
                if(cmd.getName().equalsIgnoreCase ("IReadTheRules"))  {
                   
                    if(args.length == 0) {
                       
                        getPlayer("playername");
                        getServer().dispatchCommand(getServer().getConsoleSender(), "permissions player addgroup [B](sender)[/B] user");
                        
    And at (sender) it writes the name of the player

    MFG
    Black_ixx
     
  5. Basic Java string formatting:
    Code:
    "permissions player addgroup " + sender.getName() + " user"
    ?

    Still, I don't think you need to use a command to do that, hook the permissions plugin and use their interface.
     
    black_ixx likes this.
  6. Offline

    Technius

    getServer().dispatchCommand(getServer().getConsoleSender(), "permissions player addgroup " + player.getName() + " user");
     
    black_ixx likes this.
  7. I have it, thanks to both of you
     
  8. Offline

    gummby8

    http://pastebin.com/iRE8PnJq
    I am trying to run this as a script when I do I get an error that says "getServer is not defined"
     
  9. Offline

    Njol

    Use Bukkit.getServer().
     
  10. Offline

    gummby8

    "Bukkit" is not defined.
     
  11. Offline

    desht

    Then import it!

    (You are using an IDE, right? In Eclipse, hit Ctrl-1 on the line where you have the error, and choose to import org.bukkit.Bukkit. I'm sure NetBeans & Intellij have similar functionality).
     
  12. Offline

    gummby8

    Lol I have the smallest working knowledge of java. I am not making a plugin, I am simply trying to run a script within a plugin that someone else made. This script is written in notepad++ (>.<)

    Where have I seen your profile pic from!?
     
  13. Offline

    desht

    Not sure what you mean by "script". Java isn't a scripting language as such.

    Read Terry Pratchett at all?
     
  14. Offline

    gummby8

Thread Status:
Not open for further replies.

Share This Page