mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-03-02 11:11:58 +01:00
Use ItemData#equals when finding item name
Avoids accidentally causing an NPE while comparing potion data.
This commit is contained in:
parent
f78887a02e
commit
85111f25cb
@ -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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user