本文整理汇总了Java中org.bukkit.configuration.serialization.DelegateDeserialization类的典型用法代码示例。如果您正苦于以下问题:Java DelegateDeserialization类的具体用法?Java DelegateDeserialization怎么用?Java DelegateDeserialization使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DelegateDeserialization类属于org.bukkit.configuration.serialization包,在下文中一共展示了DelegateDeserialization类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unmarshalElement
import org.bukkit.configuration.serialization.DelegateDeserialization; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static void unmarshalElement(Element baseElement, Map<String, Object> map) {
List<Element> childElements = baseElement.elements();
for (Element childElement : childElements) {
String name = childElement.getName();
Attribute itemMetaAttribute = childElement.attribute("itemmeta");
Object value;
if (itemMetaAttribute != null && Boolean.valueOf(itemMetaAttribute.getValue()).booleanValue()) {
Map<String, Object> metaMap = Maps.newHashMap();
unmarshalElement(childElement, metaMap);
Material material = Material.valueOf((String) map.get("type"));
ItemMeta metaDummy = Bukkit.getItemFactory().getItemMeta(material);
Class<?> deserializationClass = metaDummy.getClass();
do {
if (!deserializationClass.isAnnotationPresent(DelegateDeserialization.class)) {
break;
}
DelegateDeserialization annotation = deserializationClass.getAnnotation(DelegateDeserialization.class);
deserializationClass = annotation.value();
} while (true);
ItemMeta meta;
try {
Method method = deserializationClass.getMethod("deserialize", Map.class);
meta = (ItemMeta) method.invoke(null, metaMap);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new IllegalStateException("Cannot deserialize item meta", e);
}
value = meta;
} else {
value = deserializeObject(childElement);
}
map.put(name, value);
}
}