Solved Command doesn't work

Discussion in 'Plugin Development' started by MrFrozen, Jun 4, 2015.

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

    MrFrozen

    Hey Guys,

    I made a command in a plugin and weird enough it won't work while normal this works fine...
    When I execute the command it returns
    Code:
    /tronixgo
    My Code:
    Code:
    public boolean tronixgo (CommandSender sender, Command cmd, String label, String[] args) {
            if(sender instanceof Player) {
                if(cmd.getName().equalsIgnoreCase("tronixgo")) {
                    Player p = (Player) sender;
                    if(args.length == 0) {
                        getServer().getConsoleSender().sendMessage(tronix + "A tronix command has been executed wrong!");
                    } else {
                        p.sendMessage(tronix + ChatColor.GREEN + ChatColor.BOLD + "Welcome to your new journey");
                        p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "A journey that we call " + ChatColor.DARK_RED + ChatColor.BOLD + "TRONIX");
                        p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "A journey that you can start by exploring the spawn dungeons");
                        p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "A journey that can beat your or help you");
                        p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "And this all depends on your skill level of minecraft");
                        p.sendMessage("" + ChatColor.GOLD + ChatColor.BOLD + "So I think you are ready now not?");
                    }
                    return true;
                }
            } else {
                getServer().getConsoleSender().sendMessage(tronix + "Console cannot execute this");
            }
            return false;
        }
     
  2. Offline

    walu

    I think you should write your command to the yml file:

    Code:
    name: //Plugin name
    main: //Plugin main(me.name.mainfile)
    version: 1.0
    commands:
       tronixgo:
          description: //Description of your command.
          usage: /<command>
     
  3. Offline

    JoelyBob

    Is there supposed to be a space between tronixgo and (CommandSender?

    Code:
    public boolean tronixgo (CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
    //I would suggest
    
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
     
  4. Offline

    BizarrePlatinum

    @JoelyBob that wouldn't make a difference.

    @MrFrozen I believe the Boolean is returning false there, so bukkit's sending the usage, meaning conditions in the code aren't being met.
     
  5. Offline

    JoelyBob

    The space...? Or the name? I know the name doesn't matter...
     
  6. Offline

    MrFrozen


    I always create my commands ikt his but for a weird reason it give me the usage from the YML

    Code:
    name: TronixGo
    description: Tutorial plugin for TronixGo
    version: 1.0
    main: me.officialjoe.tronixgo.app
    commands:
      tronixgo:
        usage: /<command>
        description: Tutorial start command
    Thanks this helped for 50% didnt noticed it it now returns the usage and what it should give anyways I will sort that out thanks!

    EDIT by Timtower: merged posts
     
    Last edited: Jun 7, 2015
  7. Offline

    JoelyBob

    No worries..
     
  8. @MrFrozen Yeah for commands you have to override the onCommand() method from CommandExecutor. Unlike events, you cannot call the method whatever you want. Another problem with your code is that it assumes that a non-player CommandSender would always be a console, when this isn't the case :) It would be better to report the error back to the CommandSender, rather than the console, just to be sure.
     
Thread Status:
Not open for further replies.

Share This Page