diff --git a/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java b/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java index 238751b6..e58f280d 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java +++ b/src/main/java/org/shanerx/tradeshop/commands/EditCommand.java @@ -35,6 +35,7 @@ import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.FireworkMeta; +import org.bukkit.inventory.meta.ItemMeta; import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.enumys.Message; import org.shanerx.tradeshop.enumys.Permissions; @@ -256,9 +257,21 @@ public void edit() { } private StaticGuiElement shopItemEditMenu(int index, boolean isCost) { - return new StaticGuiElement('e', (isCost ? costItems : productItems).get(index).getItemStack(), click2 -> { - ShopItemStack item = (isCost ? costItems : productItems).get(index), - tempItem = item.clone(); + ShopItemStack item = (isCost ? costItems : productItems).get(index).clone(); + ItemStack tempStack = item.getItemStack(); + ItemMeta tempMeta = tempStack.getItemMeta(); + List newLore = new ArrayList<>(); + newLore.add(colorize("&8Amount &7ยป &f" + item.getAmount())); + + if (tempMeta != null && tempMeta.hasLore()) { + newLore.add(""); + newLore.addAll(tempMeta.getLore()); + } + + tempMeta.setLore(newLore); + tempStack.setItemMeta(tempMeta); + + return new StaticGuiElement('e', tempStack, click2 -> { InventoryGui itemEdit = new InventoryGui(plugin, "Edit Cost Item", ITEM_LAYOUT); GuiElementGroup itemGroup = new GuiElementGroup('g'); @@ -267,7 +280,7 @@ private StaticGuiElement shopItemEditMenu(int index, boolean isCost) { // Save and Back itemEdit.addElement(new StaticGuiElement('s', new ItemStack(Material.ANVIL), click3 -> { - (isCost ? costItems : productItems).set((isCost ? costItems : productItems).indexOf(item), tempItem); + (isCost ? costItems : productItems).set(index, item); InventoryGui.goBack(pSender); return true; }, "Save Changes")); @@ -288,36 +301,36 @@ private StaticGuiElement shopItemEditMenu(int index, boolean isCost) { //Add new item settings below if (item.getItemStack().getItemMeta() instanceof Damageable) { - itemGroup.addElement(numericalOption(ShopItemStackSettingKeys.COMPARE_DURABILITY, tempItem, new ItemStack[]{ + itemGroup.addElement(numericalOption(ShopItemStackSettingKeys.COMPARE_DURABILITY, item, new ItemStack[]{ FALSE_ITEM, new ItemStack(Material.IRON_BLOCK), TRUE_ITEM, new ItemStack(Material.GOLD_BLOCK) })); } - if (tempItem.getItemStack().getItemMeta() instanceof BookMeta) { - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_BOOK_AUTHOR, tempItem, TRUE_ITEM, FALSE_ITEM)); - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_BOOK_PAGES, tempItem, TRUE_ITEM, FALSE_ITEM)); + if (tempMeta instanceof BookMeta) { + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_BOOK_AUTHOR, item, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_BOOK_PAGES, item, TRUE_ITEM, FALSE_ITEM)); } - if (tempItem.getItemStack().getItemMeta() instanceof FireworkMeta) { - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_FIREWORK_DURATION, tempItem, TRUE_ITEM, FALSE_ITEM)); - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_FIREWORK_EFFECTS, tempItem, TRUE_ITEM, FALSE_ITEM)); + if (tempMeta instanceof FireworkMeta) { + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_FIREWORK_DURATION, item, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_FIREWORK_EFFECTS, item, TRUE_ITEM, FALSE_ITEM)); } - if (tempItem.getItemStack().getType().toString().endsWith("SHULKER_BOX")) { - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_SHULKER_INVENTORY, tempItem, TRUE_ITEM, FALSE_ITEM)); + if (tempStack.getType().toString().endsWith("SHULKER_BOX")) { + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_SHULKER_INVENTORY, item, TRUE_ITEM, FALSE_ITEM)); } - if (plugin.getVersion().isAtLeast(1, 17) && tempItem.getItemStack().getType().equals(Material.BUNDLE)) { - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_BUNDLE_INVENTORY, tempItem, TRUE_ITEM, FALSE_ITEM)); + if (plugin.getVersion().isAtLeast(1, 17) && tempStack.getType().equals(Material.BUNDLE)) { + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_BUNDLE_INVENTORY, item, TRUE_ITEM, FALSE_ITEM)); } - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_NAME, tempItem, TRUE_ITEM, FALSE_ITEM)); - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_LORE, tempItem, TRUE_ITEM, FALSE_ITEM)); - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_UNBREAKABLE, tempItem, TRUE_ITEM, FALSE_ITEM)); - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_ENCHANTMENTS, tempItem, TRUE_ITEM, FALSE_ITEM)); - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_ITEM_FLAGS, tempItem, TRUE_ITEM, FALSE_ITEM)); - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_CUSTOM_MODEL_DATA, tempItem, TRUE_ITEM, FALSE_ITEM)); - itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_ATTRIBUTE_MODIFIER, tempItem, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_NAME, item, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_LORE, item, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_UNBREAKABLE, item, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_ENCHANTMENTS, item, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_ITEM_FLAGS, item, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_CUSTOM_MODEL_DATA, item, TRUE_ITEM, FALSE_ITEM)); + itemGroup.addElement(booleanOption(ShopItemStackSettingKeys.COMPARE_ATTRIBUTE_MODIFIER, item, TRUE_ITEM, FALSE_ITEM)); itemEdit.addElement(itemGroup); diff --git a/src/main/java/org/shanerx/tradeshop/commands/WhatCommand.java b/src/main/java/org/shanerx/tradeshop/commands/WhatCommand.java index 8c38bab1..880c165c 100644 --- a/src/main/java/org/shanerx/tradeshop/commands/WhatCommand.java +++ b/src/main/java/org/shanerx/tradeshop/commands/WhatCommand.java @@ -33,11 +33,15 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; import org.shanerx.tradeshop.TradeShop; import org.shanerx.tradeshop.enumys.*; import org.shanerx.tradeshop.objects.Shop; import org.shanerx.tradeshop.objects.ShopItemStack; +import java.util.ArrayList; +import java.util.List; + public class WhatCommand extends CommandRunner { public WhatCommand(TradeShop instance, CommandPass command) { @@ -126,7 +130,19 @@ private String stateText(int state) { } private StaticGuiElement shopitemViewMenu(ShopItemStack item) { - return new StaticGuiElement('e', item.getItemStack(), click2 -> { + ItemStack tempStack = item.getItemStack().clone(); + ItemMeta tempMeta = tempStack.getItemMeta(); + List newLore = new ArrayList<>(); + newLore.add("Amount: " + item.getAmount()); + + if (tempMeta != null && tempMeta.hasLore()) { + newLore.add(""); + newLore.addAll(tempMeta.getLore()); + } + + tempMeta.setLore(newLore); + tempStack.setItemMeta(tempMeta); + return new StaticGuiElement('e', tempStack, click2 -> { InventoryGui itemView = new InventoryGui(plugin, "Edit Cost Item", ITEM_LAYOUT); GuiElementGroup itemGroup = new GuiElementGroup('g'); @@ -134,7 +150,7 @@ private StaticGuiElement shopitemViewMenu(ShopItemStack item) { itemView.addElement(new StaticGuiElement('a', new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); - itemGroup.addElement(new StaticGuiElement('e', item.getItemStack())); + itemGroup.addElement(new StaticGuiElement('e', tempStack)); itemGroup.addElement(new StaticGuiElement('e', settingItem(item.getShopSettingAsBoolean(ShopItemStackSettingKeys.COMPARE_NAME)), "Compare Name", "State: " + item.getShopSettingAsBoolean(ShopItemStackSettingKeys.COMPARE_NAME))); itemGroup.addElement(new StaticGuiElement('e', settingItem(item.getShopSettingAsBoolean(ShopItemStackSettingKeys.COMPARE_LORE)), "Compare Lore", "State: " + item.getShopSettingAsBoolean(ShopItemStackSettingKeys.COMPARE_LORE))); diff --git a/src/main/java/org/shanerx/tradeshop/objects/Shop.java b/src/main/java/org/shanerx/tradeshop/objects/Shop.java index 07a056f6..b8b39cba 100644 --- a/src/main/java/org/shanerx/tradeshop/objects/Shop.java +++ b/src/main/java/org/shanerx/tradeshop/objects/Shop.java @@ -459,6 +459,7 @@ public void addCost(ItemStack newItem) { if (!utils.isValidType(newItem.getType())) return; + /* Added stacks are separated by stack size int amount = newItem.getAmount(); List items = new ArrayList<>(); while (amount > 0) { @@ -476,6 +477,30 @@ public void addCost(ItemStack newItem) { } items.forEach((ItemStack iS) -> cost.add(new ShopItemStack(iS))); + + */ + + ///* Added stacks are not separated and are added ontop of existing similar stacks + ShopItemStack toAddShopItemStack = new ShopItemStack(newItem), + toRemoveShopItemStack = null; + + + for (ShopItemStack shopItemStack : getCost()) { + if (shopItemStack.getItemStack().getType().equals(newItem.getType()) && shopItemStack.isSimilar(newItem)) { + toRemoveShopItemStack = shopItemStack; + toAddShopItemStack = shopItemStack.clone(); + toAddShopItemStack.setAmount(shopItemStack.getAmount() + newItem.getAmount()); + break; + } + } + + if (toRemoveShopItemStack != null) + cost.remove(toRemoveShopItemStack); + + cost.add(toAddShopItemStack); + //*/ + + if (!getShopType().isITrade() && chestLoc != null) cost.removeIf(item -> item.getItemStack().getType().toString().endsWith("SHULKER_BOX") && getInventoryLocation().getBlock().getType().toString().endsWith("SHULKER_BOX")); @@ -539,6 +564,7 @@ public void addProduct(ItemStack newItem) { if (!utils.isValidType(newItem.getType())) return; + /* Added stacks are separated by stack size int amount = newItem.getAmount(); List items = new ArrayList<>(); while (amount > 0) { @@ -556,6 +582,28 @@ public void addProduct(ItemStack newItem) { } items.forEach((ItemStack iS) -> product.add(new ShopItemStack(iS))); + */ + + + ///* Added stacks are not separated and are added ontop of existing similar stacks + ShopItemStack toAddShopItemStack = new ShopItemStack(newItem), + toRemoveShopItemStack = null; + + + for (ShopItemStack shopItemStack : getProduct()) { + if (shopItemStack.getItemStack().getType().equals(newItem.getType()) && shopItemStack.isSimilar(newItem)) { + toRemoveShopItemStack = shopItemStack; + toAddShopItemStack = shopItemStack.clone(); + toAddShopItemStack.setAmount(shopItemStack.getAmount() + newItem.getAmount()); + break; + } + } + + if (toRemoveShopItemStack != null) + product.remove(toRemoveShopItemStack); + + product.add(toAddShopItemStack); + //*/ saveShop(); updateSign(); diff --git a/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java b/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java index 2eafa654..b4ee028a 100644 --- a/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java +++ b/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java @@ -159,6 +159,15 @@ public boolean setShopSettings(ShopItemStackSettingKeys key, ObjectHolder val return false; } + public int getAmount() { + return itemStack.getAmount(); + } + + public void setAmount(int amount) { + itemStack.setAmount(amount); + toBase64(); + } + public String getItemStackB64() { return itemStackB64; }