Solved Trying to detect a word through a string

Discussion in 'Plugin Development' started by Random_Tomato, Jul 15, 2016.

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

    Random_Tomato

    So basically I am trying to detect if a player has sent specific words to chat, I have got it working for individual words but I would like to get it working for multiple words which can be edited through a config.

    I know it is probably something really minor that I have messed up with but any help is much appreciated!

    Player Chat Class:
    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {
    Player player = event.getPlayer();
    String message = event.getMessage().toLowerCase();

    List<String> banned = plugin.getConfig().getStringList("Banned Words");

    if(message.contains(banned)) {
    event.setCancelled(true);
    player.sendMessage("That is a naughty word");

    Config:
    Banned Words:
    - Tomato
    - Melon
    - Stawberries


    -Random
     
  2. Offline

    thapengwin

    Use a for loop to iterate the banned messages.
     
Thread Status:
Not open for further replies.

Share This Page