Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- `mat:<material>`*~
- `amt:<integer>`*~
- `data:<integer>`*~
- `itemmodel:<string>`*~
- `custommodeldata:<integer>`*~
- `lorecontains:<string>`~
- `loreequals:<string>` (Separate lines with `|`)*~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class ItemWrapper {
private boolean checkLoreEquals;
private boolean checkMaterialContains;
private boolean checkDurability;
private boolean checkItemModel;
private boolean checkCustomData;
private boolean checkAmount;
private boolean checkType;
Expand All @@ -105,6 +106,7 @@ public class ItemWrapper {
private boolean remove;
private String material;
private short data;
private NamespacedKey itemModel;
private int customData;
private int amount;
private String name;
Expand Down Expand Up @@ -146,6 +148,8 @@ public String toString() {
+ checkMaterialContains
+ ", checkDurability="
+ checkDurability
+ ", checkItemModel="
+ checkItemModel
+ ", checkCustomData="
+ checkCustomData
+ ", checkAmount="
Expand Down Expand Up @@ -174,6 +178,8 @@ public String toString() {
+ material
+ ", data="
+ data
+ ", itemModel="
+ itemModel
+ ", customData="
+ customData
+ ", amount="
Expand Down Expand Up @@ -222,6 +228,14 @@ public short getDurability() {
protected void setDurability(short durability) {
this.data = durability;
}

public NamespacedKey getItemModel() {
return this.itemModel;
}

protected void setItemModel(NamespacedKey itemModel) {
this.itemModel = itemModel;
}

public int getCustomData() {
return this.customData;
Expand Down Expand Up @@ -326,6 +340,14 @@ protected void setCheckDurability(boolean checkDurability) {
public boolean shouldCheckDurability() {
return this.checkDurability;
}

protected void setCheckItemModel(boolean checkItemModel) {
this.checkItemModel = checkItemModel;
}

public boolean shouldCheckItemModel() {
return this.checkItemModel;
}

protected void setCheckCustomData(boolean checkCustomData) {
this.checkCustomData = checkCustomData;
Expand Down Expand Up @@ -544,6 +566,11 @@ public String onPlaceholderRequest(Player p, String args) {
wrapper.setCheckType(true);
wrapper.setCheckAmount(true);
wrapper.setCheckDurability(true);
try {
Class.forName("org.bukkit.inventory.meta.ItemMeta").getMethod("hasItemModel", null);
wrapper.setCheckItemModel(true);
} catch (Exception e) {
}
try {
Class.forName("org.bukkit.inventory.meta.ItemMeta").getMethod("hasCustomModelData", null);
wrapper.setCheckCustomData(true);
Expand Down Expand Up @@ -581,6 +608,10 @@ public String onPlaceholderRequest(Player p, String args) {
data = multiMod ? data += "data:" : "";
data += item.getDurability() + " &r";
}
if (wrapper.shouldCheckItemModel() && item.hasItemMeta() && item.getItemMeta().hasItemModel()) {
data = multiMod ? data += "itemmodel:" : "";
data += item.getItemMeta().getItemModel() + " &r";
}
if (wrapper.shouldCheckCustomData() && item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) {
data = multiMod ? data += "custommodeldata:" : "";
data += item.getItemMeta().getCustomModelData() + " &r";
Expand Down Expand Up @@ -805,6 +836,9 @@ private String giveItem(ItemWrapper wrapper, Player p) {
return "error";
}
}
if (wrapper.shouldCheckItemModel()) {
meta.setItemModel(wrapper.getItemModel());
}
if (wrapper.shouldCheckCustomData()) {
meta.setCustomModelData(wrapper.getCustomData());
}
Expand Down Expand Up @@ -909,6 +943,18 @@ private int getItemAmount(ItemWrapper wrapper, Player p, ItemStack... items) {
continue;
}
ItemMeta toCheckMeta = toCheck.getItemMeta();
if (wrapper.shouldCheckItemModel()) {
try {
if (!toCheckMeta.hasItemModel())
continue;
if (wrapper.getItemModel() != toCheckMeta.getItemModel()) {
continue;
}
} catch (NoSuchMethodError e) {
PlaceholderAPIPlugin.getInstance().getLogger().log(Level.WARNING,
"[CheckItem Expansion] ItemModel doesn't exist before 1.21.2!");
}
}
if (wrapper.shouldCheckCustomData()) {
try {
if (!toCheckMeta.hasCustomModelData())
Expand Down Expand Up @@ -1199,6 +1245,12 @@ private ItemWrapper getWrapper(ItemWrapper wrapper, String input, Player p) {
continue;
}
}
if (part.startsWith("itemmodel:")) {
part = part.replace("itemmodel:", "");
wrapper.setItemModel(NamespacedKey.fromString(PlaceholderAPI.setBracketPlaceholders(p, part)));
wrapper.setCheckItemModel(true);
continue;
}
if (part.startsWith("custommodeldata:")) {
part = part.replace("custommodeldata:", "");
wrapper.setCustomData(getInt(PlaceholderAPI.setBracketPlaceholders(p, part)));
Expand Down