From 64ba6a23c448fc2c4a5262602dd2b95a2f4176fd Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Tue, 5 Mar 2024 14:10:10 +0100 Subject: [PATCH] Added `.item:serializer` module to automatically load and save item objects. 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 `Item#copy(Class)` not checking if current item has field of receiving class. Fixed various bugs in **ShapedRecipe**. Fixed recipes not copying items in their most default state (Item). --- item/src/main/java/it/angrybear/yagl/items/Item.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/item/src/main/java/it/angrybear/yagl/items/Item.java b/item/src/main/java/it/angrybear/yagl/items/Item.java index 4086b01f..37ae279e 100644 --- a/item/src/main/java/it/angrybear/yagl/items/Item.java +++ b/item/src/main/java/it/angrybear/yagl/items/Item.java @@ -428,10 +428,13 @@ default I copy(@NotNull Class clazz) { for (final Field field : item.getNonStaticFields()) try { field.setAccessible(true); + ReflectionUtils.getField(this, field.getName()); Object obj1 = field.get(this); item.setFieldObject(field, obj1); } catch (IllegalAccessException e) { throw new RuntimeException(e); + } catch (IllegalArgumentException ignored) { + } return item.getObject(); }