From 21280b0b1f838622907e2f8513f7477485262812 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 24 Jul 2021 15:20:00 +0200 Subject: [PATCH] Add defensive copy for ItemStack --- .../plugin/hologram/base/BaseItemLine.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseItemLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseItemLine.java index e84e7c2f..28990bc2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseItemLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseItemLine.java @@ -56,17 +56,21 @@ public abstract class BaseItemLine extends BaseTouchableLine implements Standard @Override public @Nullable ItemStack getItemStack() { - return itemStack; + return clone(itemStack); } public void setItemStack(@Nullable ItemStack itemStack) { if (itemStack != null) { Preconditions.checkArgument(0 < itemStack.getAmount() && itemStack.getAmount() <= 64, "itemStack's amount must be between 1 and 64"); } - this.itemStack = itemStack; + this.itemStack = clone(itemStack); setChanged(); } + private ItemStack clone(@Nullable ItemStack itemStack) { + return itemStack != null ? itemStack.clone() : null; + } + @Override public double getHeight() { return 0.7;