Anti Swear Extension Problem

Discussion in 'Spigot Plugin Development' started by mamaie, Aug 13, 2018.

  1. Hello guys , i try to make a anti swear plugin but i have some problems with extensions. I don t know how make this.
    Here it s my source code : https://pastebin.com/zAhWQXze
     
  2. I don’t understand you’re trying to ask
     
  3. I haven't looked at your command method at all, but I read your event method.

    Code (Text):
    if (getConfig().getStringList("Cuvinte Interzise").contains(falsewords)) {
    What you wrote is equivalent to "does this list contain this user's exact message". So let's say a player says "What the ****". Your code checks if the list contains the message "what the ****". You list probably contains "****" but not the entire string "what the ****".

    Assuming you don't want to get into regex (which is probably the best solution if you're willing to learn it), you'll need to loop through each entry in your list and check if falsewords.contains(word).

    In pseudo code:
    Code (Text):
    for each word in dirtyWordsList{
      if userMessage.contains(word){
        //they said a dirty word! do something!
      }
    }
     
  4. What i was trying to say was that my plugin blocks "f***" but not "f***kkkkkkkkkkkk", like with more than one letter
     
  5. Maybe I can explain this better.

    Code (Text):
    if (getConfig().getStringList("Cuvinte Interzise").contains(falsewords))
    Take a look at what contains() does for lists.
    https://docs.oracle.com/javase/8/docs/api/java/util/List.html#contains-java.lang.Object-

    It looks at each element in the list and checks if it is equal to the object you gave it. In this example, it would check if "f***".equals("f***kkkkkkkkkkkk"). Those strings are not equivalent so that statement would be false.

    What you want to use is string.contains()
    https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#contains-java.lang.CharSequence-
    Check to see if the user message contains a listed word: "f***kkkkkkkkkkkk".contains("f***")

    In order to check every word on the list, loop through the list.