From d2af5fb0add876be1a1b01d163ed3caa1657f7c3 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 17 Aug 2019 14:07:51 +0200 Subject: [PATCH] Make ShopProduct abstract class --- .../shopchest/api/shop/ShopProduct.java | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/de/epiceric/shopchest/api/shop/ShopProduct.java b/api/src/main/java/de/epiceric/shopchest/api/shop/ShopProduct.java index 202b918..2d6b173 100644 --- a/api/src/main/java/de/epiceric/shopchest/api/shop/ShopProduct.java +++ b/api/src/main/java/de/epiceric/shopchest/api/shop/ShopProduct.java @@ -7,7 +7,14 @@ import org.bukkit.inventory.ItemStack; * * @since 1.13 */ -public interface ShopProduct { +public abstract class ShopProduct implements Cloneable { + private ItemStack itemStack; + private int amount; + + public ShopProduct(ItemStack itemStack, int amount) { + this.itemStack = itemStack; + this.amount = amount; + } /** * Gets a copy of this product's {@link ItemStack} with an amount of one @@ -15,7 +22,9 @@ public interface ShopProduct { * @return the item * @since 1.13 */ - ItemStack getItemStack(); + public ItemStack getItemStack() { + return itemStack.clone(); + } /** * Sets this product's {@link ItemStack} @@ -25,7 +34,10 @@ public interface ShopProduct { * @param itemStack the item * @since 1.13 */ - void setItemStack(ItemStack itemStack); + public void setItemStack(ItemStack itemStack) { + this.itemStack = itemStack.clone(); + this.itemStack.setAmount(1); + } /** * Gets the amount of items bought or sold in one transaction @@ -33,7 +45,9 @@ public interface ShopProduct { * @return the amount * @since 1.13 */ - int getAmount(); + public int getAmount() { + return amount; + } /** * Sets the amount of items bought or sold in one transaction @@ -41,7 +55,9 @@ public interface ShopProduct { * @param amount the amount * @since 1.13 */ - void setAmount(int amount); + public void setAmount(int amount) { + this.amount = amount; + } /** * Gets the localized name of this product's item in the configured langauge file @@ -49,6 +65,21 @@ public interface ShopProduct { * @return the localized name * @since 1.13 */ - String getLocalizedName(); + public abstract String getLocalizedName(); + + @Override + public ShopProduct clone() { + try { + ShopProduct shopProduct = (ShopProduct) super.clone(); + + if (this.itemStack != null) { + shopProduct.itemStack = this.itemStack.clone(); + } + + return shopProduct; + } catch (CloneNotSupportedException e) { + throw new Error(e); + } + } } \ No newline at end of file