/**
* A method to serialize banner meta to a JSONObject. Saves the base color, each pattern color, and each
* pattern type.
*
* @param banner The BannerMeta to serialize
* @return The JSONObject representation of the BannerMeta, or null if an exception occurred
*/
public static JSONObject serializeBanner(BannerMeta banner) {
try {
JSONObject root = new JSONObject();
if (banner.getBaseColor() != null)
root.put("base-color", banner.getBaseColor().getDyeData());
JSONArray colors = new JSONArray();
JSONArray patternTypes = new JSONArray();
for (Pattern pattern : banner.getPatterns()) {
colors.put(pattern.getColor().getDyeData());
patternTypes.put(pattern.getPattern().getIdentifier());
}
root.put("colors", colors);
root.put("pattern-types", patternTypes);
return root;
} catch (JSONException ex) {
ex.printStackTrace();
return null;
}
}
BannerSerialization.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:NexusInventory
作者:
评论列表
文章目录