Skip to content

Commit

Permalink
Adds getClone(false) to not call TranslatableItemCloneEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Jan 5, 2024
1 parent 69dd07c commit dcd6385
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 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.54</version>
<version>1.697.55</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.54</version>
<version>1.697.55</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.54</version>
<version>1.697.55</version>
<packaging>pom</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public DataAssetType getType() {
@Override
@NotNull
public TranslatableItem modify(Function<String, String> function) {
ItemStack clone = getClone();
ItemStack clone = getClone(false);
ItemMeta meta = clone.getItemMeta();
Objects.requireNonNull(meta, "ItemMeta cannot be null");
ItemStackModder modder = ItemStackModder.mod(clone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit dcd6385

Please sign in to comment.