Diablo Styled Weapons?

Discussion in 'Plugin Development' started by Mining4diamonds, Dec 31, 2013.

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

    Mining4diamonds

    I recently got stumped while coding something and figure out what to do next. Basically I want to make it so that the plugin reads the lore of the item so if the lore says DMG 100 - 145 that would then be the damage on the item.

    [​IMG]
    So something like this where it says damage 305 - 400 how could I make it so that plugin reads the lore and sets that as the weapon damage.
     
  2. Offline

    valon750

    Mining4diamonds

    I think there's a whole work around with getting a substring, after a certain character, that being ":", then replacing "-" characters.

    I've been interested in this in the past, and wouldn't mind getting a hang for this, so I'll keep track of this post to see where it goes.
     
  3. Offline

    NathanWolf

    This should work (could be slightly optimized with substring I think, but whatever)

    Code:java
    1. // Assuming you have a non-null ItemMeta object "itemMeta"
    2. List<String> lore = itemMeta.getLore();
    3.  
    4. // Check each line of the lore
    5. for (String line : lore) {
    6. // Look for a line that starts with "Damage:"
    7. if (line.startsWith("Damage:")) {
    8. // Parse out the two bits of damage. This assumes there are two.
    9. String[] damageParts = line.replace("Damage:", "").split("-");
    10. if (damageParts.length == 2) {
    11. Integer minDamage = Integer.parseInt(damageParts[0].trim());
    12. Integer maxDamage = Integer.parseInt(damageParts[1].trim());
    13. // ... do something with these two values
    14. }
    15. }
    16. }


    Hope that helps! I don't know how to actually do the part where you modify the weapon's damage... :\

    arg, mega-edit... wish somebody could make the java syntax tags not blow away indentation!
     
  4. Offline

    valon750

    NathanWolf

    Now that's impressive!

    Always wondered how to do that, now I know!
     
    NathanWolf likes this.
  5. Offline

    NathanWolf

    :D String.split is one of my favorite things, definitely my go-to for parsing. I probably overuse it...

    ArrayUtils.join (the opposing method) is also very handy.

    PHP made me learn to love such things.
     
  6. Offline

    valon750

    NathanWolf

    Messing with the strings and whatnot has always hurt my brain personally xD
     
  7. Offline

    Jalau

    loop through lore lines:
    for(String lore : is.getItemMeta().getLore()) {

    check if it's damage line:
    if(lore.contains("Damage") {

    And then get it like:
    String damagemin = lore.substring(lore.indexOf(":") +2, lore.indexOf("-") -1);
    int i = Integer.parseInt(damagemin);

    NOT TESTED! But that would be probably the code to get the min damage ;)



    Wouldn't work for color codes, also for setting damage:
    Code:java
    1.  
    2. int index = 0;
    3. ItemMeta im = is.getItemMeta();
    4. List<String> lorearray = im.getLore();
    5. for(String lore : lorearray) {
    6. if(lore.contains("Damage")) {
    7. lorearray.set(index, "Damage: 200 - 210" ) // What Ever
    8. im.setLore(lorearray);
    9. is.setItemMeta(im);
    10. }
    11. index++;
    12. }
    13. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page