New line help.

Discussion in 'Plugin Development' started by Simonhansen1999, Dec 26, 2015.

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

    Simonhansen1999

    Hello!

    I have a bit issues with new line and i hope your guys can help! :D

    Alright, lets get to it..

    This is where i set the lore on the item:
    [​IMG]
    im trying to do so after the "," it creates a new line to the lore.

    Config:
    [​IMG]

    Is it possible to do it without changing the config?

    Sorry for bad english.
     
  2. Offline

    Xerox262

    Splitting it at "," should do the trick. You might need to change it from an array to a Collection though, don't remember if Lore takes arrays.
     
  3. Offline

    Zombie_Striker

    @Xerox262
    Not arrays, it takes in a List<String>

    @Simonhansen1999
    Don't replace the comma, instead, split at the comma, and add each split string to the lore as a new line.
     
  4. Offline

    Simonhansen1999

    Can you give a example? Still pretty new to this. :)
     
  5. Offline

    Xerox262

    New to Bukkit or Java, because the solution we gave is quite basic Java. Maybe you should read this, http://wiki.bukkit.org/Plugin_Tutorial#Learning_Java

    Edit: When did they add Derek Banas? I don't remember those videos there.

    But yea, when you feel like you're ready all it takes is a simple
    String#split(",");
    Then
    Arrays.asList(String[]);
     
    Last edited: Dec 26, 2015
  6. Offline

    Simonhansen1999

    Dude, i can the most of the things on the site and theres nothing about "split", this is the only thing i need help to, so why can you not just come with a example instead?
     
  7. Offline

    Zombie_Striker

    cococow123 and mug561 like this.
  8. Offline

    Xerox262

    I linked him to the learning Java section of it...

    @Simonhansen1999 I told you under the message with my most recent edit how to do it.
     
    Zombie_Striker likes this.
  9. Offline

    Simonhansen1999

    didn't see it before i posted mine.

    now i have this:
    [​IMG]
    and its works, but have can i do so it shows all parts?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 26, 2015
  10. Offline

    Zombie_Striker

    @Simonhansen1999
    For loop through all of the objects in the array, and add each object to lore2. OR as I posted above, merge the Array with the Collection.
     
  11. Offline

    Simonhansen1999

    I can't figure out how the Collection thing works, so i must just stop it here.. I really need it, but.. :/
     
  12. Offline

    Zombie_Striker

  13. Offline

    mug561

    I know I'm not solving the error or anything but..
    "§"??

    Correct me if I'm wrong but can't you use chatcolor in lore?

    And here's a mini-lesson. Please look into the things @Zombie_Striker Mentioned before.
    Along with learning about collections in general.

    Code:
            String s = "Pie is better, Than all universe";
            // This is my example String, in your case it would be what you get from config
           
            String[] s1 = s.split(",");
            /* This turns string s into two sparate strings in the array.
             * The First Being "Pie is better" and the second being "than all universe"
             * A basic collection of strings is an array
             *You can get each string from the array by typing the array's name followed by two square brackets
             *and the number string you want. Keep In mind, array's start counting at 0
             *So The first string in the array would be s1[0] and that would be considered a string
             *
             *So:
             *s1[0] = "Pie is better"
             *and
             *s1[1] = "Than all universe"
            */
           
            ItemStack item = new ItemStack(Material.DIRT);
            // Creates a new Itemstack.
           
            ItemMeta meta = item.getItemMeta();
            // Gets the item meta
           
            List<String> lore = meta.getLore();
            /* This gets the lore from the meta,
            * which you would want to do if you were preserving the item's lore, while adding your own ontop of that.
            * If you just want to set the items lore and forget about the previous lore. change meta.getLore() to :
            * new ArrayList<String>(); or you can make the object elsewhere. You just need a new list.
            * Each new entry in the list is a new line on the lore
            * Lore can Have ChatColors in it;
            */
            for(String str: s1){
                lore.add(str);
            }
            /* Enhanced for loop to iterate through every string in the array
             * adds to the lore list.
             * Don't Know about enchanced for loops? https://www.youtube.com/watch?v=w41D0V-BnKQ
             */
            meta.setLore(lore);
            // Finally, after we edited the lore list, we must tell the meta that this is the new lore
           
            item.setItemMeta(meta);
            //And since we edited the meta, we MUST update that too.
     
  14. Offline

    Xerox262

    You can use ChatColors in lore. Also if you're not editing the String's then you can just do
    Code:
    List<String> lore = meta.getLore();
    lore.addAll((List<String>) Arrays.asList(s1));
    Assuming s1 is your String array.
     
    mug561 likes this.
  15. Offline

    Simonhansen1999

    Maybe a bit late, but i fixed it. Thanks for the help! :D
     
  16. Offline

    Mrs. bwfctower

    You could just do
    Code:
    meta.setLore(Arrays.asList(s1));
     
Thread Status:
Not open for further replies.

Share This Page