Plugin Help Ignoring Capitals in config

Discussion in 'Plugin Help/Development/Requests' started by HCMatt, Apr 26, 2015.

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

    HCMatt

    I'm creating a ChatFilter that is fully customizable with commands. It all works great but if i wanted to block the word 'Test', i would also have to add 'test' to the BadWord list because it doesn't check for equalsIgnoreCase(). Is there any way around this.
    My onCommand():

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(!(sender instanceof Player)){
                sender.sendMessage(ChatColor.RED +" You must be a player.");
                return true;
            }else {
                Player p = (Player) sender;
                if(!(p.hasPermission("filter.add"))){
                    p.sendMessage(ChatColor.RED + "You do not have permission.");
                    return true;
                }else
                if(args.length != 2){
                    p.sendMessage(ChatColor.RED + "Usage: /filter add <word>");
                    return true;
                }else if(args[0].equalsIgnoreCase("add")){
                    List<String> list = (List<String>) getConfig().getList("BadWords");
                    String word = args[1];
                    if(list.contains(word)){
                        p.sendMessage(ChatColor.RED + word + " is already in the filter.");
                        return true;
                    }else {
                        list.add(word);
                        saveConfig();
                        p.sendMessage(ChatColor.GREEN + "Added " + word + " to the BadWords list.");
                        return true;
                    }
                }else if(args[0].equalsIgnoreCase("remove")){
                    List<String> list = (List<String>) getConfig().getList("BadWords");
                    String word = args[1];
                    if(list.contains(word)){
                        list.remove(word);
                        saveConfig();
                        p.sendMessage(ChatColor.GREEN + "Removed " + word + " to the BadWords list.");
                        return true;
                    }else {
                        p.sendMessage(ChatColor.RED + word + " is not in the filter and can't be removed.");
                        return true;
                    }
                }else {
                    p.sendMessage(ChatColor.RED + "Usage: /filter add <word>");
                    return true;
                }
            }
        }
     
  2. Offline

    Lolmewn

    It would probably be better to use equalsIgnoreCase, otherwise people will randomly add casing to swearwords and... well. Would kinda defeat the purpose of the plugin.
     
  3. Offline

    HCMatt

    @Lolmewn I know that, but how do i check for equalsIgnoreCase from a Config String?
     
  4. Offline

    Lolmewn

    @HCMatt Oh, I see. You can't use contains() since that's case sensitive. Instead, loop over the strings yourself and then use equalsIgnoreCase. If no match found, add it - otherwise print error like you're doing now.
     
  5. @HCMatt You can do what @Lolmewn said, you can also lower case the config and what people say (Not lowercase what is sent, just assign a lower cased message to a string). This way you can check easily if it is a bad word.
     
Thread Status:
Not open for further replies.

Share This Page