Solved Configuration Messages

Discussion in 'Spigot Plugin Development' started by ryu, Jun 10, 2016.

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

    ryu

    Hello, I was wondering if anyone knew how I would be able to create a config for my messages where instead of me having to use this way:
    Code (Text):
    #PlaceHolders
    # %amount% - Amount of experience or money
    # %new% - New Line

    Messages:
      Withdraw_Help: '&c&l/withdraw <$>%new%&7This will create a bank note with the%new%&7equivalent value of <$>.'
       
    I can do it this way:
    Code (Text):
    #PlaceHolders
    # %amount% - Amount of experience or money

    Messages:
      Withdraw_Help:
      - '&c&l/withdraw <$>'
      - '&7This will create a bank note with the'
      - '&7equivalent value of <$>.'
       
    Code I am using atm:
    Code (Text):
    String WithdrawHelp = WithdrawAdvanced.plugin.getConfig().getString("Messages.Withdraw_Help");
                        WithdrawHelp = WithdrawHelp.replaceAll("&", "§");
                        WithdrawHelp = WithdrawHelp.replaceAll("%new%", "\n");
                        player.sendMessage(WithdrawHelp);
     
  2. Loop through all the messages with a for loop, then send each one

    Code (Text):
    for(String whmsg : getConfig().getStringList("Messages.Withdraw_Help")){
    p.sendMessage(whmsg);
    }
     
  3. ConfigurationSection#getStringList(String key) returns a list of strings which is read the way you want it to.
     
  4. ryu

    ryu

    Alright I just need your help with one last thing
    [​IMG]
    I'm trying to do the same thing with an item lore but it's not working...any ideas?
     
  5. You use a for loop and every time it finds a new string in the string list add another lore line
     
  6. @ryu looks like you're using java 8.
    If it's ok to stay on java 8, you could use:
    Code (Java):
    .replaceAll(input -> input.replace("Query", "Replacement"))
    If you want a more classic way of doing this, you should create a new String List, then loop over all of the values in the getStringList() and add the modified string to the new list, then set that as the lore.
     
  7. ryu

    ryu

    oh alright ty :)
     
  8. My translation was made like this:
    Using an enum with String as values for each enum, on enable if file dosen't exist loop through all enum and add them to it, if it exist get all of them and replace string value with the one from config
     
Thread Status:
Not open for further replies.