Command not returning message

Discussion in 'Plugin Development' started by CooperCraft15, Jan 25, 2016.

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

    CooperCraft15

    This is my code, when they do /business.create <Name>
    Nothing happens, this is my code;
    package me.renovirus.myplugin;

    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;

    public class BusinessMe extends JavaPlugin{
    private final Logger log = Logger.getLogger("Minecraft");
    @Override
    public void onEnable(){
    log.info("[BusinessMe] Is now enabled!");
    }

    @Override
    public void onDisable(){
    log.info("[BusinessMe] Is now disabled!");

    }
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (args.length > 1)
    {
    sender.sendMessage(ChatColor.RED + "Too many arguments!");

    }else{
    if (args.length < 1)
    sender.sendMessage(ChatColor.RED +"Not enough arguments!");

    return true;}
    return true;

    }



    public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args) {
    String command = cmd.getName();
    if (command.equalsIgnoreCase("business.create")) {
    sender.sendMessage(ChatColor.GREEN +"[BusinessMe] You have succesfully created a Buinsess!");}

    return true;



    }


    public boolean onCommand2(CommandSender sender, Command cmd, String label, String[] args) {
    String command1 = cmd.getName();
    if (command1.equalsIgnoreCase("business.remove")) {
    sender.sendMessage(ChatColor.GREEN + "[BusinessMe] You have succesfully removed a business!");}

    return true;}

    }
     
  2. Offline

    Zimboni

    Could you format your code and put it between[code=java] and [/code]? Would be way easier to read and troubleshoot.

    For now my only idea would be if the 1 in
    ruins it but I'm not sure since I'm not too experienced with plugin development so far

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 25, 2016
  3. Offline

    shades161

    You need to check that the command name is the right one on your first onCommand() as it is not checking for the command name. onCommand should also return false by default, not true.
    IE:
    Code:
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
              if (cmd.getName().equalsIgnoreCase("myCommandName")) {
                   //Do Stuff
              }          
            return false;  
        }
    (PS, please put your code, properly fomatted between the [!code=java] [!/code] tags)
     
  4. Offline

    CooperCraft15

    Ok Thanks. Now I need to figure out how to log the Business into the system when they create it xD but thanks anyways.
     
  5. Offline

    Zombie_Striker

    Don't steal minecraft's logger! Use getLogger instead.

    Bukkit already logs your plugin for you. You do not need these.

    As for your problem, you check if the args are wrong, but you don't do anything if the args are the correct length. Also, it must be called onCommand()
     
    shades161 likes this.
Thread Status:
Not open for further replies.

Share This Page