src/main/java/me/hyfe/simplespigot/item/SpigotItem.java
/**
     * Converts a section from a config into an ItemStack (must use specific format).
     *
     * @param config      The config to get the item from.
     * @param path        The path inside the config to get the item from (e.g 1.item)
     * @param replace     A replacer to replace certain parts of the configurable options necessary (name, lore).
     * @param defaultItem If the section is not present, this is the default item.
     * @return The ItemStack built from the config path.
     */
Converts a section from a config into an ItemStack (must use specific format).
@param config      The config to get the item from.
@param path        The path inside the config to get the item from
@param replace     A replacer to replace certain parts of the configurable options necessary (name, lore).
@param defaultItem If the section is not present, this is the default item.
@return The ItemStack built from the config path.
Converts a section from a config into an ItemStack ( must use specific format ) . @param config The config to get the item from . @param path The path inside the config to get the item from @param replace A replacer to replace certain parts of the configurable options necessary ( name lore ) . @param defaultItem If the section is not present this is the default item . @return The ItemStack built from the config path .
@Nullable
    public static ItemStack toItemOrDefault(Config config, String path, Replace replace, ItemStack defaultItem) {
        if (!config.has(path)) {
            return defaultItem;
        }
        UnaryOperator<String> pathBuilder = string -> String.format("%s.%s", path, string);
        String entry = config.string(pathBuilder.apply("material"));
        if (entry == null) {
            return null;
        }
        String[] entryArray = entry.split(":");
        boolean isHead = entryArray[0].equalsIgnoreCase("head") && entryArray.length == 2;
        ItemStack itemStack = isHead ? null : MultiMaterial.parseItem(entry);
        if (itemStack == null && !isHead) {
            return null;
        }
        Builder builder = builder().itemStack(itemStack);
        validatePath(config, pathBuilder.apply("name"), localPath -> builder.name(Text.modify(config.string(pathBuilder.apply("name")), replace)));
        validatePath(config, pathBuilder.apply("lore"), localPath -> builder.lore(Text.modify(config.list(localPath), replace)));
        validatePath(config, pathBuilder.apply("amount"), localPath -> builder.amount(config.integer(localPath)));
        validatePath(config, pathBuilder.apply("rgb"), localPath -> builder.color(config.string(localPath)));
        validatePath(config, pathBuilder.apply("customModelData"), localPath -> builder.customModelData(config.integer(localPath)));
        if (config.bool(pathBuilder.apply("glow"))) {
            builder.glow();
        }
        config.stringList(pathBuilder.apply("item-flags")).forEach(builder::flag);
        config.stringList(pathBuilder.apply("enchants")).forEach(builder::enchant);
        if (isHead) {
            builder.head(entryArray[1]);
        }
        return builder.build();
    }
@ Nullable public static ItemStack toItemOrDefault ( Config config , String path , Replace replace , ItemStack defaultItem ) { if ( ! config . has ( path ) ) { return defaultItem ; } UnaryOperator < String > pathBuilder = string -> String . format ( "%s.%s" , path , string ) ; String entry = config . string ( pathBuilder . apply ( "material" ) ) ; if ( entry == null ) { return null ; } String [ ] entryArray = entry . split ( ":" ) ; boolean isHead = entryArray [ 0 ] . equalsIgnoreCase ( "head" ) && entryArray . length == 2 ; ItemStack itemStack = isHead ? null : MultiMaterial . parseItem ( entry ) ; if ( itemStack == null && ! isHead ) { return null ; } Builder builder = builder ( ) . itemStack ( itemStack ) ; validatePath ( config , pathBuilder . apply ( "name" ) , localPath -> builder . name ( Text . modify ( config . string ( pathBuilder . apply ( "name" ) ) , replace ) ) ) ; validatePath ( config , pathBuilder . apply ( "lore" ) , localPath -> builder . lore ( Text . modify ( config . list ( localPath ) , replace ) ) ) ; validatePath ( config , pathBuilder . apply ( "amount" ) , localPath -> builder . amount ( config . integer ( localPath ) ) ) ; validatePath ( config , pathBuilder . apply ( "rgb" ) , localPath -> builder . color ( config . string ( localPath ) ) ) ; validatePath ( config , pathBuilder . apply ( "customModelData" ) , localPath -> builder . customModelData ( config . integer ( localPath ) ) ) ; if ( config . bool ( pathBuilder . apply ( "glow" ) ) ) { builder . glow ( ) ; } config . stringList ( pathBuilder . apply ( "item-flags" ) ) . forEach ( builder :: flag ) ; config . stringList ( pathBuilder . apply ( "enchants" ) ) . forEach ( builder :: enchant ) ; if ( isHead ) { builder . head ( entryArray [ 1 ] ) ; } return builder . build ( ) ; }
Converts a section from a config into an ItemStack (must use specific format).
Converts a section from a config into an ItemStack ( must use specific format ) .