Commands not working

Discussion in 'Plugin Development' started by AcePilot10, Feb 28, 2015.

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

    AcePilot10

    So I made this simple FakeJoin plugin. Basically when you type /fj it will send a help message, when you type /fj join <player> it will broadcast the player has joined the server, and the same with /fj leave <player>. The problem is that whenever I attempt to run the commands nothing happens. I don't get any error or "unkown command" just nothing happens. Here's my code:
    Code:
    package me.AcePilot10.FakeJoin;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    
    public class Commands {
       
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args) {
           
            if(label.equalsIgnoreCase("fj") || sender.hasPermission("fj.use")) {
                sender.sendMessage("[" + ChatColor.GRAY + "FakeJoin" + ChatColor.WHITE + "]" + ChatColor.GREEN + " Help for FakeJoin");
                sender.sendMessage(ChatColor.BLUE + "/fj join (player)");
                sender.sendMessage(ChatColor.BLUE + "/fj leave (player)");
            } 
            if(label.equalsIgnoreCase("fj join") || args.length == 1 || sender.hasPermission("fj.use")) {
                Bukkit.broadcastMessage(ChatColor.YELLOW + "" + args[1] + " has joined the game");
                } else {
                    sender.sendMessage("[" + ChatColor.GRAY + "FakeJoin" + ChatColor.WHITE + "]" + ChatColor.RED + " Error in syntax, use /fj to see a list of commands!");
                    return true;
                }
              if(label.equalsIgnoreCase("fj leave") || args.length == 1 || sender.hasPermission("fj.use")) {
                    Bukkit.broadcastMessage(ChatColor.YELLOW + "" + args[1] + " has left the game");
            } else {
                sender.sendMessage("[" + ChatColor.GRAY + "FakeJoin" + ChatColor.WHITE + "]" + ChatColor.RED + " Error in syntax, use /fj to see a list of commands!");
                return true;
            }
              return false;
        }   
    }
     
  2. Datdenkikniet likes this.
  3. Offline

    SuperOriginal

    Use command.getName() instead of label as well.
     
  4. also: commands can't contain spaces (fj leave for instance). You have to use arguments instead.
     
  5. Offline

    AcePilot10

    Thanks so much guys!!!!!!!
     
Thread Status:
Not open for further replies.

Share This Page