From 5f30c6edcb1a6a210c3f148d3145c1f686c2e01e Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Wed, 5 Apr 2023 17:49:34 -0700 Subject: [PATCH] Added custom-data: to the sellall= and sell= --- .../commandtags/CommandTags.java | 7 +++- .../tags/economy/SellItemTags.java | 42 +++++++++++-------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index 3f4be7d..6dab4ab 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -200,7 +200,7 @@ public class CommandTags { } } case "item-paywall=": { - //if player uses item-paywall= [Material] [Amount] [Id] [CustomModelData] + //if player uses item-paywall= [Material] [Amount] //player can use item-paywall= [custom-item] List cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List remCont = new ArrayList<>(); @@ -284,6 +284,7 @@ public class CommandTags { } else { //if the item is a standard material if (cont.get(f).getType() == sellItem.getType()) { + //Checking for custom model data. If it does not have or not the correct number go to next in loop. if(customData != 0){ if(!cont.get(f).hasItemMeta()){ continue; @@ -293,6 +294,7 @@ public class CommandTags { } } + //Adding item to the remove list then checking if we have reached the required amount. ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); @@ -308,6 +310,7 @@ public class CommandTags { for (int f = 0; f <= remCont.size() - 1; f++) { ItemStack remItem = remCont.get(f); + //Check if its the last item in the loop and only subtract the remaining amount. if(f == remCont.size() - 1){ if (plugin.inventorySaver.hasNormalInventory(p)) { p.getInventory().getItem((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount()); @@ -316,7 +319,7 @@ public class CommandTags { cont.get((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount()); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); } - } else { + } else { //If its anywhere but the last in loop just get rid of the items. if (plugin.inventorySaver.hasNormalInventory(p)) { p.getInventory().getItem(remItem.getDurability()).setAmount(0); p.updateInventory(); diff --git a/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java b/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java index 291ad49..5b9426a 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java @@ -29,7 +29,7 @@ public class SellItemTags implements Listener { public void commandTag(CommandTagEvent e){ if(e.name.equalsIgnoreCase("sell=")){ e.commandTagUsed(); - //if player uses sell= it will be eg. sell= [enchanted:KNOCKBACK:1] [potion:JUMP] + //if player uses sell= it will be eg. sell= [enchanted:KNOCKBACK:1] [potion:JUMP] [custom-data:#] try { if (plugin.econ != null) { int sold = removeItem(e.p, e.args, false); @@ -98,6 +98,20 @@ public class SellItemTags implements Listener { //get inventory slots and then an empty list to store slots that have the item to sell List cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List remCont = new ArrayList<>(); + byte id = -1; + String potion = "false"; + int customData = 0; + for(String argsTemp : args){ + if(argsTemp.startsWith("potion:")){ + potion = argsTemp.replace("potion:",""); + } + if (argsTemp.startsWith("id:")) { + id = Byte.parseByte(argsTemp.replace("id:", "")); + } + if (argsTemp.startsWith("custom-data:")) { + customData = Integer.parseInt(argsTemp.replace("custom-data:", "")); + } + } //create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount) ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), removeAll ? 0 : Integer.parseInt(args[2])); @@ -107,23 +121,6 @@ public class SellItemTags implements Listener { ItemStack remItm; if (itm != null && itm.getType().equals(sellItem.getType())) { remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f); - //determine if the command contains parameters for extensions - String potion = "false"; - for(String argsTemp : args){ - if(argsTemp.startsWith("potion:")){ - potion = argsTemp.replace("potion:",""); - } - } - //legacy ID - byte id = -1; - if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) { - for (String argsTemp : args) { - if (argsTemp.startsWith("id:")) { - id = Byte.parseByte(argsTemp.replace("id:", "")); - break; - } - } - } //check to ensure any extensions are checked try { if (!potion.equals("false")) { @@ -139,6 +136,15 @@ public class SellItemTags implements Listener { continue; } } + if (customData != 0) { + if (!itm.hasItemMeta()) { + continue; + } else { + if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){ + continue; + } + } + } }catch(Exception exc){ //skip if it cannot do unless plugin.debug is enabled plugin.debug(exc,p);