当前位置: 首页>>代码示例>>Java>>正文


Java Enchantment.getByName方法代码示例

本文整理汇总了Java中org.bukkit.enchantments.Enchantment.getByName方法的典型用法代码示例。如果您正苦于以下问题:Java Enchantment.getByName方法的具体用法?Java Enchantment.getByName怎么用?Java Enchantment.getByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.enchantments.Enchantment的用法示例。


在下文中一共展示了Enchantment.getByName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialize

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
/**
 * Deserialize items.
 */
public static ItemStack deserialize(ConfigurationSection section) {
    Material type = Material.getMaterial(section.getString("type"));
    byte data = (byte) section.getInt("data");

    ItemBuilder item = new ItemBuilder(type, data);

    item.setAmount(section.getInt("amount"));
    item.setDurability((short) section.getInt("durability"));

    item.setDisplayName(section.getString("displayName"));
    item.setLore(section.getString("lore"));

    List<String> enchants = section.getStringList("enchantments");
    for (String enchant : enchants) {
        String tmp[] = enchant.split(",");

        Enchantment enc = Enchantment.getByName(tmp[0]);
        int lev = Integer.parseInt(tmp[1]);

        item.addEnchantment(enc, lev);
    }

    return item.build();
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:28,代码来源:ItemBuilder.java

示例2: EnchantedBookCustomItem

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
public EnchantedBookCustomItem(Material material, Config config, PlaceholderRegistry placeholders) {
    super(material, config, placeholders);
    storedEnchantments = new HashMap<>();

    if (config.has("stored-enchantments")) {
        Map<String, Object> stEnch = config.getMap("stored-enchantments");

        for(Map.Entry<String, Object> e : stEnch.entrySet()) {
            Enchantment ench = Enchantment.getByName(e.getKey().replace(' ', '_').toUpperCase(Locale.ENGLISH));
            if (ench == null)
                Uppercore.logger().severe("Cannot find enchantment: " + e.getKey());
            else
                storedEnchantments.put(ench, PlaceholderValue.intValue(e.getValue().toString()));
        }
    }
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:17,代码来源:EnchantedBookCustomItem.java

示例3: buildEnchantments

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
static Map<Enchantment, Integer> buildEnchantments(Map<String, Object> map, ItemMetaKey key) {
    Map<?, ?> ench = SerializableMeta.getObject(Map.class, map, key.BUKKIT, true);
    if (ench == null) {
        return null;
    }

    Map<Enchantment, Integer> enchantments = new HashMap<Enchantment, Integer>(ench.size());
    for (Map.Entry<?, ?> entry : ench.entrySet()) {
        Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());

        if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
            enchantments.put(enchantment, (Integer) entry.getValue());
        }
    }

    return enchantments;
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:18,代码来源:CraftMetaItem.java

示例4: CustomItem

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
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()));
        }
    }
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:35,代码来源:CustomItem.java

