One command works, the other not so much

Discussion in 'Plugin Development' started by gamelord327, May 8, 2013.

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

    gamelord327

    I'm trying to get some commands to work in my plugin but only one is working. The idea is to get a command to change my custom login/out message in-game. The problem is that /cm set join <message> is working /cm set quit <message> is not working. Here is some of my code:

    My CommandCM.java:

    Code:
    package com.adam.custommessage;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
     
    public class CommandCM implements CommandExecutor{
     
        Main plugin;
     
        public CommandCM(Main instance){
            plugin = instance;
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("cm")){
                if(args.length > 0){
                    if(args[0].equalsIgnoreCase("reload")){
                        plugin.reloadConfig();
                        sender.sendMessage(ChatColor.GREEN + "[customMessage] Config has now been reloaded successfully!");
                        return true;
                    }
                }
            }
           
            if(args[0].equalsIgnoreCase("set")){
                if(args[1].equalsIgnoreCase("join")){
                    if(args.length > 2){
                        StringBuilder sb = new StringBuilder();
                        for(int i = 2; i < args.length; i++){
                            sb.append(args[i]).append(' ');
                        }
                        plugin.getConfig().set("onJoin", sb.toString());
                        plugin.getServer().getLogger().info(sb.toString());
                        plugin.saveConfig();
                        sender.sendMessage(ChatColor.GREEN + "[customMessage] Global Join Message has been changed!");
                        return true;
                    }
                }
                }
            if(args[0].equalsIgnoreCase("set")){
                if(args[3].equalsIgnoreCase("quit")){
                    if(args.length > 4){
                        StringBuilder sb = new StringBuilder();
                        for(int i = 4; i < args.length; i++){
                            sb.append(args[i]).append(' ');
                        }
                        plugin.getConfig().set("onQuit", sb.toString());
                        plugin.getServer().getLogger().info(sb.toString());
                        plugin.saveConfig();
                        sender.sendMessage(ChatColor.GREEN + "[customMessage] Global Quit Message has been changed!");
                        return true;
                    }
                }
                    return false;
    }
            return false;}}
    And my plugin.yml:

    Code:
    name: customMessage
    main: com.adam.custommessage.Main
    version: 1.2.1
     
    commands:
      cm:
        description: Commands to customMessage
        usage: /cm ?
     
      cm.reload:
        description: Allows you to use /cm reload.
        default: op
       
      cm.set.join:
        description: Allows you to use /cm set.
        default: op
         
      cm.set.quit:
        description: Allows you to use /cm set.
        default: op
    Please let me know what's happening as im still learning everything and i have tried a few ways of doing this but still cant fix it.
     
  2. Offline

    kreashenz

    One of the brackets in the top part (reload part) is out of place. Remove one, then place it on the bottom of the join part..
     
Thread Status:
Not open for further replies.

Share This Page