Solved Adding Material To Config

Discussion in 'Plugin Development' started by MrGriefer_HGTech, Aug 28, 2015.

Thread Status:
Not open for further replies.
  1. Hello there,

    I trying to do:
    Code:
    FileConfiguration c = new YMLLoader("plugins/SugarRush", "item.yml").getFileConfiguration();
            SugarRush.item = c;
          
            List<String> lore = new ArrayList<String>();
            c.addDefault("Item.AllNodes.Material", Material.COMPASS);
    
    Ignore: List<String> lore = new ArrayList<String>(); for now! If you look at the code above it makes:
    c.addDefault("Item.AllNodes.Material", Material.COMPASS): which doesn't work I want to set the Material to be COMPASS so I did that and when I open my .yml file I get this Material: !!org.bukkit.Material 'COMPASS'

    How could I add a Material on a config file??

    EDIT: Sorry for my bad English :(
     
  2. Offline

    frontflip12345

    Save only a string, not the material enum itself.

    And later, you can get back your Material like this:
    Code:
    Material.getMaterial(materialString);
     
  3. Offline

    Hawktasard

    @MrGriefer_HGTech
    You're setting it to the actual material. You probably wanted to store the name ("COMPASS" in this case). To get the name you can do Material.COMPASS.name(), then you can use Material.matchMaterial(c.getString("some.thing")) to get it back from the config.
     
    mrgreen33gamer likes this.
  4. @frontflip12345 @Hawktasard

    Thanks both of you methods worked, but how could I set the lore for an Item I did this:
    Code:
    FileConfiguration c = new YMLLoader("plugins/SugarRush", "item.yml").getFileConfiguration();
    SugarRush.item = c;
    
    List<String> lore = new ArrayList<String>();
    c.addDefault("Item.AllNodes.Lore", lore);
    How could I make it so it comes like:
    HTML:
    Lore:
    - "&7- &8Lore"
     
  5. Offline

    CrystallFTW

    @MrGriefer_HGTech
    Code:
         List<String> lore = new ArrayList<String>();
            for(String str : c.getStringList("Item.AllNodes.Lore")){
               lore.add(str);
            }
         meta.setLore(lore);
    
    I think this would work.
     
  6. I am trying to add the lore on the config not the item itself

    Anyone???

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

    CrystallFTW

    @MrGriefer_HGTech are you trying to add the lore to a config file? just do
    Code:
    List<String> lore = Arrays.asList("Lore Line 1","Lore Line 2");
    c.addDefault("Item.Lore", lore);      
    
     
  8. Offline

    meguy26

    @MrGriefer_HGTech
    I have a slightly simpler solution. :)

    ItemStacks are serializable, and can just be added to the config (ConfigurationSection#put(String node, ItemStack stack);) <- supposed to be ; then ). xD
    what this does is save the entire itemstack to the config, and you can reload it with ConfigurationSection#getItemStack(String node), at least I believe that is the method.
     
Thread Status:
Not open for further replies.

Share This Page