Solved Word filter. Please help.

Discussion in 'Plugin Development' started by Aljed_The_Legit, Apr 20, 2014.

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

    Aljed_The_Legit

    Here is an example from config:
    Filtered-Message:
    # Check if player typed in a message. Then send them a message.
    - Hi, '&bHello'

    This is a plugin I have been developing. I'm wondering how I can make this possible.
     
  2. Offline

    clmcd42

    I'm not really sure what you're describing. You want to check when a player sends a certain message into chat and then send him a message from the config when he does? If so, you need to use EventHandler, probably AsyncPlayerChatEvent
     
  3. Offline

    Aljed_The_Legit

    Alright, I knew this would happen. xD
    What I'm trying to describe is when a player says a filtered word like 'Fuck, &bHEY! No swearing!' after the comma is the message that will be sent to the player.
     
  4. Offline

    clmcd42

    Oh. Well, you're still gonna want to user AsyncPlayerChatEvent, but you should set up your config more like this to make for easier separating of filtered word and message:
    Code:
    filtered-message:
      hi: 'message'
      bye: 'message'
    That way you don't have to hard code the separation of the word from the message. Do you understand how to use the events and everything?
     
  5. Offline

    Aljed_The_Legit

    Code:
    for (String word : this.getConfig().getConfigurationSection("Filtered-Words").getKeys(false)) {
    if (event.getMessage().contains(word.toLowerCase()) {
    player.sendMessage(this.getConfig().getString(word);
    }
    }
    
    ?
     
  6. Offline

    Th3Br1x

    Yes. But you should replace the 'bad word' or prevent the message to get send :)
     
  7. Offline

    clmcd42

    Almost.
    Code:java
    1. for(String word : this.getConfig().getConfigurationSection("Filtered-Words").getKeys(false)) {
    2. if(event.getMessage().toLowerCase().contains(word.toLowerCase())) {
    3. player.sendMessage(this.getConfig().getString("Filtered-Words." + word);
    4. event.setCancelled(true);
    5. }
    6. }


    Notice that you would have to compare the message and the word in the same case, because players are likely to figure out they can mix up the case to get around it. Also the event has to be cancelled if you want to stop the message from going to the server. Lastly, the getString() call has to have "Filtered-Words." at the beginning in order for it to know what you're talking about.
     
  8. Offline

    Aljed_The_Legit

    Alright, thank you.
     
Thread Status:
Not open for further replies.

Share This Page