Command only returning usage

Discussion in 'Plugin Development' started by SpongyBacon, Jan 20, 2014.

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

    SpongyBacon

    Hey!
    So i've setup a command with a few arguments for the first time, and when I type any of the commands or arguments, it just returns '/attack'.

    Here's my code:
    Code:
    package me.SpongyBacon.Attack;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
       
        public void onEnable(){
            getLogger().info("Attack has been enabled!");
        }
       
        public void onDisable(){
            getLogger().info("Attack has been disabled!");
        }
       
        public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args){
            Player player = (Player) sender;
            Location bl = (Location) player.getEyeLocation().getBlock().getLocation();
            if(cmd.getName().equalsIgnoreCase("attack")){
                sender.sendMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " Attack is a plugin built by SpongyBacon, to summon attacks of mobs on your command!\nUse" + ChatColor.RED + " /attack help" + ChatColor.GOLD + " to use this plugin!");
                if(args.length == 1){
                    if(args[0].equalsIgnoreCase("help")){
                        sender.sendMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " Commands:\n"
                                + ChatColor.RED + "/Attack Summon" + ChatColor.GOLD + " - Allows you to summon an attack where you are looking at!\n"
                                + ChatColor.RED + ChatColor.STRIKETHROUGH + "/Attack Menu" + ChatColor.RESET + ChatColor.GOLD + " - COMING SOON! Compelete GUI menu of Attack!"
                                + ChatColor.RED + ChatColor.STRIKETHROUGH + "/Attack Summon <player>" + ChatColor.RESET + ChatColor.GOLD + " - COMING SOON! Allows you to summon an attack at a players location!");
                    }else if(args[0].equalsIgnoreCase("summon")){
                        sender.sendMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " In order to summon an attack you must use one of the following...\n"
                                + ChatColor.RED + "/Summon ALL" + ChatColor.GOLD + " - Summons ALL implimented mobs\n"
                                + ChatColor.RED + "/Summon zombies" + ChatColor.GOLD + " - Summons a horde of zombies\n"
                                + ChatColor.RED + "/Summon creepers" + ChatColor.GOLD + " - Summons a horde of creepers\n"
                                + ChatColor.RED + "/Summon skeletons" + ChatColor.GOLD + " - Summons a horde of skeletons\n"
                                + ChatColor.RED + "/Summon endermen" + ChatColor.GOLD + " - Summons a horde of endermen\n"
                                + ChatColor.RED + "/Summon spiders" + ChatColor.GOLD + " - Summons a horde of spiders\n");;
                        if(args.length == 2){
                            if(args[1].equalsIgnoreCase("all")){
                                Bukkit.broadcastMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " An attack of" + ChatColor.RED + " All available mobs" + ChatColor.GOLD + " has been summoned by " + ChatColor.RED + sender.getName() + ChatColor.GOLD + "!");
                                //SPAWN ALL THE MOBS :P
                            }else if(args[1].equalsIgnoreCase("zombies")){
                                Bukkit.broadcastMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " An attack of" + ChatColor.RED + " Zombies" + ChatColor.GOLD + " has been summoned by " + ChatColor.RED + sender.getName() + ChatColor.GOLD + "!");
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ZOMBIE);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ZOMBIE);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ZOMBIE);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ZOMBIE);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ZOMBIE);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ZOMBIE);
                            }else if(args[1].equalsIgnoreCase("creepers")){
                                Bukkit.broadcastMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " An attack of" + ChatColor.RED + " Creepers" + ChatColor.GOLD + " has been summoned by " + ChatColor.RED + sender.getName() + ChatColor.GOLD + "!");
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.CREEPER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.CREEPER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.CREEPER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.CREEPER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.CREEPER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.CREEPER);
                            }else if(args[1].equalsIgnoreCase("skeletons")){
                                Bukkit.broadcastMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " An attack of" + ChatColor.RED + " Skeletons" + ChatColor.GOLD + " has been summoned by " + ChatColor.RED + sender.getName() + ChatColor.GOLD + "!");
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SKELETON);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SKELETON);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SKELETON);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SKELETON);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SKELETON);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SKELETON);
                            }else if(args[1].equalsIgnoreCase("endermen")){
                                Bukkit.broadcastMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " An attack of" + ChatColor.RED + " Endermen" + ChatColor.GOLD + " has been summoned by " + ChatColor.RED + sender.getName() + ChatColor.GOLD + "!");
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ENDERMAN);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ENDERMAN);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ENDERMAN);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ENDERMAN);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ENDERMAN);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.ENDERMAN);
                            }else if(args[1].equalsIgnoreCase("spiders")){
                                Bukkit.broadcastMessage(ChatColor.RED + "[Attack]" + ChatColor.GOLD + " An attack of" + ChatColor.RED + " Spiders" + ChatColor.GOLD + " has been summoned by " + ChatColor.RED + sender.getName() + ChatColor.GOLD + "!");
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SPIDER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SPIDER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SPIDER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SPIDER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SPIDER);
                                ((Block) bl.getDirection()).getWorld().spawnEntity(bl, EntityType.SPIDER);
                            }
                        }
                       
                    }
                }
            }
            return false;
        }
     
    }
    
     
  2. Offline

    Jentagh

    Maybe try returning true?
     
  3. Offline

    Haribo98

    Haven't done this in a long while, since I use sk89q's command framework nowadays, but I do believe you still have to extends CommandExecutor, and registerCommand("name") in onEnable().

    wow >.>

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page