From 69dd07ce8a5dcd655a1fc08b975a69270e3decb3 Mon Sep 17 00:00:00 2001 From: lbenav8095 Date: Fri, 5 Jan 2024 16:03:00 -0500 Subject: [PATCH] Adds TranslatableItemCloneEvent --- ci-pom.xml | 2 +- local-pom.xml | 2 +- pom.xml | 2 +- .../translatable/TranslatableItem.java | 7 ++- .../events/TranslatableItemCloneEvent.java | 56 +++++++++++++++++++ .../bloblib/events/TranslatableItemEvent.java | 16 ++++++ 6 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/main/java/us/mytheria/bloblib/events/TranslatableItemCloneEvent.java create mode 100644 src/main/java/us/mytheria/bloblib/events/TranslatableItemEvent.java diff --git a/ci-pom.xml b/ci-pom.xml index 8ff1b6e..79e1ad1 100644 --- a/ci-pom.xml +++ b/ci-pom.xml @@ -7,7 +7,7 @@ us.mytheria BlobLib - 1.697.53 + 1.697.54 pom.xml bloblib diff --git a/local-pom.xml b/local-pom.xml index a813878..88ebfd2 100644 --- a/local-pom.xml +++ b/local-pom.xml @@ -5,7 +5,7 @@ us.mytheria BlobLib - 1.697.53 + 1.697.54 pom.xml bloblib diff --git a/pom.xml b/pom.xml index 17f1342..c209dfb 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 us.mytheria BlobLib - 1.697.53 + 1.697.54 pom 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 db16d7e..83ad506 100644 --- a/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java +++ b/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java @@ -1,5 +1,6 @@ package us.mytheria.bloblib.entities.translatable; +import org.bukkit.Bukkit; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; @@ -7,6 +8,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import us.mytheria.bloblib.api.BlobLibTranslatableAPI; +import us.mytheria.bloblib.events.TranslatableItemCloneEvent; import java.util.Objects; @@ -85,6 +87,9 @@ default TranslatableItemModder modder() { } default ItemStack getClone() { - return new ItemStack(get()); + ItemStack clone = new ItemStack(get()); + TranslatableItemCloneEvent event = new TranslatableItemCloneEvent(this, clone); + Bukkit.getPluginManager().callEvent(event); + return event.getClone(); } } diff --git a/src/main/java/us/mytheria/bloblib/events/TranslatableItemCloneEvent.java b/src/main/java/us/mytheria/bloblib/events/TranslatableItemCloneEvent.java new file mode 100644 index 0000000..5a8f7ee --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/events/TranslatableItemCloneEvent.java @@ -0,0 +1,56 @@ +package us.mytheria.bloblib.events; + +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import us.mytheria.bloblib.entities.translatable.TranslatableItem; + +/** + * Called when a TranslatableItem is cloned. + */ +public class TranslatableItemCloneEvent extends TranslatableItemEvent { + private ItemStack clone; + + /** + * Called when a TranslatableItem is cloned. + * + * @param translatableItem The TranslatableItem. + * @param clone The clone. + */ + public TranslatableItemCloneEvent(TranslatableItem translatableItem, ItemStack clone) { + super(translatableItem); + this.clone = clone; + } + + private static final HandlerList HANDLERS_LIST = new HandlerList(); + + public TranslatableItemCloneEvent(TranslatableItem translatableItem) { + super(translatableItem); + } + + @Override + public HandlerList getHandlers() { + return HANDLERS_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLERS_LIST; + } + + /** + * Will get the clone. + * + * @return The clone. + */ + public ItemStack getClone() { + return clone; + } + + /** + * Will set the clone. + * + * @param clone The clone. + */ + public void setClone(ItemStack clone) { + this.clone = clone; + } +} diff --git a/src/main/java/us/mytheria/bloblib/events/TranslatableItemEvent.java b/src/main/java/us/mytheria/bloblib/events/TranslatableItemEvent.java new file mode 100644 index 0000000..a3a237d --- /dev/null +++ b/src/main/java/us/mytheria/bloblib/events/TranslatableItemEvent.java @@ -0,0 +1,16 @@ +package us.mytheria.bloblib.events; + +import org.bukkit.event.Event; +import us.mytheria.bloblib.entities.translatable.TranslatableItem; + +public abstract class TranslatableItemEvent extends Event { + public TranslatableItemEvent(TranslatableItem translatableItem) { + this.translatableItem = translatableItem; + } + + private final TranslatableItem translatableItem; + + public TranslatableItem getTranslatableItem() { + return translatableItem; + } +}