Solved Problems with AsyncPlayerChatEvent

Discussion in 'Spigot Plugin Development' started by JuanDouCore_, Jun 2, 2017.

  1. It turns out that I am trying to censor words from the configuration file with the following code:
    Code (Text):
      @EventHandler
      public void alHablar(AsyncPlayerChatEvent e)
      {
        String mensaje = e.getMessage();
        for (String listItem : this.listpalabras)
          if (mensaje.contains(listItem))
            e.setMessage("****");
      }
    But it turns out that the user at the moment of speaking in the chat if he censors the word if he says it as it is written in the configuration and if he writes the word with a capital letter no longer censored, some way to make a word censure All kind of word For example changing capital letters etc.
     
  2. mensaje.toLowerCase().contains(listItem)
     
  3. @BeastSpencer You would need to make sure the listItem is lowecase too
     
  4. Code (Java):

    if (list.stream().map(String::toLowerCase).anyMatch(s -> event.getMessage().toLowerCase().contains(s))) {
        event.setMessage("*****");
    }
     
     
    • Agree Agree x 1
  5. If you are going to do this, make sure you are on Java 8+
     
  6. Streams are so purrrtty


    Sent from my iPhone using Tapatalk
     
    • Agree Agree x 1