Getting Configuration Values

Discussion in 'Plugin Development' started by zakarls, Apr 18, 2014.

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

    zakarls

    How would I get configuration values from a list in the config.yml file. Im not quite sure how this works. Thanks for any help given. This is what I put together but it does not work:

    Code:java
    1. List<String> blocked = plugin.getConfig().getStringList("blocked");
    2. for (String block : blocked) {
    3. if(event.getMessage().toLowerCase().contains(block)){
    4. event.setCancelled(true);
    5. }
    6. }


    Example of config file:

    BlockedWords:
    - word1
    -word2
    - word3
     
  2. Offline

    agent6262

    First off are there any errors? And second what event is this?
     
  3. Offline

    rohan576

    zakarls
    There isn't enough context for me to tell what's going on. However, I'd highly suggest loading the blocked word list in onEnable(), since all the nanoseconds it takes to get those values will eventually add up.
     
  4. Offline

    agent6262

    rohan576
    Yah for sure, you should always load all the configuration files you can in the onEnable()
     
  5. Offline

    zakarls

    agent6262 Yes. There are errors that dont allow the plugin to load. Once i comment out that part the plugin works just fine.

    rohan576 Here is more context. It is in the onPlayerChat event.

    Code:java
    1. @EventHandler
    2. public void onPlayerChat(PlayerChatEvent event){
    3. Player player = event.getPlayer();
    4. if(plugin.mute == true){
    5. if(player.isOp() || player.hasPermission("mute.bypass")){
    6.  
    7. }else{
    8. event.setCancelled(true);
    9. }
    10. }
    11.  
    12. List<String> blocked = plugin.getConfig().getStringList("blocked");
    13. for (String block : blocked) {
    14. if(event.getMessage().toLowerCase().contains(block)){
    15. event.setCancelled(true);
    16. }
    17. }
    18. }


    agent6262 I will try to do that but i dont think thats what is making the plugin not work
     
  6. Offline

    agent6262

    What does your actual config file look like? Because there could be a bug in there.
     
    zakarls likes this.
  7. Offline

    zakarls

    agent6262
    Code:
    ##Config By:Zakarls##
     
    blocked:
      - word1
      - word2
      - word3
    agent6262 Oh wow. You're right. I never thought it could be an error in there. It works now :) thanks a lot :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page