Skip to content

Commit

Permalink
Added .item:serializer module to automatically load and save item o…
Browse files Browse the repository at this point in the history
…bjects.

Added parsers:
- [EnchantmentParser](item/serializer/src/main/java/it/angrybear/serializers/EnchantmentParser.java);
- [ItemParser](item/serializer/src/main/java/it/angrybear/serializers/ItemParser.java);
- [ShapeParser](item/serializer/src/main/java/it/angrybear/serializers/ShapeParser.java);
- [ShapedRecipeParser](item/serializer/src/main/java/it/angrybear/serializers/ShapedRecipeParser.java);
- [ShapelessRecipeParser](item/serializer/src/main/java/it/angrybear/serializers/ShapelessRecipeParser.java);
- [FurnaceRecipeParser](item/serializer/src/main/java/it/angrybear/serializers/FurnaceRecipeParser.java).
Added [YAGLParser](item/serializer/src/main/java/it/angrybear/serializers/YAGLParser.java) to automatically load parsers.
Moved everything to package `it.angrybear.yagl`.
Reworked `Item#copy()` method: it will try to get a default empty constructor from the current class. If it fails, it defaults to `ItemImpl`.
Fixed `Item#copy(Class)` with automatic resolution of interfaces: passing `Item` or `BukkitItem` will convert them into `ItemImpl` and `BukkitItemImpl`.
Fixed various bugs in **ShapedRecipe**.
  • Loading branch information
fulminazzo committed Mar 5, 2024
1 parent ee07309 commit 00498f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public BukkitItem setUnbreakable(final boolean unbreakable) {

@Override
public BukkitItem copy() {
return super.copy(BukkitItemImpl.class);
return (BukkitItem) super.copy();
}
}
9 changes: 8 additions & 1 deletion item/src/main/java/it/angrybear/yagl/items/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -397,7 +398,13 @@ default Item removeItemFlags(final @NotNull Collection<ItemFlag> itemFlags) {
* @return the item
*/
default Item copy() {
return copy(ItemImpl.class);
Class<? extends Item> clazz = this.getClass();
try {
Constructor<? extends Item> constructor = ReflectionUtils.getConstructor(clazz);
} catch (Exception e) {
clazz = ItemImpl.class;
}
return copy(clazz);
}

/**
Expand Down

0 comments on commit 00498f9

Please sign in to comment.