Configuration file help!!

Discussion in 'Plugin Development' started by TheEyeMonster, Oct 1, 2013.

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

    TheEyeMonster

    Hey guys,

    My configuration file:

    Code:
    Motds:
           - Motd1
           - Motd2
           - Motd3
    
    My configuration code:

    [​IMG]

    What I want:

    A code that gets the amount of Motds typed into the configuration file, and then random chooses one of these.
     
  2. TheEyeMonster
    Well you'd get the size with this
    Code:
    int size = getConfig().getStringList("Motds").size();
    Then to select a random
    Code:
    String random = getConfig().getStringList("Motds").get(new Random().nextInt(size));
     
  3. Offline

    TheEyeMonster

    Thank you Assist, will try it right now!

    How can I fix this, I don't understand why its giving this error.

    [​IMG]

    Fixed that error, but how can I use the "random" in a different class?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. TheEyeMonster
    Make a global variable (null for now), then on loadConfiguration, set it equal to the random string.
    Code:
    // somewhere up in your class
    public static String random; 
     
    // somewhere down in your class
    public void loadConfiguration() {
    // other stuff
    random = getConfig().getStringList("Motds").get(new Random().nextInt(size));
    // other stuff
    }
    Then in another class, you can get the string with, for example, if your main class (or the class the string is in) is called Main
    Code:
    String random = Main.random;
     
Thread Status:
Not open for further replies.

Share This Page