LegacyStringToItemParser: rely exclusively on item_from_string_bc_map.json, do not interpret integers given as strings

fixes #4507
This commit is contained in:
Dylan K. Taylor
2021-10-13 20:29:18 +01:00
parent 6284cd14c7
commit b570324288
2 changed files with 690 additions and 5 deletions

View File

@@ -63,8 +63,8 @@ final class LegacyStringToItemParser{
if(!is_array($mappings)) throw new AssumptionFailedError("Invalid mappings format, expected array");
foreach($mappings as $name => $id){
if(!is_string($name) or !is_int($id)) throw new AssumptionFailedError("Invalid mappings format, expected string keys and int values");
$result->addMapping($name, $id);
if(!is_int($id)) throw new AssumptionFailedError("Invalid mappings format, expected int values");
$result->addMapping((string) $name, $id);
}
return $result;
@@ -114,9 +114,7 @@ final class LegacyStringToItemParser{
throw new LegacyStringToItemParserException("Unable to parse \"" . $b[1] . "\" from \"" . $input . "\" as a valid meta value");
}
if(is_numeric($b[0])){
$item = $this->itemFactory->get((int) $b[0], $meta);
}elseif(isset($this->map[strtolower($b[0])])){
if(isset($this->map[strtolower($b[0])])){
$item = $this->itemFactory->get($this->map[strtolower($b[0])], $meta);
}else{
throw new LegacyStringToItemParserException("Unable to resolve \"" . $input . "\" to a valid item");