Skip to content

Commit

Permalink
Adds TranslatableItemCloneEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Jan 5, 2024
1 parent 85f6c4a commit 69dd07c
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ci-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.53</version>
<version>1.697.54</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion local-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.53</version>
<version>1.697.54</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.697.53</version>
<version>1.697.54</version>
<packaging>pom</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;
import org.bukkit.persistence.PersistentDataType;
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;

Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 69dd07c

Please sign in to comment.