How I can get ItemType object by its name?
ItemType & ItemTypes class does not contains methods like “getByName(String)”…
String text_item_type = node.getNode("TYPE").getString();
ItemType type = ???;
How I can get ItemType object by its name?
ItemType & ItemTypes class does not contains methods like “getByName(String)”…
String text_item_type = node.getNode("TYPE").getString();
ItemType type = ???;
Use Sponge.getGameRegistry().getType(ItemType.class, itemTypeString), it will return an Optional.
It is Sponge.getRegistry() ;).
Or, for bonus ducks,
ItemType type = node.getNode("TYPE").getValue(TypeToken.of(ItemType.class));
Why am I not thought of this myself … 
But I think, first variant will be better for me, becasuse it allows to check, is ItemType correct!
if (!node.getNode("TYPE").isVirtual()) {
throw new ObjectMappingException("Item type does not specified!");
}
String text_item_type = node.getNode("TYPE").getString();
Optional<ItemType> optional_type = Sponge.getRegistry().getType(ItemType.class, text_item_type);
if (!optional_type.isPresent()) {
throw new ObjectMappingException("ItemType \"" + text_item_type + "\" does not exist!");
}
ItemType type = optional_type.get();
No, this allows you to do that as well. If it throws an ObjectMappingException, then it’s an invalid item. In fact the code you posted is nearly identical to the functionality of the code I posted, just with different error messages.