Solved Chat Filter

Discussion in 'Plugin Development' started by Irantwomiles, Jun 16, 2015.

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

    Irantwomiles

    Hello Everyone, So I've recently been using AsyncPlayerChatEvent and I've been trying to make a chat filter of some sort. This is what I currently have
    Code:
    
    List<String> list = Arrays.asList("fuck", "bitch");
        CharSequence[] cuss = list.toArray(new CharSequence[list.size()]);
    if(event.getMessage().contains(cuss)) {
                   
                }
    but for some reason, the #contains(CharSequence) doesnt accept an array of CharSequences. Any Idea on how I would go about this?

    And I didn't post everything. The List and CharSequence is in the Global space and the if statement is in my Method.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  2. Offline

    TheWolfBadger

    @Irantwomiles Why not?:
    Code:
    String cuss = "multiple, curses, here, separated, by, the, commas";
    String[] cussWords = cuss.split(", ");
    for(String strings : cussWords) {
    if(event.getMessage().contains(strings) {
    // Kick them or whatever you want to punish them for
    break;
        }
    }
     
    Irantwomiles likes this.
  3. Offline

    Irantwomiles

    Ahh didnt even try that way *facepalm* ty. imma give it a go.

    @TheWolfBadger Thanks that worked! Ill mark as solved!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  4. Offline

    TheWolfBadger

    Irantwomiles likes this.
  5. Offline

    RingOfStorms

    uh, why did you make a string and then split it immediately afterword for no reason at all?

    What's wrong with
    Code:
    String[] cussWords = new String[] {"curse", "words", "here"};
    
    Making a long string and then regex splitting is very much a waste of time and overhead that provides little to no benefit as far as I can tell.
     
    TheWolfBadger likes this.
  6. Offline

    TheWolfBadger

    @RingOfStorms I wasn't optimizing it. That way would work too. I was working from my phone, so I just gave information from what I remembered. That is totally a less time sorting matter though and would optimize it much.
     
Thread Status:
Not open for further replies.

Share This Page