Taking a variable from a string

Discussion in 'Plugin Development' started by 8803286, Apr 14, 2014.

Thread Status:
Not open for further replies.
  1. Hi i was just looking at essentials config and i found this

    items:
    - 277 1 digspeed:3 name:Dwarf lore:Diggy|Diggy|Hole
    - 278 1 efficiency:1 durability:1 name:&4Gigadrill lore:The_drill_that_&npierces|the_heavens

    I just wondering how i take the
    name: data
    lore: data
    from that string. I have no clue how to code this.
     
  2. Offline

    ResultStatic

    8803286 there is methods in the yamlconfiguration that store item stacks, not sure if they are using those, but its probbally easier to use yamlconfigs for storing items
     
  3. Offline

    jb42300

    Wait so do you want no title and no lore????? PM me if u reply to me so i can respond
     
  4. for(String kit : cKits.config.getConfigurationSection("").getKeys(false)){
    Integer delay = cKits.config.getInt(kit+".delay", 0);
    Material icon = Material.getMaterial(cKits.config.getString(kit+".icon", "GLASS"));
    String permission = cKits.config.getString(kit+".permission", "Member");

    for(String item : cKits.config.getStringList(kit+".items")){
    String name;
    List<String> lore;
    }
    }


    I sended the code i have

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    jb42300

    I dont know what you want tho XD srry but would you not like the name and lore???
     

  6. I want to save the lore and the name
     
  7. Offline

    jb42300

    ooooooo ok lol
    Go into the public void onEnable() and to it saveConfig()
    It should look like this

    Code:java
    1.  
    2. public void onEnable() {
    3. getLogger().info("Has Been Enabled");
    4. saveConfig();
    5. }
    6.  
    7. public void onDisable() {
    8. getLogger().info("Has Been Disabled");
    9. saveConfig();
    10.  
    11. }
     
  8. What are you talking about?

    Edit: SHIT Soz i want to get the lore and the name from the config
     
  9. Offline

    agent6262

    If you are trying to take the data from those strings i would have a look at string splitting and java regular expressions/patterns. and once you have thoes in a string array then you can save them to a file.

    P.S. if you need help saving to a file/yml file pm me
     
  10. Offline

    agent6262

    You could split it on a space char but you might have to do some clever string comparisons to get the data from something like this name:&4Gigadrill. Or you could use a regex pattern which might make your life a bit easier
     

  11. I don't know how to use regex pattern
     
  12. Offline

    agent6262

    Because i'm a nice guy i will go ahead and GIVE you a possible regex pattern that will work. But in the mean time please take a look at some tutorials online otherwise you will never learn how to use them. Here is one that i learned off of.

    Because of the complex string and number of different combinations your best bet is to just split along a white space char or " ".

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  13. Offline

    coasterman10

    Use String.split() to split the strings into tokens, and then you can parse those individually.
     
Thread Status:
Not open for further replies.

Share This Page