Make ShopProduct abstract class

This commit is contained in:
Eric 2019-08-17 14:07:51 +02:00
parent 5c2f3022b5
commit d2af5fb0ad

View File

@ -7,7 +7,14 @@ import org.bukkit.inventory.ItemStack;
* *
* @since 1.13 * @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 * Gets a copy of this product's {@link ItemStack} with an amount of one
@ -15,7 +22,9 @@ public interface ShopProduct {
* @return the item * @return the item
* @since 1.13 * @since 1.13
*/ */
ItemStack getItemStack(); public ItemStack getItemStack() {
return itemStack.clone();
}
/** /**
* Sets this product's {@link ItemStack} * Sets this product's {@link ItemStack}
@ -25,7 +34,10 @@ public interface ShopProduct {
* @param itemStack the item * @param itemStack the item
* @since 1.13 * @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 * Gets the amount of items bought or sold in one transaction
@ -33,7 +45,9 @@ public interface ShopProduct {
* @return the amount * @return the amount
* @since 1.13 * @since 1.13
*/ */
int getAmount(); public int getAmount() {
return amount;
}
/** /**
* Sets the amount of items bought or sold in one transaction * Sets the amount of items bought or sold in one transaction
@ -41,7 +55,9 @@ public interface ShopProduct {
* @param amount the amount * @param amount the amount
* @since 1.13 * @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 * 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 * @return the localized name
* @since 1.13 * @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);
}
}
} }