Solved Send the player strings which are in the config?

Discussion in 'Plugin Development' started by Cherwin1, Apr 22, 2014.

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

    Im busy with my plugin "RewardVoting".

    I want to make it that when a player does /vote
    it will show the amount of votesites which are in the config!

    But how do you do that?

    [Config]
    Votesites:
    - "http://www.google.com/"
    - "htttp://www.example.com/"

    So it shows the player two(or more) vote sites like this

    Vote sites:
    http://www.google.com/
    http://www.example.com/

    if i do 'sender.sendMessage(getConfig.getString("votesites"));'
    it shows them like this: [http://www.google.com/ , http://www.example.com/]

    Please help me!

    Thanks,
    Cherwin1
     
  2. Offline

    TrollTaylor

    Try adding this to the end of the getString
    Code:
    .replace("[", "").replace("]", "")
     
  3. Thanks

    Do you know how i can get them under each other?
    So it is not like "votesite1, votesite2, votesite3 etc"
     
  4. Offline

    TrollTaylor

    Cherwin1 You would have to send multiple messages so like i dont know if this will work tough
    Code:java
    1. sender.sendMessage(getConfig.getString("votesites").get(1));
    2. sender.sendMessage(getConfig.getString("votesites").get(2))
    3. sender.sendMessage(getConfig.getString("votesites").get(3));;
     
  5. Nope doesn't work :(

    Please help!
    It still displays the text like this: Votesite1, Votesite2, Votesite3 etc

    The code is:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("vote")){
    2. sender.sendMessage(ChatColor.BLACK + "[" + ChatColor.GOLD + ChatColor.BOLD + getConfig().getString("votename") + ChatColor.RESET + ChatColor.BLACK + "] " + ChatColor.WHITE + ChatColor.BOLD + "vote links:");
    3. sender.sendMessage(config.getString("votesites").replace("[", "").replace("]", ""));
    4. return true;
    5. }


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

    pure1101

    you have to use config.getStringList like:
    Code:java
    1. sender.sendMessage(config.getStringList("votesites").get(1));
    2. sender.sendMessage(config.getStringList("votesites").get(2));
    3. sender.sendMessage(config.getStringList("votesites").get(3));
     
  7. Offline

    Wizehh

    Better yet:
    PHP:
    for (int i 0config.getStringList("votesites").length()) {
        
    sender.sendMessage(config.getStringList("votesites").get(i);
    }
     
  8. Wizehh

    I get an error on this line

    for (int i = 0; i < config.getStringList("votesites").length()) {

    The error is:
    Multiple markers at this line
    - Syntax error on token ")", ; expected after this token
    - Line breakpoint:VoteForReward [line: 250] - onCommand(CommandSender, Command, String,
    String[])
    - The method length() is undefined for the type List<String>

    Please help me!
     
  9. Offline

    pure1101

    :p even better:
    Code:java
    1. for(String vs : config.getStringList("votesites")){
    2. sender.sendMessage(vs);
    3. }


    ah wizehh forgot the third section of the for loop, it should look like this:
    Code:java
    1. for(int i = 0; i < config.getStringList("votesites").size(); i++){


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  10. Wizehh pure1101

    Thank you guys for the good help!

    but one more thing :( i cant put "return true;" under the sendMessage then it will only show 1 vote site

    But if i dont do that it will say /vote under it
    Help me one more time please :D
     
  11. Offline

    Wizehh

    Just place the return true outside of the loop.
     
  12. Oh didnt think about that lol
    im so dumb :/ haha

    Thanks for your help!
    i appreciate it alot!
    _______
    Cherwin1
     
Thread Status:
Not open for further replies.

Share This Page