11package me .zort .configurationlib .configuration .bukkit ;
22
33import lombok .Getter ;
4- import me .zort .configurationlib .Node ;
5- import me .zort .configurationlib .NodeTypes ;
6- import me .zort .configurationlib .SectionNode ;
4+ import lombok .RequiredArgsConstructor ;
5+ import me .zort .configurationlib .*;
76import me .zort .configurationlib .configuration .bukkit .adapter .ItemStackAdapter ;
87import me .zort .configurationlib .util .Colorizer ;
98import me .zort .configurationlib .util .ItemValidator ;
1918import org .bukkit .inventory .ItemStack ;
2019import org .bukkit .inventory .meta .ItemMeta ;
2120import org .bukkit .inventory .meta .SkullMeta ;
21+ import org .jetbrains .annotations .NotNull ;
2222import org .jetbrains .annotations .Nullable ;
2323
2424import java .lang .reflect .Field ;
@@ -41,7 +41,9 @@ public BukkitSectionNode(@Nullable SectionNode<ConfigurationSection> parent, Con
4141 this .children = new ConcurrentHashMap <>();
4242 init ();
4343
44- //registerAdapter(ItemStack.class, new ItemStackAdapter());
44+ if (parent == null ) {
45+ registerAdapter (ItemStack .class , new ItemStackAdapter ());
46+ }
4547 }
4648
4749 @ Override
@@ -91,9 +93,9 @@ public void putSelf(ConfigurationSection location) {
9193 @ Override
9294 public Object buildValue (Field field , Node <ConfigurationSection > node , Placeholders placeholders ) {
9395 // I'm specifying new field types for mapped objects.
94- if (field .getType ().equals (ItemStack .class ) && node instanceof BukkitSectionNode ) {
96+ /* if(field.getType().equals(ItemStack.class) && node instanceof BukkitSectionNode) { // Replaced by DefaultItemDeserializer
9597 return ((BukkitSectionNode) node).getAsItem(placeholders);
96- } else if (field .getType ().equals (List .class ) && node instanceof BukkitSimpleNode ) {
98+ } else */ if (field .getType ().equals (List .class ) && node instanceof BukkitSimpleNode ) {
9799 Object listCandidate = ((BukkitSimpleNode ) node ).get ();
98100 if (listCandidate instanceof List ) {
99101 return listCandidate ;
@@ -246,4 +248,13 @@ private static int verMajor() {
246248 return Integer .parseInt (verString );
247249 }
248250
251+ private static class DefaultItemDeserializer implements NodeDeserializer <ItemStack , ConfigurationSection > {
252+
253+ @ Override
254+ public ItemStack deserialize (@ NotNull ItemStack deserializeInto , NodeContext <Node <ConfigurationSection >, ConfigurationSection > context , Placeholders placeholders ) {
255+ return ((BukkitSectionNode ) context .getNode ()).getAsItem (placeholders );
256+ }
257+
258+ }
259+
249260}
0 commit comments