Permalink
Browse files

Fix durability for legacy items and better handle invalid materials

  • Loading branch information...
PseudoKnight committed Aug 11, 2018
1 parent 20cdb23 commit cd75e1a89fd4b136eee3401eafc64156b2319d7b
@@ -237,7 +237,7 @@ public MCMaterial GetMaterial(String name) {
public MCItemStack GetItemStack(int id, int qty) {
Material mat = BukkitMCLegacyMaterial.getMaterial(id);
if(mat == null) {
return new BukkitMCItemStack(new ItemStack(Material.AIR));
return null;
}
return new BukkitMCItemStack(new ItemStack(mat, qty));
}
@@ -246,7 +246,7 @@ public MCItemStack GetItemStack(int id, int qty) {
public MCItemStack GetItemStack(int id, int data, int qty) {
Material mat = BukkitMCLegacyMaterial.getMaterial(id, data);
if(mat == null) {
return new BukkitMCItemStack(new ItemStack(Material.AIR));
return null;
}
return new BukkitMCItemStack(new ItemStack(mat, qty, (short) data));
}
@@ -266,9 +266,9 @@ public MCItemStack GetItemStack(String type, int qty) {
Material mat = Material.getMaterial(type);
if(mat == null) {
mat = Material.getMaterial(type, true);
if(mat == null) {
return new BukkitMCItemStack(new ItemStack(Material.AIR));
}
}
if(mat == null) {
return null;
}
return new BukkitMCItemStack(new ItemStack(mat, qty));
}
@@ -285,6 +285,9 @@ public MCItemStack GetItemStack(String type, int data, int qty) {
mat = converted;
}
}
if(mat == null) {
return null;
}
return new BukkitMCItemStack(new ItemStack(mat, qty, (short) data));
}
@@ -273,22 +273,15 @@ public MCItemStack item(Construct i, Target t, boolean legacy) {
if(legacy || item.containsKey("type")) {
// Do legacy item conversion
MCMaterial material;
if(item.containsKey("name")) {
mat = item.get("name", t).val();
MCMaterial material;
if(mat.equals("MAP")) {
// special handling, ignore data until later
material = StaticLayer.GetConvertor().GetMaterialFromLegacy(mat, 0);
} else {
material = StaticLayer.GetConvertor().GetMaterialFromLegacy(mat, data);
}
if(material == null) {
throw new CREFormatException("Could not convert legacy item from " + mat + ":" + data, t);
}
ret = StaticLayer.GetItemStack(material, qty);
CHLog.GetLogger().w(CHLog.Tags.DEPRECATION, "Converted \"" + mat + ":" + data + "\"" + " to "
+ ret.getType().getName(), t);
} else {
Construct type = item.get("type", t);
if(type instanceof CString) {
@@ -303,16 +296,21 @@ public MCItemStack item(Construct i, Target t, boolean legacy) {
type = new CString(type.val().substring(0, seperatorIndex), t);
}
}
mat = type.val();
int id = Static.getInt32(type, t);
if(id == 358) {
// special map handling, ignore data until later
ret = StaticLayer.GetItemStack(id, 0, qty);
material = StaticLayer.GetConvertor().GetMaterialFromLegacy(id, 0);
} else {
ret = StaticLayer.GetItemStack(id, data, qty);
material = StaticLayer.GetConvertor().GetMaterialFromLegacy(id, data);
}
CHLog.GetLogger().w(CHLog.Tags.DEPRECATION, "Converted \"" + type.val() + ":" + data + "\"" + " to "
+ ret.getType().getName(), t);
}
if(material == null) {
throw new CREFormatException("Could not convert legacy item from " + mat + ":" + data, t);
}
ret = StaticLayer.GetItemStack(material, data, qty);
CHLog.GetLogger().w(CHLog.Tags.DEPRECATION, "Converted \"" + mat + ":" + data + "\"" + " to "
+ material.getName(), t);
} else if(item.containsKey("name")) {
mat = item.get("name", t).val();
@@ -633,6 +633,9 @@ public static MCItemStack ParseItemNotation(String functionName, String notation
throw new CREFormatException("Invalid item notation: " + notation, t);
}
MCItemStack is = StaticLayer.GetItemStack(type, data, qty);
if(is == null) {
throw new CREFormatException("Invalid item values: " + notation, t);
}
CHLog.GetLogger().w(CHLog.Tags.DEPRECATION, "Item notation is deprecated."
+ " Converting '" + notation + "' to '" + is.getType().getName() + "'.", t);
return is;

0 comments on commit cd75e1a

Please sign in to comment.