Filter System

Discussion in 'Spigot Plugin Help' started by LazerShadow, Sep 22, 2015.

  1. I have a filter system, and it works fine except for one part.

    Its kind of hard to explain so let me show some examples.

    I'm using a config to save the words.

    If in the config the list goes like:
    - bad
    - badword
    - thisbadword

    and I chat bad that badword thisbadword
    it comes out *** that ***word this***word.

    So it chooses the first word when looping through the config and I need to to check the whole config file.

    Code (Java):
    public static String censorMsg(String message)
        {

            for (String str : Main.config.getStringList("Censored-Word-List"))
            {
                if (message.contains(str))
                {
                    String censor;
                    StringBuilder strBuilder = new StringBuilder();
                    for (int i = 0; i < str.length(); i++)
                    {
                        strBuilder.append("•");
                    }
                    censor = strBuilder.toString();
                    message = message.replaceAll(str, censor);
                }
            }
            return message;
        }
     
  2. Right? What's the problem?
     
  3. It doesn't filter the whole word. So if I had bad and badword filtered and someone typed badword it would only filter the bad part of it and not the whole badword
     
  4. You Need to split the message string into an Array (or List) of words first (Split by space sign). Then check if any element of your Array (/ List) contains the "bad part". If it does, clear or remove the complete Array element. After all, put your string back together out of all left elements.
    Btw. this thread should be moved here: https://www.spigotmc.org/forums/spigot-plugin-development.52/.
    It's about development, not help for existing plugins.