From 0023760c909ab4a5931ccf4c08107460d0494f0d Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Sun, 5 May 2024 18:40:05 -0700 Subject: [PATCH] Changes to item-paywall= --- .../classresources/ItemCreation.java | 6 +- .../commandtags/CommandTags.java | 88 +++++-------------- .../commandpanels/nbt/NBTManager.java | 3 +- 3 files changed, 25 insertions(+), 72 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java index fde6ff9..ed55332 100644 --- a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java +++ b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java @@ -47,7 +47,7 @@ public class ItemCreation { return null; } ItemStack s = null; - boolean hideAttributes = true; + boolean hideAttributes = false; String mat; String matraw; String skullname; @@ -168,7 +168,7 @@ public class ItemCreation { if(itemSection.contains("itemType")){ //if hidden, reverse if(itemSection.getStringList("itemType").contains("noAttributes")){ - hideAttributes = false; + hideAttributes = true; /// Swapped for better isIdentical checks. } if(itemSection.getStringList("itemType").contains("noNBT")){ addNBT = false; @@ -348,7 +348,7 @@ public class ItemCreation { p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " material: " + itemSection.getString("material"))); return null; } - plugin.setName(panel,s, itemSection.getString("name"), itemSection.getStringList("lore"), p, placeholders, colours, hideAttributes); + s = plugin.setName(panel,s, itemSection.getString("name"), itemSection.getStringList("lore"), p, placeholders, colours, hideAttributes); return s; } diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index 565017c..91c36f2 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -237,19 +237,14 @@ public class CommandTags { HashMap remCont = new HashMap<>(); String[] args = command.split("\\s"); try { - int id = -1; - for (String val : args) { - if (val.startsWith("id:")) { - id = Integer.parseInt(val.substring(3)); - } - } - //create the item to be removed ItemStack sellItem; if (Material.matchMaterial(args[1]) == null) { + //If custom item set to custom item data. sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false); sellItem.setAmount(Integer.parseInt(args[2])); } else { + //If normal just set material. 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 @@ -266,68 +261,22 @@ public class CommandTags { continue; } - ItemStack itm = cont.get(f); + ItemStack itm = cont.get(f); //Get item/slot - if (Material.matchMaterial(args[1]) == null) { - //if custom item is a mmo item (1.14+ for the API) - try { - 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]; - - if (plugin.isMMOItem(itm, mmoType, mmoID)) { - ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount()); - remainingAmount -= add.getAmount(); - if (removal) remCont.put(f,add); - if (remainingAmount <= 0) { - removedItem = PaywallOutput.Passed; - break; - } - } - continue; //This stops the other custom item section from reading and adding false numbers. - } - } catch (Exception ex) { - plugin.debug(ex, p); - } - - //item-paywall is a custom item as it is not a material - if (plugin.itemCreate.isIdentical(sellItem, itm, Objects.requireNonNull(panel.getConfig().getConfigurationSection("custom-item." + args[1])).contains("nbt"))) { - ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount()); - remainingAmount -= add.getAmount(); - if (removal) remCont.put(f,add); - if (remainingAmount <= 0) { - removedItem = PaywallOutput.Passed; - break; - } - } - - } else { - //if the item is a standard material - if (itm.getType() == sellItem.getType()) { - if(itm.hasItemMeta() && !ignoreNBT){ - //If item has custom meta continue to next item. - continue; - } - - //Check if the item matches the id set. If not continue to next in loop. - if (id != -1 && itm.getDurability() != id) { - continue; - } - - //Adding item to the remove list then checking if we have reached the required amount. - ItemStack add = new ItemStack(itm.getType(), itm.getAmount()); - remainingAmount -= add.getAmount(); - if (removal) remCont.put(f,add); - if (remainingAmount <= 0) { - removedItem = PaywallOutput.Passed; - break; - } + if(plugin.itemCreate.isIdentical(sellItem,itm, !ignoreNBT)){ //Check if both sell item and item in slot are identical + //Adding item to the remove list then checking if we have reached the required amount. + ItemStack add = new ItemStack(itm.getType(), itm.getAmount()); + remainingAmount -= add.getAmount(); + if (removal) remCont.put(f,add); + if (remainingAmount <= 0) { + removedItem = PaywallOutput.Passed; + break; } } } if (remainingAmount <= 0) { + //If we have reached the end of the paywall. for(Map.Entry entry : remCont.entrySet()) { ItemStack remItem = entry.getValue(); @@ -335,22 +284,25 @@ public class CommandTags { if (sellItem.getAmount() < remItem.getAmount()) { if (plugin.inventorySaver.hasNormalInventory(p)) { if (removal) + //Normal inventory p.getInventory().getItem(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount()); p.updateInventory(); } else { if (removal) + //Saved inventory cont.get(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount()); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); } } else { //If its anywhere but the last in loop just get rid of the items. if (plugin.inventorySaver.hasNormalInventory(p)) { - if (removal) p.getInventory().setItem(entry.getKey(), null); - //p.getInventory().remove(entry.getValue()); - //p.getInventory().getItem(entry.getKey()).setAmount(0); + if (removal) + //Normal inventory + p.getInventory().setItem(entry.getKey(), null); p.updateInventory(); } else { - if (removal) cont.remove(entry.getValue()); - //cont.get(entry.getKey()).setAmount(0); + if (removal) + //Saved inventory + cont.remove(entry.getValue()); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); } } diff --git a/src/me/rockyhawk/commandpanels/nbt/NBTManager.java b/src/me/rockyhawk/commandpanels/nbt/NBTManager.java index 99ff974..61e3c11 100644 --- a/src/me/rockyhawk/commandpanels/nbt/NBTManager.java +++ b/src/me/rockyhawk/commandpanels/nbt/NBTManager.java @@ -33,6 +33,7 @@ public class NBTManager { public String getData(ItemStack item, String key){ NBTItem nbti = new NBTItem(item); if(!nbti.hasNBTData()) return ""; - return nbti.getString(key); + //nbti.getOrDefault(key, ""); + return nbti.getOrDefault(key, ""); } } \ No newline at end of file