Solved How to use configuration keys with sendmessage?

Discussion in 'Plugin Development' started by OkinawaBoss, Nov 2, 2015.

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

    OkinawaBoss

    Before I get started, I don't have an extremely extensive knowledge of java. So without further adieu.
    For now lets say this is my config file:
    Code:
    list:
      '1':
        1: hello
        2: how
        3: are
      '2':
        1: you
        2: doing
        3: today
    And lets say this is my code
    Code:
                    for(String key : getConfig().getConfigurationSection("list").getKeys(false)){
                        String one = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("list."+key+".1"));
                        String two = getConfig().getString("list."+key+".2");
                        String three = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("list."+key+".3"));
    
    
                    new FancyMessage("")
                        .then(one)
                        .then(two)
                        .then(three)
                        .send(player);
                   
                   
                    }
    The output would be
    Code:
    hello
    how
    are
    you
    doing
    today
    So my question is, how would I get the output to be
    Code:
    hello how are you doing today
     
    Last edited: Nov 2, 2015
  2. Offline

    CrystalxNeth

    Code:
    String message = "";
    for(String key : getConfig().getConfigurationSection("list").getKeys(false)){
                        String one = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("list."+key+".1"));
                        String two = getConfig().getString("list."+key+".2");
                        String three = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("list."+key+".3"));
                        message+=one+" "+two+" "+three+" ";
    }
    sender.sendMessage(message);
    
    Something like that should do it;
     
  3. Offline

    OkinawaBoss

    @CrystalxNeth Well I thought I would be able to figure it out from sendMessage but what I'm really trying to do is use fanciful. I guess I should have just said that. Sorry
     
  4. Offline

    Scimiguy

    You should actually be using a StringBuilder, but the above works for less-efficient purposes
     
  5. Offline

    CrystalxNeth

    Anytime you send a player a message it will create a new line in chat, so you'd need to create the string and then send it if you wish to have all of the strings on one line.
     
  6. Offline

    OkinawaBoss

    I guess this cant be done. So I'm going to mark this as solved.
     
  7. Online

    timtower Administrator Administrator Moderator

    @OkinawaBoss You need to put them after each other, with a stringbuilder, it is very possible.
     
  8. Offline

    OkinawaBoss

    @timtower
    I've tried to look at the documentation and several forums. Could you please explain how to implement a stringbuilder?
     
Thread Status:
Not open for further replies.

Share This Page