From dcd6385a1097f1eb913257a9842b5b064802b49a Mon Sep 17 00:00:00 2001 From: lbenav8095 Date: Fri, 5 Jan 2024 17:52:16 -0500 Subject: [PATCH] Adds getClone(false) to not call TranslatableItemCloneEvent --- ci-pom.xml | 2 +- local-pom.xml | 2 +- pom.xml | 2 +- .../translatable/BlobTranslatableItem.java | 2 +- .../translatable/TranslatableItem.java | 22 ++++++++++++++++++- .../events/TranslatableItemCloneEvent.java | 6 +---- .../bloblib/events/TranslatableItemEvent.java | 3 ++- 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ci-pom.xml b/ci-pom.xml index 79e1ad1..44a2e35 100644 --- a/ci-pom.xml +++ b/ci-pom.xml @@ -7,7 +7,7 @@ us.mytheria BlobLib - 1.697.54 + 1.697.55 pom.xml bloblib diff --git a/local-pom.xml b/local-pom.xml index 88ebfd2..f1e2dae 100644 --- a/local-pom.xml +++ b/local-pom.xml @@ -5,7 +5,7 @@ us.mytheria BlobLib - 1.697.54 + 1.697.55 pom.xml bloblib diff --git a/pom.xml b/pom.xml index c209dfb..bdbec41 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 us.mytheria BlobLib - 1.697.54 + 1.697.55 pom diff --git a/src/main/java/us/mytheria/bloblib/entities/translatable/BlobTranslatableItem.java b/src/main/java/us/mytheria/bloblib/entities/translatable/BlobTranslatableItem.java index 4076407..8891f1c 100644 --- a/src/main/java/us/mytheria/bloblib/entities/translatable/BlobTranslatableItem.java +++ b/src/main/java/us/mytheria/bloblib/entities/translatable/BlobTranslatableItem.java @@ -68,7 +68,7 @@ public DataAssetType getType() { @Override @NotNull public TranslatableItem modify(Function function) { - ItemStack clone = getClone(); + ItemStack clone = getClone(false); ItemMeta meta = clone.getItemMeta(); Objects.requireNonNull(meta, "ItemMeta cannot be null"); ItemStackModder modder = ItemStackModder.mod(clone); diff --git a/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java b/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java index 83ad506..1b8bc0c 100644 --- a/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java +++ b/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java @@ -86,10 +86,30 @@ default TranslatableItemModder modder() { return TranslatableItemModder.mod(this); } - default ItemStack getClone() { + /** + * Will get a clone of the TranslatableItem, allowing + * other plugins to modify the ItemStack. + * + * @param callEvent If the event should be called. + * @return The clone. + */ + default ItemStack getClone(boolean callEvent) { ItemStack clone = new ItemStack(get()); + if (!callEvent) + return clone; TranslatableItemCloneEvent event = new TranslatableItemCloneEvent(this, clone); Bukkit.getPluginManager().callEvent(event); return event.getClone(); } + + /** + * Will get a clone of the TranslatableItem, allowing + * other plugins to modify the ItemStack. + * Event will be called. + * + * @return The clone. + */ + default ItemStack getClone() { + return getClone(true); + } } diff --git a/src/main/java/us/mytheria/bloblib/events/TranslatableItemCloneEvent.java b/src/main/java/us/mytheria/bloblib/events/TranslatableItemCloneEvent.java index 5a8f7ee..997ec44 100644 --- a/src/main/java/us/mytheria/bloblib/events/TranslatableItemCloneEvent.java +++ b/src/main/java/us/mytheria/bloblib/events/TranslatableItemCloneEvent.java @@ -17,16 +17,12 @@ public class TranslatableItemCloneEvent extends TranslatableItemEvent { * @param clone The clone. */ public TranslatableItemCloneEvent(TranslatableItem translatableItem, ItemStack clone) { - super(translatableItem); + super(translatableItem, false); this.clone = clone; } private static final HandlerList HANDLERS_LIST = new HandlerList(); - public TranslatableItemCloneEvent(TranslatableItem translatableItem) { - super(translatableItem); - } - @Override public HandlerList getHandlers() { return HANDLERS_LIST; diff --git a/src/main/java/us/mytheria/bloblib/events/TranslatableItemEvent.java b/src/main/java/us/mytheria/bloblib/events/TranslatableItemEvent.java index a3a237d..ea5b4f0 100644 --- a/src/main/java/us/mytheria/bloblib/events/TranslatableItemEvent.java +++ b/src/main/java/us/mytheria/bloblib/events/TranslatableItemEvent.java @@ -4,7 +4,8 @@ import us.mytheria.bloblib.entities.translatable.TranslatableItem; public abstract class TranslatableItemEvent extends Event { - public TranslatableItemEvent(TranslatableItem translatableItem) { + public TranslatableItemEvent(TranslatableItem translatableItem, boolean isAsync) { + super(isAsync); this.translatableItem = translatableItem; }