Formatting String to List<String> for Lore

Discussion in 'Plugin Development' started by xWatermelon, Sep 22, 2013.

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

    xWatermelon

    How can I format/change a String to a List<String> which I can use for setting an item's lore? I basically want it to be changed so every 30 characters (about, cut at spaces) will be put on a new line. Can anyone help me?
     
  2. Offline

    chasechocolate

    Try something like this:
    Code:java
    1. public List<String> formatLore(String text){
    2. List<String> lore = new ArrayList<String>();
    3. int max = 30; //Max characters per line
    4. String current = "";
    5.  
    6. for(String str : text.split(" ")){
    7. if(current.trim().length + str.length <= max){
    8. lore.add(current.trim());
    9. current = "";
    10. } else {
    11. current += (str + " ");
    12. }
    13. }
    14.  
    15. return lore;
    16. }
     
Thread Status:
Not open for further replies.

Share This Page