Loading Items From Config

Discussion in 'Plugin Development' started by KoolzSkillz, Oct 24, 2014.

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

    KoolzSkillz

    just wondering how I could do this, any help is appreciated :)

    Ok what I mean is


    Config.yml, yes it's not layer out right it is just an example
    Level1:
    Item: Material.Diamond_Pickaxe
    Enchantments:
    - Sharpness,3
    - Protection, 5
    Name:
    - &2Level 1 Thing
    Lore:
    - null


    Is that possible?
     
  2. Offline

    TheCodingCat

    if when you save the item to the config you simply do
    config.set(path, YourItemStack);
    then you can retrieve it with
    config.getItemStack(YourPath);
     
  3. Offline

    coasterman10

    This would be possible, however it would be more practical with the following chnges:
    - I would suggest using the item ID seeing as most people don't know the Bukkit enum values.
    - Enchantment IDs would also be more practical seeing as most people don't know the Bukkit enum values.
    - The lore section can be completely left out if null and you can check if it exists or not in your code.

    Enchantments would be a standard map, name would just be a string, and lore would be a string list. The config would be formatted like so:
    Code:
    Level1:
      Item: 278
      Enchantments:
        16: 3
        0: 5
      Name: "&2Level 1 Thing"
      Lore:
      - "..."
      - "..."
    Read up on the Bukkit Configuration API to figure out how to do all this, since it is fairly straightforward. If your IDE has code completion, you can simply scroll through the suggestions on getConfig() to see everything your config can do. The javadoc is here: http://jd.bukkit.org/rb/apidocs/org/bukkit/configuration/ConfigurationSection.html
     
  4. Offline

    unon1100

    You can use the valueOf method in enumerations.
    Example with potion effects:

    config:
    Code:
    Potion1:
      Effect: BLINDNESS
      Amplifier: 0
      Duration: 10
    etc etc etc
    Code to scan it:
    Code:java
    1. ConfigurationSection cs = getConfig().getConfigurationSection("Potion1");
    2. PotionEffect eff = new PotionEffect(PotionEffectType.valueOf(cs.getString("Effect").toUpperCase()), cs.getInt("Amplifier"), cs.getInt("Duration"));


    There may be some errors as I literally typed this on a tablet, so yea. Don't copy the code, use it as a reference. You should be able to figure out how to do the same thing but with materials and enchantments.
     
Thread Status:
Not open for further replies.

Share This Page