BannerSerialization.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:NexusInventory 作者:
/**
 * A method to deserialize a BannerMeta object from a JSONObject. This method assumes that the JSONArrays containing
 * the colors and pattern types are the same length.
 *
 * @param json The JSONObject of the BannerMeta to deserialize
 * @return The BannerMeta or null if an exception occurs
 */
public static BannerMeta getBannerMeta(JSONObject json) {
    try {
        BannerMeta dummy = (BannerMeta) new ItemStack(Material.BANNER).getItemMeta();
        if (json.has("base-color"))
            dummy.setBaseColor(DyeColor.getByDyeData(Byte.parseByte("" + json.get("base-color"))));

        JSONArray colors = json.getJSONArray("colors");
        JSONArray patternTypes = json.getJSONArray("pattern-types");
        for (int i = 0; i < colors.length(); i++) {
            dummy.addPattern(new Pattern(DyeColor.getByDyeData(Integer.valueOf((int) colors.get(i)).byteValue()),
                    PatternType.getByIdentifier(patternTypes.getString(i))));
        }

        return dummy;
    } catch (JSONException ex) {
        ex.printStackTrace();
        return null;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号