Solved Getting config file path as String

Discussion in 'Plugin Help/Development/Requests' started by NewDevOnTheBlock, Apr 7, 2015.

Thread Status:
Not open for further replies.
  1. Hello,

    So, I'm having a bit of trouble with getting my config file path.
            - Name1
            - Name2
            - Name3
        Group3: []
    What I'm trying to do make it so the player can type in a command like /testcommand. If they type in /testcommand Group1, then it will send them all of the players name inside of the group. What I'm having trouble with is getting Group1, Group2 or Group 3 as a String to compare to my args[0].

    Here is my currently not-working code:
    if( args[0] == getConfig().getString("Groups."))
    Thank you to everyone who helps me learn.
  2. Offline


    Is this what you're looking for?
    String playersInGroup = getConfig().getString(args[0]);
    Last edited: Apr 8, 2015
  3. Offline


  4. Would you be able to show me how this could be used? I've tried multiple different ways of using it now, but I just can't seem to get it to work. getStringList() returns a List<String>, and I need it as a String. I've be able to convert it to a String, but it's not getting the group I am testing "Group1".

    How would you use getStringList() to go into the "Groups" and then cycle through all of the groups there until it gets one that matches args[0].
  5. Offline


    @NewDevOnTheBlock Please learn basic Java before attempting Bukkit.

    Simply put: getStringList() returns a list of strings. When you say [item] or '- item' you are saying that you want a list of strings to be stored. You can use a for loop to iterate over the list, and get every string in it.
    Question: Puzzle this out in your head. You have both name1 and name2 under group1. Hypothetically, if you could just convert it to only one string, what would the string be?
  6. I ended up solving the problem.

    //This will put in a set called 'allGroups' the name of every sub-node under node Groups.
    Set<String> allGroups = this.getConfig().getConfigurationSection("Groups").getKeys(false);
        //This statement will loop through the set 'allGroups' and see if the users second argument is in the set
        if( allGroups.contains(args[0]) ) {
            //I created an ArrayList called 'playersInGroup' to get each player from the sub-nodes.
            ArrayList<String> playersInGroup = new ArrayList<>();
            playersInGroup.add(getConfig().getString( "Groups." + args[0] ) );
    Last edited: Apr 8, 2015
  7. Offline


    What does this accomplish?
    You literally just created a List<String>, after agonizing over having one and not knowing what to do with this. lol
  8. I agonized over having to deal with one, but I didn't sit here empty minded and went and created an answer.

    The getConfigurationSection().getKeys(false) sent in a Set<String> all of the sub-nodes under the node Groups. From there, I searched through that allGroups set to see if it contained args[0]. What this does it allow for the user of this plugin to enter whatever group name they want in the configuration file. I have since perfected the method to allow args[0] to be any case instead of exactly the group name.
Thread Status:
Not open for further replies.

Share This Page