Solved Settings enchantments, lores, displayname via config like essentials.

Discussion in 'Plugin Development' started by Eos, Sep 6, 2015.

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

    Eos

    How would I be able to set a custom lore, enchantment etc; via config like how essentials did theres

    example:
    264: sharpness:1 name:43123 lore:123231
     
  2. Make a parser yourself or look at essentials sourcecode
     
  3. Offline

    Eos

    @FisheyLP
    How would I get the id from that specific line?
     
  4. Code:
    String[] parts = yourString.split(" ");
    int id = Integer.parseInt(parts[0]);
    int amount = parts.length >= 1 ? Integer.parseInt(parts[1]) : 1;
    But you need to include the optional tags by yourself (like enchantments, displayname etc.)
     
  5. Offline

    Eos

    @FisheyLP
    How would I make it "Optional".
     
  6. I think essentials has things like "name:This_is_the_item_name".
    So you would just loop through all the parts of the string and search for one that starts with "name:", then substring "name:".length() of the part, so just "This_is_the_item_name" is left. Then have a variable outside the loop and set it to the part.

    Example (open)
    Don't know if this works but something like this ^^ PS: Don't copy paste!
    Code:
    String name = null;
    
    for (String part : parts)
    if (part.startsWith("name:")) name = part.substring("name:".length()).replace("_", " ");
     
  7. Offline

    Eos

    @FisheyLP

    So this is what I have so far

    Code:
       public void giveItemfromConfig(Player p)
        {
            String name ="name:";
            for ( String s : plugin.file.getFile().getStringList(plugin.file.path) ) {
                try {
                    if ( s.contains(name) )
                    {
                        String namelength = s.substring(name.length());
                        p.getInventory().addItem(applyLore(new ItemStack(Integer.parseInt(s)), namelength));
                        p.sendMessage("debug");
    
                    } else {
                        ///nope.exe
                        p.getInventory().addItem(new ItemStack(Integer.parseInt(s)));
    
                    }
                } catch(Exception e)
                {
                    Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA + "Error in Config, Your id must be a integer");
                }
            }
    
        }
    The problem is that it's always throwing out the expection when I use name: in my config if I remove the name:
    it gives me the diamond sword

    here's my config
    Code:
    ChestPopulater:
      items:
      - 276 name:cookie
    
    Solved it myself

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

Share This Page