Solved Get values from a list in the config

Discussion in 'Plugin Development' started by CheesyFreezy, Jan 22, 2015.

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

    CheesyFreezy

    Heey heey developers!

    How am i supposed to get all the values from a list in a config.
    What i want is to make a plugin where people can't swear, so they can add there own banned words in the config but i want to make something like this:
    Code:
    if(event.getMessage().contains(/*all values from list*/)) {
       event.setCancelled(true);
       player.sendMessage("You just sweared!");
    } else {
      event.setCancelled(false);
     
  2. Offline

    sirrus86

    You'll want to iterate over all of the words in the config and see if the message contains any of them... Basically a for-loop before your conditional.
     
  3. Offline

    CheesyFreezy

    @sirrus86
    The only thing that works for me is this:

    Code:
    for(Object bannedWords : core.getConfig().getList("BANNED_WORDS")) {
       if(event.getMessage().contains(bannedWords.toString())) {
          event.setCancelled(true);
          player.sendMessage("You just sweared!");
       } else {
          event.setCancelled(false);
       }
    }
     
  4. Offline

    CraftCreeper6

    @CheesyFreezy
    Change the first line to for(String bannedWords : core.getConfig().getStringList("BANNED_WORDS")){

    You are iterating over an object... it's not at all necessary.
     
  5. Remove dis :
    Code:java
    1.  
    2. else {
    3. event.setCancelled(false);
    4. }
    5.  
     
  6. Offline

    CheesyFreezy

  7. Offline

    CraftCreeper6

  8. Offline

    CheesyFreezy

  9. Offline

    CraftCreeper6

Thread Status:
Not open for further replies.

Share This Page