Send and Execute Commands

Discussion in 'Plugin Development' started by Makeshift, Jun 15, 2012.

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


    Hi guys,

    I recently got into java and Bukkit development, and would like to create a 'daemon' of sorts to manage commands for various things. I've created ingame commands so when people type various things, it replies globally and to the player in various different ways etc.

    However, the 'daemon' part of the plugin is failing epicly. I would like to say a command in chat (in this case, "/cv"), and then I would like my plugin to execute several commands in the console. For example:
    I say /cv in chat
    In the console, "mv create 1" and "mv modify 1" is executed.

    I'm trying to use the script located here: get errors in line 17. I was also wondering if there is an easier way of doing it with server.dispatchCommand, and if so, how would one do so? As said, I'm not very familiar with Java as yet, and am still getting my head around calling classes from other classes and such...

    Here is my code so far for my
    package me.makeshift27015.worldcontroller;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    public class main extends JavaPlugin {
    public void onEnable() {
    //Irrelevent for now.
    public void onDisable() {
    //Irrelevent for now.
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    cmd.getName().equalsIgnoreCase("cv"); { //Initial command, add args
    sender.sendMessage("Hello World."); }
    return false;
  2. Server.dispatchCommand(<your sender>,<Your command String>);
  3. Offline


    Could you give a small example of it being used in my situation, say, replacing 'Sender.sendMessage' with a usable one? In the one I tried to do, Server cannot be resolved and I'm not sure where the sender would be used. So the console is told who the sender is?
  4. Offline


    do this to send a command to console to be executed:

    its what I use in one of my plugins to give mcmmo XP since I cant hook into mcmmo directly...i just make it send a console command the same way id type it manually.

    so mine for example is
    Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), addxp pString + " mining " + xpadd);

    you would have
    2. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    3. if (cmd.getName().equalsIgnoreCase("cv")) {
    4. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), mv create 1);
    5. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), mv modify 1);
    6. sender.sendMessage("MV create and modify ran successfull for 1");
    7. return true;
    8. }
    9. return false;
    10. }
  5. Offline


    Wonderful! Thank you for your help, that works perfectly.
  6. Offline


    No problem at all, Ive asked tons of bukkit questions on here, figured Id pass on what I picked up in the last few weeks.
    and ferrybig is a big help also, I think he lives on the forums just replying to plugin dev section :)
Thread Status:
Not open for further replies.

Share This Page