Skip to content

Commit

Permalink
Merge pull request #29 from liquip/fix/item-impl
Browse files Browse the repository at this point in the history
Fix features and enchantments not being initialized
  • Loading branch information
sqyyy-jar authored Dec 31, 2022
2 parents 229d107 + 04e9601 commit 4cbf406
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group = "io.github.liquip"
version = "2.0.0-beta"
version = "2.0.1-beta"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public class ItemImpl implements Item {
private final Material material;
private final Component displayName;
private final List<Component> lore;
private final Multimap<Class<? extends Event>, BiConsumer<? extends Event, ItemStack>> eventHandlers;
private final Object2IntMap<Enchantment> enchantments;
private final List<Feature> features;
private final Map<TaggedFeature<?>, Object> taggedFeatures;
private final Multimap<Class<? extends Event>, BiConsumer<? extends Event, ItemStack>> eventHandlers;

public ItemImpl(@NonNull Liquip api, @NonNull Key key, @NonNull Material material, @NonNull Component displayName,
@NonNull List<Component> lore, @NonNull Object2IntMap<Enchantment> enchantments, @NonNull List<Feature> features,
Expand All @@ -46,10 +46,18 @@ public ItemImpl(@NonNull Liquip api, @NonNull Key key, @NonNull Material materia
this.displayName = displayName;
this.lore = new ArrayList<>(lore.size());
this.lore.addAll(lore);
this.eventHandlers = ArrayListMultimap.create();
this.eventHandlers.putAll(eventHandlers);
this.enchantments = new Object2IntOpenHashMap<>(enchantments.size());
this.enchantments.putAll(enchantments);
for (final Object2IntMap.Entry<Enchantment> entry : enchantments.object2IntEntrySet()) {
this.enchantments.put(entry.getKey(), entry.getIntValue());
entry.getKey().initialize(this, entry.getIntValue());
}
this.features = new ArrayList<>(features.size());
this.features.addAll(features);
for (final Feature feature : features) {
this.features.add(feature);
feature.initialize(this);
}
this.taggedFeatures = new LinkedHashMap<>(taggedFeatures.size());
for (final Map.Entry<TaggedFeature<?>, ConfigElement> entry : taggedFeatures.entrySet()) {
final Object res = entry.getKey().initialize(this, entry.getValue());
Expand All @@ -60,8 +68,6 @@ public ItemImpl(@NonNull Liquip api, @NonNull Key key, @NonNull Material materia
}
this.taggedFeatures.put(entry.getKey(), res);
}
this.eventHandlers = ArrayListMultimap.create();
this.eventHandlers.putAll(eventHandlers);
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 4cbf406

Please sign in to comment.