Rename data value to durability

This commit is contained in:
filoghost 2020-06-11 20:36:36 +02:00
parent 93724b5096
commit d1ab1fefc7
7 changed files with 36 additions and 36 deletions

View File

@ -42,7 +42,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon {
private Material material;
private int amount;
private short dataValue;
private short durability;
private String nbtData;
private String name;
@ -96,15 +96,15 @@ public class ConfigurableIconImpl implements ConfigurableIcon {
}
@Override
public void setDurability(short dataValue) {
if (dataValue < 0) dataValue = 0;
public void setDurability(short durability) {
if (durability < 0) durability = 0;
this.dataValue = dataValue;
this.durability = durability;
}
@Override
public short getDurability() {
return dataValue;
return durability;
}
@Override
@ -317,7 +317,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon {
}
// If the material is not set, display BEDROCK
ItemStack itemStack = (material != null) ? new ItemStack(material, amount, dataValue) : new ItemStack(Material.BEDROCK, amount);
ItemStack itemStack = (material != null) ? new ItemStack(material, amount, durability) : new ItemStack(Material.BEDROCK, amount);
// First try to apply NBT data
if (nbtData != null) {

View File

@ -21,13 +21,13 @@ public class Lang extends SpecialConfig {
public String no_open_permission = "&cYou don't have permission &e{permission} &cto use this menu.";
public String default_no_icon_permission = "&cYou don't have permission for this icon.";
public String no_required_item = "&cYou must have &e{amount}x {material} &c(data value: {datavalue}) for this.";
public String no_required_item = "&cYou must have &e{amount}x {material} &c(durability: {datavalue}) for this.";
public String no_money = "&cYou need {money}$ for this.";
public String no_exp = "&cYou need {levels} XP levels for this.";
public String menu_not_found = "&cMenu not found! Please inform the staff.";
public String open_menu = "&aOpening the menu \"{menu}\".";
public String open_menu_others = "&aOpening the menu \"{menu}\" to {player}.";
public String any = "any"; // Used in no_required_item when data value is not restrictive
public String any = "any"; // Used in no_required_item when durability is not restrictive
public Lang(PluginConfig config) {
super(config);

View File

@ -189,7 +189,7 @@ public class AdvancedIcon extends ConfigurableIconImpl {
player.sendMessage(ChestCommands.getLang().no_required_item
.replace("{material}", MaterialsHelper.formatMaterial(item.getMaterial()))
.replace("{amount}", Integer.toString(item.getAmount()))
.replace("{datavalue}", item.hasRestrictiveDataValue() ? Short.toString(item.getDataValue()) : ChestCommands.getLang().any)
.replace("{datavalue}", item.hasRestrictiveDurability() ? Short.toString(item.getDurability()) : ChestCommands.getLang().any)
);
}
}

View File

@ -24,7 +24,7 @@ public class RequiredItem {
private Material material;
private int amount;
private short dataValue;
private short durability;
private boolean isDurabilityRestrictive = false;
public RequiredItem(Material material, int amount) {
@ -42,31 +42,31 @@ public class RequiredItem {
return amount;
}
public short getDataValue() {
return dataValue;
public short getDurability() {
return durability;
}
public void setRestrictiveDataValue(short data) {
Preconditions.checkArgument(data >= 0, "Data value cannot be negative");
public void setRestrictiveDurability(short durability) {
Preconditions.checkArgument(durability >= 0, "Durability cannot be negative");
this.dataValue = data;
this.durability = durability;
isDurabilityRestrictive = true;
}
public boolean hasRestrictiveDataValue() {
public boolean hasRestrictiveDurability() {
return isDurabilityRestrictive;
}
private boolean isValidDataValue(short data) {
private boolean isMatchingDurability(short data) {
if (!isDurabilityRestrictive) return true;
return data == this.dataValue;
return data == this.durability;
}
public boolean isItemContainedIn(Inventory inventory) {
int amountFound = 0;
for (ItemStack item : inventory.getContents()) {
if (item != null && item.getType() == material && isValidDataValue(item.getDurability())) {
if (item != null && item.getType() == material && isMatchingDurability(item.getDurability())) {
amountFound += item.getAmount();
}
}
@ -89,7 +89,7 @@ public class RequiredItem {
current = contents[i];
if (current != null && current.getType() == material && isValidDataValue(current.getDurability())) {
if (current != null && current.getType() == material && isMatchingDurability(current.getDurability())) {
if (current.getAmount() > itemsToTake) {
current.setAmount(current.getAmount() - itemsToTake);
return true;

View File

@ -100,7 +100,7 @@ public class IconParser {
try {
ItemStackParser itemReader = new ItemStackParser(material, true);
icon.setMaterial(itemReader.getMaterial());
icon.setDurability(itemReader.getDataValue());
icon.setDurability(itemReader.getDurability());
icon.setAmount(itemReader.getAmount());
} catch (FormatException e) {
errorCollector.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid ID: " + e.getMessage());
@ -222,8 +222,8 @@ public class IconParser {
try {
ItemStackParser itemReader = new ItemStackParser(serializedItem, true);
RequiredItem requiredItem = new RequiredItem(itemReader.getMaterial(), itemReader.getAmount());
if (itemReader.hasExplicitDataValue()) {
requiredItem.setRestrictiveDataValue(itemReader.getDataValue());
if (itemReader.hasExplicitDurability()) {
requiredItem.setRestrictiveDurability(itemReader.getDurability());
}
requiredItems.add(requiredItem);
} catch (FormatException e) {

View File

@ -24,8 +24,8 @@ public class ItemStackParser {
private Material material = Material.STONE; // In the worst case (bad exception handling) we just get stone
private int amount = 1;
private short dataValue = 0;
private boolean explicitDataValue = false;
private short durability = 0;
private boolean hasExplicitDurability = false;
/**
* Reads item in the format "id:data, amount"
@ -51,14 +51,14 @@ public class ItemStackParser {
}
// Read the optional data value
// Read the optional durability
String[] splitByColons = input.split(":");
if (splitByColons.length > 1) {
short dataValue = NumberParser.getPositiveShort(splitByColons[1], "invalid data value \"" + splitByColons[1] + "\"");
short durability = NumberParser.getPositiveShort(splitByColons[1], "invalid durability \"" + splitByColons[1] + "\"");
this.explicitDataValue = true;
this.dataValue = dataValue;
this.hasExplicitDurability = true;
this.durability = durability;
// Only keep the first part as input
input = splitByColons[0];
@ -80,16 +80,16 @@ public class ItemStackParser {
return amount;
}
public short getDataValue() {
return dataValue;
public short getDurability() {
return durability;
}
public boolean hasExplicitDataValue() {
return explicitDataValue;
public boolean hasExplicitDurability() {
return hasExplicitDurability;
}
public ItemStack createStack() {
return new ItemStack(material, amount, dataValue);
return new ItemStack(material, amount, durability);
}
}

View File

@ -154,8 +154,8 @@ public class MenuParser {
OpenTrigger openTrigger = new OpenTrigger(itemReader.getMaterial(), clickType);
if (itemReader.hasExplicitDataValue()) {
openTrigger.setRestrictiveDurability(itemReader.getDataValue());
if (itemReader.hasExplicitDurability()) {
openTrigger.setRestrictiveDurability(itemReader.getDurability());
}
} catch (FormatException e) {