*Help* Sending a Player a StringList from a config file

Discussion in 'Plugin Development' started by SuperOriginal, Feb 10, 2014.

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

    SuperOriginal

    So i've been working on a simple /vote plugin where it sends the player a list of links that is defined in a config file. The problem is it only sends the player the first item in the list rather than the entire list.

    I've stripped the code down to the basics here:

    Code:java
    1. public void onEnable(){
    2. getConfig().options().copyDefaults(true);
    3. saveConfig();
    4. }
    5.  
    6. public boolean onCommand(CommandSender sender, Command cmd, String label, String [] args) {
    7. List<String> links = getConfig().getStringList("links");
    8. Player p = (Player) sender;
    9. if(cmd.getName().equalsIgnoreCase("vote")){
    10. if(args.length == 0){
    11. for(String link : links){
    12. p.sendMessage(link);
    13. return true;
    14. }
    15. }
    16. }


    The config is simply
    links:
    - test.com
    - test2.com

    I'm fairly new to Java so please pardon me if the answer is right in front of my face. Thanks!
     
  2. Offline

    xTigerRebornx

    supercube101 Since you are returning inside the for loop, it returns at the end of the first link. Take the returning out of your for loop
     
  3. Offline

    SuperOriginal

Thread Status:
Not open for further replies.

Share This Page