Add defensive copy for ItemStack

This commit is contained in:
filoghost 2021-07-24 15:20:00 +02:00
parent ce2dfd993b
commit 21280b0b1f

View File

@ -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;