item lores.

Discussion in 'Plugin Development' started by TheGamesHawk2001, Apr 28, 2015.

Thread Status:
Not open for further replies.
  1. Hi, I want to add text onto a lore that already has a lore without disrupting the current lore :)

    Tried something more complicated :

    Code:
                                ArrayList<String> lore1 = new ArrayList<String>();
                                lore1.clear();
                                lore1.addAll(im1.getLore());
                             
                                int blocksmined = lore1.indexOf(ChatColor.YELLOW + "" + ChatColor.ITALIC + "Blocks Mined: " + ChatColor.AQUA + "" + ChatColor.ITALIC + Main.config.getInt(pid.toString() + ".options" + ".total-mined") + ChatColor.GRAY + ".");
                             
                                lore1.remove(blocksmined);
                             
                                lore1.add(ChatColor.YELLOW + "" + ChatColor.ITALIC + "Blocks Mined: " + ChatColor.AQUA + "" + ChatColor.ITALIC + Main.config.getInt(pid.toString() + ".options" + ".total-mined") + ChatColor.GRAY + ".");
                                im1.setLore(lore1);
                             
                                is.setItemMeta(im1);
    Not really done many complicated things with lores tbh, thanks!
     
  2. Try something like:
    Code:java
    1. ArrayList<String> lore = meta.getLore();
    2. lore.add("some text");
    3. lore.add("some more text :p");
    4.  
    5. meta.setLore(lore);
    6. item.setItemMeta(meta);
     
  3. But this is triggered every block break. I have a block break counter config path so I will need to remove that before I add it again to the lore other wise I will get some thing like this

    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
    Hi
     
  4. Ah, you want to replace something in the Arraylist?
    I quickly wrote a method to replace strings in an ArrayList:
    Code:java
    1. public ArrayList<String> replace(ArrayList<String> list, String regex, String replacement) {
    2. int index = 0;
    3. for(String str : list) {
    4. if(str.matches(regex))
    5. list.set(index, str.replaceAll(regex, replacement));
    6. index++;
    7. }
    8. return list;
    9. }
    10.  

    You may need to know regular expressions to use it.
    For example:
    Code:java
    1. list = replace(list, "Blocks Mined: (\\d).", "Blocks Mined: 999.");

    \\d is a regex code for every digit.
    ( ) is a group.
     
    Last edited: Apr 28, 2015
Thread Status:
Not open for further replies.

Share This Page