Problem in code

Discussion in 'Plugin Development' started by BDKing88, Jan 12, 2014.

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

    BDKing88

    Hey everybody! I am making a team plugin, and I believe I have written it correct, but when I type the command in-game, nothing happens.
    Code:java
    1. public boolean onCommand1(CommandSender sender, Command cmd, String commandLabel, String[] args, Player player) {
    2. if(cmd.getName().equalsIgnoreCase("class")) {
    3. if(args.length == 0) {
    4. sender.sendMessage(ChatColor.GREEN + "/class <class>");
    5. } else {
    6. PVPType pvptype = PVPType.searchByName(args[0]);
    7. if(pvptype != null) {
    8. pvptype.applyItems(player);
    9. sender.sendMessage(ChatColor.GREEN + "You are now an" + pvptype);
    10. }
    11. }
    12. }
    13. return false;
    14. }


    (This is spaced correctly, for some reason it won't paste in right, so that's not a problem.)

    Plugin.yml:

    Code:
    name: ZenithPvpTeams
    version: 1.0
    main: me.bdking00.zenithpvpteams.Main
     
    commands:
      class:
        description: Choose classes
      setspawnred:
        description: Set red spawn
      setspawnblue:
        description: Set blue spawn
     
    permissions:
      znpvp.engineer:
        description: Be an engineer
        default: op
      znpvp.axeman:
        description: Be an axeman
        default: op
      znpvp.setspawn:
        description: Set the spawns
        default: op
     
  2. Offline

    felixfritz

    Why is your method calld onCommand1? Shouldn't it be only onCommand?
     
  3. BDKing88
    I'm not too sure about this, as I've never tried it and am a Java noob, but I believe the method name has to be onCommand, otherwise it will not work.

    If you have multiple commands, and don't want all of them in one method (I know it can look terrible if you do), consider making separate classes for each command.
     
  4. Offline

    MeZTech

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if(commandLabel.equalsIgnoreCase("class")) {
    3. if(args.length == 0) {
    4. sender.sendMessage(ChatColor.GREEN + "/class <class>");
    5. } else {
    6. PVPType pvptype = PVPType.searchByName(args[0]);
    7. if(pvptype != null) {
    8. pvptype.applyItems(player);
    9. sender.sendMessage(ChatColor.GREEN + "You are now an" + pvptype);
    10. }
    11. }
    12. }
    13. return false;
    14. }


    Try this. I removed the 1 from onCommand, Removed the player argument, and changed the cmd.getName() to commandLabel.equalsIgnoreCase().

    Oh, and in the future. You only need one onCommand, you've made 3 different ones from what I can tell.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){
    2. if(commandLabel.equalsIgnoreCase("one"){
    3. doStuff();
    4. } else if(commandLabel.equalsIgnoreCase("two"){
    5. doOtherStuff();
    6. }
    7. }
     
  5. Offline

    BDKing88

  6. BDKing88
    Is that code in a separate class? If so, make sure to let the class implement CommandExecutor, and register the command(s) in your onEnable() method.
     
  7. Offline

    AoH_Ruthless

    BDKing88
    Paste your whole class. For one, you use the variable 'player' in your onCommand but give us no clue as to what player could be. If you paste the whole class we can help you better.
     
Thread Status:
Not open for further replies.

Share This Page