Plugin returns the YML Usage after being ran

Discussion in 'Plugin Development' started by mrcal17, Nov 4, 2016.

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

    mrcal17

    This has been really bugging me, whenever I run my command for my plugin it throws back at me my plugin.yml usage that I have set and does not run the actual command.

    The code for both are as follows (The actual command then the yml.)
    COMMAND:

    Code (open)

    Player player = (Player) sender;

    if(cmd.getName().equalsIgnoreCase("repair")){
    if(args.length != 0){
    player.sendMessage(ChatColor.RED + "Please use /repair help, " + player.getName() + ".");

    }
    if(args[0].equalsIgnoreCase("help")){

    player.sendMessage("Welcome to the help page!\nFor this command currently we have 1 sub-command\nTo use it please type '/repair fix'");

    }

    if(args[0].equalsIgnoreCase("fix")){player.openInventory(inv);

    }


    YML:
    yml (open)

    name: Dungeonrpg
    version: 1.0
    main: com.dungeoncrusades.dungeonrpg.Dungeonrpg
    authors: fun
    description: Rpg stuff for Dunegon Crusades
    commands:
    repair:
    description: Why are you looking at this?
    usage: /repair


    Sorry for the syntax of the yml I can't control it
     
  2. Offline

    Zombie_Striker

    First, for most problems, we need your full class/ full method. Next time you post, atleast post the full method.
    You are most likely returning false. Returning false prints the message. Return true to stop receiving that message.
     
  3. Offline

    mrcal17

    even after returning only true it does it
     
  4. Offline

    Zombie_Striker

  5. Offline

    mrcal17

    @Zombie_Striker
    public class ScrapsMain extends JavaPlugin implements CommandExecutor{public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player player = (Player) sender;
    if (args.length != 0) {

    player.sendMessage(ChatColor.RED + "Please use /repair help, " + player.getName() + ".");

    }
    if (args[0].equalsIgnoreCase("help")) {
    player.sendMessage("Welcome to the help page!\nFor this command currently we have 1 sub-command\nTo use it please type '/repair fix'");

    }
    if (args[0].equalsIgnoreCase("fix")) {

    player.openInventory(inv);

    }

    return true;
    }
    return false;
    }
    }

    The return false at the bottom needs to be there for if the command fails which is sending back the yml usage and I have no idea why
     
  6. Offline

    Zombie_Striker

    @mrcal17
    Either you have not correctly encapsulated your code, or you are forgetting to return true/false if the args are not correct. (BTW You have it display that message if the args are not equal to 0. I think you meant to send it if it IS equal to 0, because currently this will throw an AOOB exception if the player provides no args)

    Also, I think you have to take a look at your brackets. You have an extra end bracket at the bottom, and you are return false in a place where it should have never worked.

    [Edit] I see at the top you are implementing CommandExecutor. Java plugin already implements it. Remove that bit.
     
Thread Status:
Not open for further replies.

Share This Page