CustomItem.java 文件源码

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

项目:uppercore 作者:
public CustomItem(Material type, Config config, PlaceholderRegistry placeholders) {
    this.type = type;
    this.placeholders = placeholders;
    data = PlaceholderValue.shortValue(config.getString("data", "0"));//TODO: better api
    amount = PlaceholderUtil.parseInt(config.getString("amount", "1"));

    String rawName = config.getString("name");
    displayName = rawName == null ? null : PlaceholderValue.stringValue(ChatColor.RESET.toString() + rawName);
    if (config.has("lore")) {
        lore = ((Collection<String>) config.getCollection("lore"))
                .stream()
                .map(message -> PlaceholderUtil.process(ChatColor.RESET.toString() + message))
                .collect(Collectors.toList());
    } else lore = Collections.emptyList();
    if (config.has("flags")) {
        flags = ((Collection<String>) config.getCollection("flags"))
                .stream()
                .map(s -> s.replace(' ', '_').toUpperCase(Locale.ENGLISH))
                .map(ItemFlag::valueOf)
                .collect(Collectors.toList());
    } else
        flags = Collections.emptyList();

    if (config.has("enchantments")) {
        Map<String, Object> stEnch = config.getMap("enchantments");
        for(Map.Entry<String, Object> e : stEnch.entrySet()) {
            Enchantment ench = Enchantment.getByName(e.getKey().replace(' ', '_').toUpperCase(Locale.ENGLISH));
            if (ench == null)
                throw new InvalidConfigException("Cannot find enchantment: " + e.getKey());
            else
                enchantments.put(ench, PlaceholderValue.intValue(e.getValue().toString()));
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号