Get values from lore

Discussion in 'Resources' started by RealmsofValendor, Sep 8, 2013.

Thread Status:
Not open for further replies.
  1. I've been looking around and haven't really noticed any way of getting values from lore, Since I've had this for awhile and its helpful for the project i'm doing I decided to post.


    This is to grab 1 value.
    Code:java
    1.  
    2. public static String getValueFromLore(List<String> par1, String par2) {
    3.  
    4. String retString = "";
    5. try {
    6. if (par1 != null) {
    7. for (int i = 0; i < par1.size(); i++) {
    8. if (par1.get(i).contains(par2)) {
    9. retString = cleanUpLore(par1.get(i));
    10. return retString;
    11. }
    12. }
    13. } else
    14. return retString;
    15. } catch (Exception e) {
    16. outputError(e);
    17. }
    18. return retString;
    19. }
    20.  
    21. private static String cleanUpLore(String par1) {
    22.  
    23. String[] arg = par1.split(":");
    24. arg[1] = ChatColor.stripColor(arg[1]);
    25. String str = arg[1].replace("%", "").trim().toString();
    26. return str;
    27. }
    28.  

    How to use: int health = getValueFromLore(lore, "Health");



    Now if you are doing something like this "Damage: 100 - 150" for a rpg or whatever you would use this for. This is what you would do
    Code:java
    1.  
    2. public static int getMinValueFromLore(ItemStack item, String value) {
    3.  
    4. int returnVal = 0;
    5. ItemMeta meta = item.getItemMeta();
    6. try {
    7. List<String> lore = meta.getLore();
    8. if (lore != null) {
    9. for (int i = 0; i < lore.size(); i++) {
    10. if (lore.get(i).contains(value)) {
    11. String vals = lore.get(i).split(":")[1];
    12. vals = ChatColor.stripColor(vals);
    13. vals = vals.split("-")[0];
    14. returnVal = Integer.parseInt(vals.trim());
    15. }
    16. }
    17. }
    18. } catch (Exception e) {
    19. outputError(e);
    20. }
    21. return returnVal;
    22. }
    23.  
    24. public static int getMaxValueFromLore(ItemStack item, String value) {
    25.  
    26. int returnVal = 0;
    27. ItemMeta meta = item.getItemMeta();
    28. try {
    29. List<String> lore = meta.getLore();
    30. if (lore != null) {
    31. for (int i = 0; i < lore.size(); i++) {
    32. if (lore.get(i).contains(value)) {
    33. String vals = lore.get(i).split(":")[1];
    34. vals = ChatColor.stripColor(vals);
    35. vals = vals.split("-")[1];
    36. returnVal = Integer.parseInt(vals.trim());
    37. }
    38. }
    39. }
    40. } catch (Exception e) {
    41. outputError(e);
    42. }
    43. return returnVal;
    44. }
    45.  

    To do this:
    int damageMin = getMinValueFromLore(weapon, "Damage");
    int damageMax = getMaxValueFromLore(weapon, "Damage");
     
Thread Status:
Not open for further replies.

Share This Page