示例5: addSuffix

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
private static String addSuffix(String enchName) {
    if (Enchantment.getByName(enchName) == null) {
        return enchName;
    }

    int suffix = 2;
    while (Enchantment.getByName(enchName + "_" + suffix) != null) {
        suffix++;
    }
    return enchName + "_" + suffix;
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:12,代码来源:CraftEnchantment.java

示例6: getEnchantment

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
private Enchantment getEnchantment(String enchantment){
    try{
        return Enchantment.getByName(enchantment);
    }catch (NullPointerException e){
        plugin.log(WCServer.Level.WARNING, "El encantamiento no existe");
    }
    return null;
}
 
开发者ID:cadox8,项目名称:WC,代码行数:9,代码来源:EnchantCMD.java

示例7: parseEnchantment

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
public static Enchantment parseEnchantment(Node node, String text) throws InvalidXMLException {
    Enchantment enchantment = Enchantment.getByName(text.toUpperCase().replace(" ", "_"));
    if(enchantment == null) enchantment = NMSHacks.getEnchantment(text);

    if(enchantment == null) {
        throw new InvalidXMLException("Unknown enchantment '" + text + "'", node);
    }

    return enchantment;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:11,代码来源:XMLUtils.java

示例8: getEnchantment

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
private Enchantment getEnchantment(String enchantment) {
    try {
        return Enchantment.getByName(enchantment);
    } catch (NullPointerException e) {
        Log.log(Log.Level.WARNING, "El encantamiento no existe");
        return Enchantment.ARROW_INFINITE;
    }
}
 
开发者ID:cadox8,项目名称:PA,代码行数:9,代码来源:EnchantCMD.java

示例9: itemConfigToEnchantment

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
public static Enchantment itemConfigToEnchantment(String enchantment){
    String realname = enchantment.split(":")[0];
    return Enchantment.getByName(realname);
}
 
开发者ID:SkyLightQP,项目名称:ItemUtility,代码行数:5,代码来源:ItemHelper.java

示例10: encode

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
@Override
public String encode(ItemStack itemStack) {
    StringBuilder stringBuilder = new StringBuilder();

    if (itemStack.getDurability() != 0) {
        stringBuilder.append(itemStack.getType().toString()).append(",").append(itemStack.getDurability()).append(" ");
    } else {
        stringBuilder.append(itemStack.getType().toString());
    }

    stringBuilder.append(itemStack.getAmount()).append(" ");

    if (itemStack.hasItemMeta()) {
        if (itemStack.getItemMeta().hasDisplayName()) {
            stringBuilder.append("name,").append(itemStack.getItemMeta().getDisplayName().replace(Character.toString(ChatColor.COLOR_CHAR), "&").replace(" ", "")).append(" ");
        }

        if (itemStack.getItemMeta().hasLore()) {
            stringBuilder.append("lore,");
            boolean firstLine = true;

            for (String line : itemStack.getItemMeta().getLore()) {
                if (firstLine) {
                    firstLine = false;
                    stringBuilder.append(line.replace(Character.toString(ChatColor.COLOR_CHAR), "&").replace(" ", ""));
                    continue;
                }

                stringBuilder.append("/n").append(line.replace(Character.toString(ChatColor.COLOR_CHAR), "&").replace(" ", ""));
            }

            stringBuilder.append(" ");
        }
    }

    for (Enchantment enchantment : itemStack.getEnchantments().keySet()) {
        try {
            Enchantment.getByName(enchantment.getName());
        } catch (IllegalArgumentException e) {
            continue;
        }

        stringBuilder.append(Enchantment.getByName(enchantment.getName()).getName().replace(" ", "")).append(",").append(itemStack.getEnchantmentLevel(enchantment));
        stringBuilder.append(" ");
    }

    return stringBuilder.toString().trim();
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:49,代码来源:ItemStackSerializer.java

示例11: parseDragonLoot

import org.bukkit.enchantments.Enchantment; //导入方法依赖的package包/类
private void parseDragonLoot() {
	if (template.file == null) return; // No file to parse loot from
	
	Logger logger = JavaPlugin.getPlugin(DragonEggDrop.class).getLogger();
	FileConfiguration dragonFile = template.configFile;
	
	// Parse the basic loot rewards (i.e. spawn chances & names)
	this.eggSpawnChance = dragonFile.getDouble("egg-spawn-chance", 100.0);
	this.eggName = ChatColor.translateAlternateColorCodes('&', dragonFile.getString("egg-name", "%dragon%&r's Egg"));
	this.eggLore = dragonFile.getStringList("egg-lore").stream()
			.map(s -> ChatColor.translateAlternateColorCodes('&', s))
			.collect(Collectors.toList());
	
	this.chestSpawnChance = dragonFile.getDouble("chest-spawn-chance", 0);
	this.chestName = dragonFile.getString("chest-name", "Loot Chest");
	this.minLootGen = dragonFile.getInt("min-loot");
	this.maxLootGen = dragonFile.getInt("max-loot");
	
	this.commands = dragonFile.getStringList("death-commands");
	
	// Parse loot items
	ConfigurationSection lootSection = dragonFile.getConfigurationSection("loot");
	if (lootSection == null) return;
	
	for (String itemKey : lootSection.getKeys(false)) {
		// Parse root values (type, damage, amount and weight)
		double weight = lootSection.getDouble(itemKey + ".weight");
		
		Material type = EnumUtils.getEnum(Material.class, lootSection.getString(itemKey + ".type").toUpperCase());
		byte data = (byte) lootSection.getInt(itemKey + ".data");
		short damage = (short) lootSection.getInt(itemKey + ".damage");
		int amount = lootSection.getInt(itemKey + ".amount");
		
		if (type == null) {
			logger.warning("Invalid material type \"" + lootSection.getString(itemKey + ".type") + "\". Ignoring loot value...");
			continue;
		}
		
		// Create new item stack with passed values
		@SuppressWarnings("deprecation")
		ItemStack item = new ItemStack(type, 1, damage, data);
		item.setAmount(amount);
		
		// Parse meta
		String displayName = lootSection.getString(itemKey + ".display-name");
		List<String> lore = lootSection.getStringList(itemKey + ".lore");
		Map<Enchantment, Integer> enchantments = new HashMap<>();
		
		// Enchantment parsing
		if (lootSection.contains(itemKey + ".enchantments")) {
			for (String enchant : lootSection.getConfigurationSection(itemKey + ".enchantments").getKeys(false)) {
				Enchantment enchantment = Enchantment.getByName(enchant);
				int level = lootSection.getInt(itemKey + ".enchantments." + enchant);
				
				if (enchantment == null || level == 0) {
					logger.warning("Invalid enchantment \"" + enchant + "\" with level " + level);
					continue;
				}
				
				enchantments.put(enchantment, level);
			}
		}
		
		// Meta updating
		ItemMeta meta = item.getItemMeta();
		if (displayName != null) meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
		if (!lore.isEmpty()) meta.setLore(lore.stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList()));
		enchantments.forEach((e, level) -> meta.addEnchant(e, level, true));
		item.setItemMeta(meta);
		
		this.loot.add(weight, item);
	}
}
 
开发者ID:2008Choco,项目名称:DragonEggDrop,代码行数:74,代码来源:DragonLoot.java


注:本文中的org.bukkit.enchantments.Enchantment.getByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。