Solved Command problems... again

Discussion in 'Plugin Development' started by Techy4198, Nov 4, 2013.

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

    Techy4198

    I remember something like this happening before to me, and I think I made a thread about it, but I decided a new thread is the best idea. so, straight down to business. I have made a custom command executor class but it keeps giving me the 'usage' message set in the plugin.yml. here is the class:
    Show Spoiler
    Code:
    package me.conormcs.astrocraft.signs;
     
    import java.util.List;
    import java.util.regex.Pattern;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class CommandExecutorACS implements CommandExecutor {
        public Main plugin;
     
        public CommandExecutorACS(Main main) {
            plugin = main;
        }
     
        Pattern hex = Pattern.compile("^[0-9A-Fa-f-]+$");
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("astrocraftsigns")){
                if (sender instanceof Player) {
                    if(args.length != 0){
                        if(args[0].equalsIgnoreCase("color")){
                            if(args.length == 2){
                                if(hex.matcher(args[1]).matches() && args[1].length() == 4){
                                    char[] colors = args[1].toCharArray();
                                    if(colors[0] == '-'){
                                        colors[0] = plugin.getConfig().getString("Colors.Line").charAt(0);
                                    }
                                    if(colors[1] == '-'){
                                        colors[1] = plugin.getConfig().getString("Colors.Bracket").charAt(0);
                                    }
                                    if(colors[2] == '-'){
                                        colors[2] = plugin.getConfig().getString("Colors.Astro").charAt(0);
                                    }
                                    if(colors[3] == '-'){
                                        colors[3] = plugin.getConfig().getString("Colors.Craft").charAt(0);
                                    }
                                    plugin.getConfig().set("Colors.Line", colors[0]);
                                    plugin.getConfig().set("Colors.Bracket", colors[1]);
                                    plugin.getConfig().set("Colors.Astro", colors[2]);
                                    plugin.getConfig().set("Colors.Craft", colors[3]);
                                    plugin.getConfig().options().copyDefaults(true);
                                    plugin.reloadConfig();
                                    plugin.saveConfig();
                                    sender.sendMessage("");
                                    sender.sendMessage(Header(plugin));
                                    sender.sendMessage(ChatColor.GREEN + "Colors set.");
                                    sender.sendMessage(Header(plugin));
                                    sender.sendMessage("");
                                    return true;
                                }
                                return false;
                            }
                            return false;
                        } else if(args[0].equalsIgnoreCase("test")){
                            List<String> chatLines = plugin.getConfig().getStringList("Test");
                            sender.sendMessage("");
                            sender.sendMessage(Header(plugin));
                            for(String s : chatLines){
                                String message = ChatColor.translateAlternateColorCodes('¬', s);
                                sender.sendMessage(message);
                            }
                            sender.sendMessage(Header(plugin));
                            sender.sendMessage("");
                            return true;
                        } else return false;
                    } else return false;
                } else {
                    sender.sendMessage("Only ingame players may configure AstroCraft Signs");
                }
            }
            return true;
        }
       
        public String Header (Main plugin){
            String lineColor = plugin.getConfig().getString("Colors.Line");
            String lineColor2 = "e";
            if(hex.matcher(lineColor).matches() && lineColor.length() == 1){
                lineColor2 = lineColor;
            }
            String bracketColor = plugin.getConfig().getString("Colors.Brackets");
            String bracketColor2 = "1";
            if(hex.matcher(bracketColor).matches() && bracketColor.length() == 1){
                bracketColor2 = bracketColor;
            }
            String astroColor = plugin.getConfig().getString("Colors.Astro");
            String astroColor2 = "6";
            if(hex.matcher(astroColor).matches() && astroColor.length() == 1){
                astroColor2 = astroColor;
            }
            String craftColor = plugin.getConfig().getString("Colors.Craft");
            String craftColor2 = "e";
            if(hex.matcher(craftColor).matches() && craftColor.length() == 1){
                craftColor2 = craftColor;
            }
            StringBuilder header = new StringBuilder();
            header.append(ChatColor.getByChar(lineColor2) + "--------");
            header.append(ChatColor.getByChar(bracketColor2) + "[");
            header.append(ChatColor.getByChar(astroColor2) + "Astro");
            header.append(ChatColor.getByChar(craftColor2) + "Craft");
            header.append(ChatColor.getByChar(bracketColor2) + "]");
            header.append(ChatColor.getByChar(lineColor2) + "--------");
            return header.toString();
        }
    }

    huge and messy I know. It's for my friend's server by the way. I need help with this ASAP.
     
  2. Offline

    MrSparkzz

    Techy4198
    There are a lot of
    Code:java
    1. } else return false;

    Maybe you messed up on one? Also you should have syntax highlighting turned on. In your syntax bracket thingy after "syntax" type =java
     
  3. Offline

    sd5

    Best solution would be to add a System.out.println("x"); before every return false. Replace the x with numbers, then you will exactly know where the command breaks...
     
    MrSparkzz likes this.
  4. Offline

    MrSparkzz

    sd5
    I love doing that, it's so helpful. I use my own custom logger instead of System.out
     
  5. Offline

    Techy4198

    wow so much help so fast. I won't use java syntax, and I would prefer if nobody else did, because you can't easily copy and paste from them. I have checked the return false things about 100 times, I will add some debug outputs.

    not ONE of the debug messages ever gets outputted. a bit weird.

    CRAPPER. I realised the problem. I put it as AstroCraftSigns in the executor and when registering in the main class, but I put AstroCraftSign in the plugin.yml XD

    Code:
    this.setThreadStatus(HelpThreadStatus.SOLVED);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page