Run a command as console or op

Discussion in 'Plugin Development' started by xlilcasper, Jun 17, 2011.

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

    xlilcasper

    How would I run a command as the console an op level user? My plugin needs to run a command in another plugin (like an alias) but it has to be done as an op? Can someone point me to a method or a snip it of code or anything to get me started in the right direction?
     
  2. Offline

    Jako

    Well, sounds like you just want to be able to check if someone is an op. You can get that boolean by using player.isOp(). Then just check that when you want to know if someone is an op, and if they aren't don't run the code. Also if you want to run another plugin's command, you will need to import the plugin's jar (like you do for craftbukkit) and then look into the source, find which method the plugin uses to run a command, then just tie into that.
     
  3. Offline

    Shamebot

    try something like
    Code:java
    1. server.dispatchCommand(new ConsoleCommandSender(server)
    2. {
    3. @Override
    4. public void sendMessage(String message)
    5. {
    6. //here you can get a message sent back
    7. }
    8. },"command arg1 arg2");
     
  4. Offline

    xlilcasper

    I'll give this a try, thanks!

    This is working good but I have to now send two commands in a row. It seems to think that this is coming from two different users. Anyway to send more then one command at a time with dispatchCommand?

    what I'm trying to do is send the /manselect command and then /manuadd from group manager so I can change someones group.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  5. Offline

    Shamebot

    Just safe the ConsoleCommandSender.
    Code:java
    1. ConsoleCommandSender sender = new ConsoleCommandSender(server)
    2. {
    3. @Override
    4. public void sendMessage(String message)
    5. {
    6. //here you can get a message sent back
    7. }
    8. };
    9. server.dispatchCommand(sender, "command arg1 arg2");

    Though you could look into the groupmanager api as well.
     
  6. Offline

    xlilcasper

    I did end up using the API after much digging around and trial and error. However, knowing this may come in handy later or in another plugin. Thank you!
     
  7. Offline

    AJCStriker

    Hey, I'm looking to send the ban and kick commands to the console, but I cant seem to get the sender bit to work. Could you leave an example of how you could use the command set time day from this code?
     
  8. Offline

    Shamebot

    You can use Player.kickPlayer(..) to kick a player.
    Code:java
    1. ConsoleCommandSender sender = new ConsoleCommandSender(server)
    2. {
    3. @Override
    4. public void sendMessage(String message)
    5. {
    6. //here you can get a message sent back
    7. }
    8. };
    9. server.dispatchCommand(sender, "time set 0");
     
  9. Offline

    AJCStriker

    yer worked out that I had to import craftbukkit as a library. I am using this to allow remote console access so I had to get rid of the slash as well. Works nicely now i combined this with another post http://forums.bukkit.org/threads/console-command-onplayerlogin.9814/. Plugins called Chatter and its still in submissions. /end cheap marketing :)
     
  10. Offline

    Shamebot

    You don't need CraftBukkit for the snippet I posted.
     
Thread Status:
Not open for further replies.

Share This Page