[Solved] performCommand from server

Discussion in 'Plugin Development' started by Grovert11, Jan 21, 2012.

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

    Grovert11

    What do I have to do to use performCommand for the console?
    I want to be able to use one command in the console, which executes 2 commands.
     
  2. Offline

    javoris767

    Code:java
    1. plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "command");
     
  3. Offline

    Grovert11

    Thank you! Though I get an error on plugin in plugin.getServer
    Whith what should I replace it? (I'm a real noob in this :p)

    And if I want to add an argument, can I just place in in the "command"?
    So if I want to execute "time day" I replace command with time day?

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

    javoris767

    public MainPluginClass plugin;
     
  5. Offline

    Grovert11

    If I put in the name of my mainclass, it still gives an error.
    Here is what I have (this class is called apcommand):
    Code:
    package me.Grovert11.AddPlayer;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.event.server.PluginEvent;
     
    public class apcommand implements CommandExecutor{
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
                String[] args) {
            if(commandLabel.equalsIgnoreCase("ap")){
                if(sender instanceof ConsoleCommandSender){
                    apmain.getServer().dispatchCommand(apmain.getServer().getConsoleSender(), "command");
                }
            }
            return false;
        }
     
    }
    And if neccesary, my mainclass (apmain) too:
    Code:
    package me.Grovert11.AddPlayer;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class apmain extends JavaPlugin{
     
        Logger log = Logger.getLogger("Minecraft");
        @Override
        public void onDisable() {
            log.info("|- AddPlayer by Grovert11 -|" +
                    "                                                |-  :(  Disabled  ):  -|");
        }
     
        @Override
        public void onEnable() {
            getCommand("brb").setExecutor(new apcommand());
            log.info("|- AddPlayer by Grovert11 -|" +
                    "                                                |-        Enabled        -|");
        }
     
    }
    
    (Don't know how to insert it as java code :()
     
  6. Offline

    ItsHarry

    Don't use plugin.getServer()

    Just use getServer() immediately

    getServer().dispatchCommand()
     
  7. Offline

    Grovert11

    Then I get an error too.
    When I click the lightbulb it gives me the option to Create method getServer()
     
  8. Offline

    ItsHarry

    Oh sorry, didn't see that you were accessing it from the commandexecutor.

    In your onEnable, use new ApCommand(this);

    change the constructor to
    private static ApMain plugin;

    public ApCommand(ApMain instance)
    {
    this.plugin = instance;
    }

    Then use plugin.getServer();

    Btw. Class names should always start with a capital letter :D
     
  9. Offline

    Grovert11

    Could you change this in the code and send it, because I don't understand a thing because of my noobiness ;)
     
  10. Offline

    Grovert11

  11. Offline

    Njol

    You can simply use
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "command");
     
  12. Offline

    Grovert11

    Many, many thanks to you!
    Really appreciate your help!
     
Thread Status:
Not open for further replies.

Share This Page