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
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ private RequirementList getRequirements(FileConfiguration c, String path) {
wrapper.setAmount(c.getInt(rPath + ".amount", 1));
wrapper.hasData(c.contains(rPath + ".data") && c.isInt(rPath + ".data"));
wrapper.setData((short) c.getInt(rPath + ".data", 0));
wrapper.setDurability(c.getInt(rPath + ".durability", -1));

if (c.isString(rPath + ".name")) {
wrapper.setName(c.getString(rPath + ".name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ private boolean isRequiredItem(ItemStack itemToCheck, MenuHolder holder, Materia
if (wrapper.hasData() && itemToCheck.getDurability() != wrapper.getData()) return false;

ItemMeta metaToCheck = itemToCheck.getItemMeta();

if (wrapper.getDurability() != -1) {
if (!(metaToCheck instanceof Damageable damageable)) {
return false;
}

int maxDurability = damageable.hasMaxDamage() ? damageable.getMaxDamage() : itemToCheck.getType().getMaxDurability();
if (maxDurability <= 0) {
return false;
}

int currentDurability = maxDurability - damageable.getDamage();
if (currentDurability < wrapper.getDurability()) {
return false;
}
}

if (wrapper.isStrict()) {
if (metaToCheck != null) {
if (VersionHelper.IS_CUSTOM_MODEL_DATA && metaToCheck.hasCustomModelData()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ItemWrapper {
private CustomModelDataComponent customDataComponent = CustomModelDataComponent.builder();
private int customData = 0;
private int amount = 1;
private int durability = -1;

private boolean strict = false;
private boolean armor = false;
Expand Down Expand Up @@ -100,6 +101,14 @@ public void setAmount(int amount) {
this.amount = amount;
}

public int getDurability() {
return durability;
}

public void setDurability(int durability) {
this.durability = durability;
}

public boolean isStrict() {
return strict;
}
Expand Down