Commands Sounds Easy Right?

Discussion in 'Plugin Development' started by DeadlyDeath001, Apr 16, 2015.

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

    DeadlyDeath001

    I want to add 3 commands in one Main class. Does Not Work
    "fm-off"
    "fm-on"
    "fm [Message]"
    Code:
        public boolean onCommand(CommandSender sender, Command command, String cmd, String[] args) {
    
    
            if (command.getName().equals("fm")) {
                if (!(sender instanceof Player)) {
                    if (args.length == 0) {
                        sender.sendMessage(ChatColor.DARK_RED + "You need to type in a message!");
                    } else {
                        getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Material-BroadCast-Prefix") + message(args)));
                    }
                } else {
                    Player p = (Player) sender;
                    if (!p.hasPermission("funnymine.bc")) {
                        sender.sendMessage(ChatColor.DARK_RED
                                + "You do not have access to that command!");
    
                    } else if (args.length == 0) {
                        p.sendMessage(ChatColor.DARK_RED + "You need to type in a message!");
                    } else {
                        getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Material-BroadCast-Prefix") + message(args)));
                    } else if (command.getName().equalsIgnoreCase("fm-off"))
                        this.getConfig().set("BroadCast", false);
                    sender.sendMessage("BroadCasting Is Off");
      
                    } else if (args[0].equalsIgnoreCase("fm-on")) {
                        this.getConfig().set("BroadCast", true);
                        sender.sendMessage("BroadCasting Is On");
          
          
          
            }
            return true;
        }
        
     
  2. Offline

    dlange

  3. Offline

    mine-care

    @DeadlyDeath001 Does not work is general, what does it do when you perform the command, error? nuthing?
     
  4. Offline

    Scullyking

    @dlange
    Not helpful, if they did write the code they gave, they have a good enough understanding of java to make bukkit plugins (at least simple ones).

    @DeadlyDeath001
    Please go into detail on the error, would should happen, what isn't happening, etc.
     
  5. @Scullyking Disagreed. For anyone with sufficient Java knowledge, it's fairly apparent at least some of the problems with this.


    @DeadlyDeath001 As @dlange says, you probably need to learn more about Java if you can't see what's wrong with this. Here's a hint: Indentation is there to help you - use it ;) Also, this doesn't compile according to what you've given us.
     
  6. Offline

    dlange

    arguments are the things after the command like this: /<command> args[0] args[1] etc But when you check the length of the args it is /0 1 2 3 and so on.
     
  7. Offline

    Booshayy

    Did you extend JavaPlugin? You didn't include everything in the class so I'm not sure what the real problem is. Also make sure to use

    Code:
    if (command.getName().equalsIgnoreCase("command") {
    This ensures that no matter in what cases the command is typed that the command will still execute.

    Also, do you have a plugin.yml? Furthermore, is there a stack trace when you try to run the plugin?

    Update: Ignore that^ I looked at your syntax and it's making me cringe. I'll post the proper code with what you did wrong to help you out in a couple hours when I get off work. So sit tight or someone else here might help you before I can.
     
    Last edited: Apr 18, 2015
Thread Status:
Not open for further replies.

Share This Page