Use ItemData#equals when finding item name

Avoids accidentally causing an NPE while comparing potion data.
This commit is contained in:
md678685 2018-10-13 16:09:45 +01:00
parent f78887a02e
commit 85111f25cb

View File

@ -194,8 +194,10 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
potion = ((PotionMeta) item.getItemMeta()).getBasePotionData(); potion = ((PotionMeta) item.getItemMeta()).getBasePotionData();
} }
ItemData data = new ItemData(type, potion);
for (Map.Entry<String, ItemData> entry : items.entrySet()) { for (Map.Entry<String, ItemData> entry : items.entrySet()) {
if (entry.getValue().getMaterial().equals(type) && entry.getValue().getPotionData().equals(potion)) { if (entry.getValue().equals(data)) {
return entry.getKey(); return entry.getKey();
} }
} }
@ -399,6 +401,11 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
private Material material; private Material material;
private PotionData potionData; private PotionData potionData;
public ItemData(Material material, PotionData potionData) {
this.material = material;
this.potionData = potionData;
}
@Override @Override
public int hashCode() { public int hashCode() {
return (31 * material.hashCode()) ^ potionData.hashCode(); return (31 * material.hashCode()) ^ potionData.hashCode();
@ -412,8 +419,8 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
if (!(o instanceof ItemData)) { if (!(o instanceof ItemData)) {
return false; return false;
} }
ItemData pairo = (ItemData) o; ItemData that = (ItemData) o;
return this.material == pairo.getMaterial() && potionDataEquals(pairo); return this.material == that.getMaterial() && potionDataEquals(that);
} }
public String getItemName() { public String getItemName() {