From 5b15f59e53ea23dacbcd1fa77ea955aa5e39fe39 Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Mon, 3 Apr 2023 11:40:27 -0700 Subject: [PATCH 1/4] Added custom model data to item-paywall= --- .../commandtags/CommandTags.java | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index a54ab78..3f4be7d 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -200,22 +200,30 @@ public class CommandTags { } } case "item-paywall=": { - //if player uses item-paywall= [Material] [Amount] [Id] + //if player uses item-paywall= [Material] [Amount] [Id] [CustomModelData] //player can use item-paywall= [custom-item] List cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List remCont = new ArrayList<>(); + String[] args = command.split("\\s"); try { short id = 0; - if (command.split("\\s").length == 4) { - id = Short.parseShort(command.split("\\s")[3]); + int customData = 0; + for(String val : args) { + if(val.startsWith("id:")) { + id = Short.parseShort(val.substring(3)); + continue; + } + if(val.startsWith("custom-data:")) { + customData = Integer.parseInt(val.substring(12)); + } } //create the item to be removed ItemStack sellItem; - if (Material.matchMaterial(command.split("\\s")[1]) == null) { - sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false); + if (Material.matchMaterial(args[1]) == null) { + sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false); } else { - sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])), Integer.parseInt(command.split("\\s")[2]), id); + sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]), id); } //this is not a boolean because it needs to return an int PaywallOutput removedItem = PaywallOutput.Blocked; @@ -229,7 +237,7 @@ public class CommandTags { continue; } - if (Material.matchMaterial(command.split("\\s")[1]) == null) { + if (Material.matchMaterial(args[1]) == null) { //item-paywall is a custom item as it is not a material if (plugin.itemCreate.isIdentical(sellItem, cont.get(f))) { ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f); @@ -243,8 +251,8 @@ public class CommandTags { //if custom item is a mmo item (1.14+ for the API) try { - if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + command.split("\\s")[1] + ".material").startsWith("mmo=")) { - String customItemMaterial = panel.getConfig().getString("custom-item." + command.split("\\s")[1] + ".material"); + if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + args[1] + ".material").startsWith("mmo=")) { + String customItemMaterial = panel.getConfig().getString("custom-item." + args[1] + ".material"); String mmoType = customItemMaterial.split("\\s")[1]; String mmoID = customItemMaterial.split("\\s")[2]; @@ -276,6 +284,15 @@ public class CommandTags { } else { //if the item is a standard material if (cont.get(f).getType() == sellItem.getType()) { + if(customData != 0){ + if(!cont.get(f).hasItemMeta()){ + continue; + } + if(Objects.requireNonNull(cont.get(f).getItemMeta()).getCustomModelData() != customData){ + continue; + } + } + ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); From 5f30c6edcb1a6a210c3f148d3145c1f686c2e01e Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Wed, 5 Apr 2023 17:49:34 -0700 Subject: [PATCH 2/4] 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); From a0760da81a930b4b87b91b84b8dd315875a8a973 Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Wed, 5 Apr 2023 18:09:35 -0700 Subject: [PATCH 3/4] Fixed item paywall id checks. --- .../commandpanels/commandtags/CommandTags.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index 6dab4ab..bfc54bd 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -206,11 +206,11 @@ public class CommandTags { List remCont = new ArrayList<>(); String[] args = command.split("\\s"); try { - short id = 0; + byte id = -1; int customData = 0; for(String val : args) { if(val.startsWith("id:")) { - id = Short.parseShort(val.substring(3)); + id = Byte.parseByte(val.substring(3)); continue; } if(val.startsWith("custom-data:")) { @@ -223,7 +223,7 @@ public class CommandTags { if (Material.matchMaterial(args[1]) == null) { sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false); } else { - sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]), id); + sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])); } //this is not a boolean because it needs to return an int PaywallOutput removedItem = PaywallOutput.Blocked; @@ -294,6 +294,11 @@ public class CommandTags { } } + //Check if the item matches the id set. If not continue to next in loop. + if(id != -1 && cont.get(f).getDurability() != id){ + continue; + } + //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(); From 55dd00656fbbc5e40f917ab8018d17c7697457de Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Fri, 7 Apr 2023 11:25:39 -0700 Subject: [PATCH 4/4] Added NOCUSTOMDATA to item-paywall= and the sell='s --- .../commandtags/CommandTags.java | 33 +++++++++++++------ .../tags/economy/SellItemTags.java | 14 ++++++-- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index bfc54bd..276e297 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -208,6 +208,7 @@ public class CommandTags { try { byte id = -1; int customData = 0; + boolean noCustom = false; for(String val : args) { if(val.startsWith("id:")) { id = Byte.parseByte(val.substring(3)); @@ -216,6 +217,9 @@ public class CommandTags { if(val.startsWith("custom-data:")) { customData = Integer.parseInt(val.substring(12)); } + if(val.contains("NOCUSTOMDATA")) { + noCustom = true; + } } //create the item to be removed @@ -237,9 +241,11 @@ public class CommandTags { continue; } + ItemStack itm = cont.get(f); + if (Material.matchMaterial(args[1]) == null) { //item-paywall is a custom item as it is not a material - if (plugin.itemCreate.isIdentical(sellItem, cont.get(f))) { + if (plugin.itemCreate.isIdentical(sellItem, itm)) { ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); @@ -256,18 +262,18 @@ public class CommandTags { String mmoType = customItemMaterial.split("\\s")[1]; String mmoID = customItemMaterial.split("\\s")[2]; - if (plugin.isMMOItem(cont.get(f), mmoType, mmoID) && sellItem.getAmount() <= cont.get(f).getAmount()) { + if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) { if (plugin.inventorySaver.hasNormalInventory(p)) { - p.getInventory().getItem(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount()); + p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount()); p.updateInventory(); } else { - cont.get(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount()); + itm.setAmount(itm.getAmount() - sellItem.getAmount()); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); } removedItem = PaywallOutput.Passed; break; } - if (plugin.isMMOItem(cont.get(f), mmoType, mmoID)) { + if (plugin.isMMOItem(itm, mmoType, mmoID)) { ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); @@ -283,24 +289,31 @@ public class CommandTags { } else { //if the item is a standard material - if (cont.get(f).getType() == sellItem.getType()) { + if (itm.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()){ + if(!itm.hasItemMeta()){ continue; } - if(Objects.requireNonNull(cont.get(f).getItemMeta()).getCustomModelData() != customData){ + if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){ continue; } } //Check if the item matches the id set. If not continue to next in loop. - if(id != -1 && cont.get(f).getDurability() != id){ + if(id != -1 && itm.getDurability() != id){ continue; } + //Check if noCustom is set and if the item has custom data. If so continue to next in loop. + if(noCustom && itm.hasItemMeta()){ + if(Objects.requireNonNull(itm.getItemMeta()).hasCustomModelData()){ + continue; + } + } + //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); + ItemStack add = new ItemStack(itm.getType(), itm.getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); if (remainingAmount <= 0) { diff --git a/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java b/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java index 5b9426a..8b2b2d7 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java @@ -101,6 +101,7 @@ public class SellItemTags implements Listener { byte id = -1; String potion = "false"; int customData = 0; + boolean noCustom = false; for(String argsTemp : args){ if(argsTemp.startsWith("potion:")){ potion = argsTemp.replace("potion:",""); @@ -111,6 +112,9 @@ public class SellItemTags implements Listener { if (argsTemp.startsWith("custom-data:")) { customData = Integer.parseInt(argsTemp.replace("custom-data:", "")); } + if (argsTemp.contains("NOCUSTOMDATA")) { + noCustom = true; + } } //create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount) @@ -131,11 +135,17 @@ public class SellItemTags implements Listener { return 0; } } - if (id != -1) { - if (itm.getDurability() != id) { + //Check if the item matches the id set. If not continue to next in loop. + if(id != -1 && itm.getDurability() != id){ + continue; + } + //Check if noCustom is set and if the item has custom data. If so continue to next in loop. + if(noCustom && cont.get(f).hasItemMeta()){ + if(Objects.requireNonNull(cont.get(f).getItemMeta()).hasCustomModelData()){ continue; } } + //Check if custom model data is set and if the item has that data. If not continue to next in loop. if (customData != 0) { if (!itm.hasItemMeta()) { continue;