Creating a config that has a word list

Discussion in 'Plugin Development' started by Iguana, Mar 26, 2014.

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

    Iguana

    I'm trying to make a plugin that generates weapons with randomized names and can't quite grasp the code behind making the plugin generate the config file with the sections for prefixes, suffixes, nouns, etc.

    I was just wondering how one would go about getting the plugin to create a config.yml with a prefixes section and for the plugin to be able to read it.
     
  2. Offline

    NonameSL

    Iguana
    How to create a config that has a world list:
    First, there is getConfig() to get the config, reloadConfig() to reload, and saveConfig() to save it in the JavaPlugin class.

    in onEnable what you want to do is to set the list of worlds (Bukkit.getServer().getWorlds()) in the config as worlds like this:
    Code:
    getConfig().addDefault("worlds", Bukkit.getServer().getWorlds());
    reloadConfig();
    and in onDisable to save the config.
    Code:
    saveConfig();
    How to get objects from the config:
    There are many ways you can get objects:
    getConfig().get(String path); will return an Object.
    getConfig().getBoolean(String path); will return a boolean,
    getConfig().getColor(String path); will return a Color
    and so on:
    getBooleanList, getByteList, getCharacterList, getFloatList, getDouble, getDoubleList, getInt, getIntegerList, getItemStack, getList, getLong, getLongList, getMapList, getString, and getStringList.

    You can also use getKeys() to get the keys.

    Now, if you want to get the world list we setted earlier as "worlds", we need to use the getConfig().getList("worlds"); to return a list.
     
Thread Status:
Not open for further replies.

Share This Page