Solved Checking if a world is in the config

Discussion in 'Plugin Development' started by XXLuigiMario, Jul 12, 2014.

Thread Status:
Not open for further replies.
  1. I'm trying to check if the world is in a string list in the config with this:

    1. public boolean isWorldBlocked(String world, String plugin){
    2. for(String w : getConfig().getStringList("List." + plugin + ".Worlds")){
    3. if (w.equalsIgnoreCase(world) || w.equalsIgnoreCase("all")){
    4. return true;
    5. }
    6. }
    7. return false;
    8. }

    But It doesn't seem to be working, it always returns false.

    My config:

    1. Plugin:
    2. Message: 'This plugin is not enabled in %w'
    3. Worlds: all


    Oh and, by the way, how do I set more than 1 word in a string list in a config, for example:
    getConfig().set("List." + plugin + ".Worlds", "World1"); and then
    getConfig().set("List." + plugin + ".Worlds", "World2");
    so it looks like this in the config:
    Worlds: [world1, world2]
  2. I think all is not a string in your config.
  3. I have this on my onEnable():
    1. getConfig().addDefault("List.Plugin.Worlds", "all");
  4. Offline


    You've misspelt "Plugin" on line 2 (it's capitalised in your config). Also, that's not how you format a list. I suggest you read this page for more information; it should answer your other question too.
  5. Offline


    XXLuigiMario, Do getConfig().set("List.Plugin.Worlds" + p.getWorld().getName())? or something like that.
  6. I've not misspelled it, it's a variable...
  7. Try to replace this
    1. getConfig().addDefault("List.Plugin.Worlds", "all");
    1. ArrayList<String> list = new ArrayList<String>();
    2. list.add("all");
    3. getConfig().addDefault("List.Plugin.Worlds", list);
  8. Nvm, I fixed it.
    Although I would like to know how to format it like I asked in the OP. (I know it's possible, i've seen plugins do it)
    So I'll leave this open.

    Just saw your reply, I did this: List<String> world = Arrays.asList("all");

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 9, 2016
  9. Offline


    Oh wow, sorry; I don't know what I was thinking. Now I feel pretty stupid :p

    Anyway, I don't think whatever that other plugin created is a list (that's not to say it isn't possible to do, though). Lists look like this in a config:
        - World1
        - World2
    Here's how I'd add to the above:
    1. List<String> theList = getConfig().getStringList("List.Plugin.Worlds");
    2. theList.add("World1");
    3. getConfig().set("List.Plugin.Worlds", theList);
    4. saveConfig();
  10. dsouzamatt thanks for your reply, I already fixed that, but I don't know what's better, if the thing you posted or what I'm doing (read my previous post)
  11. Offline


    There's no real difference as far as I know, just make sure you remember to add saveConfig() to the end of your code if you use it.
  12. Ok, I won't forget that :p
Thread Status:
Not open for further replies.

Share This Page