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


Java EnchantItemEvent.getExpLevelCost方法代码示例

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


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

示例1: onEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void onEnchant(EnchantItemEvent event) {
	for (Entry<Integer, Enchant> entry : enchantmentMap.entrySet()) {
		Enchant ench = entry.getValue();
		if (ench.getTarget().isTypeCompatible(event.getItem())) {
			int chance = new Random().nextInt(ench.getChance());
			if (chance == 0) {
				int level = event.getExpLevelCost() / ench.getCostPerLevel();
				level = level <= ench.getMaxLevel() ? level : ench.getMaxLevel();
				event.getEnchantsToAdd().put(Enchantment.getById(entry.getKey()), level);
				ItemMeta meta = event.getItem().getItemMeta();
				List<String> lore = meta.getLore() != null ? meta.getLore() : new ArrayList<String>();
				lore.add(ChatColor.GRAY + ench.getName() + " " + numeral(level));
				meta.setLore(lore);
				event.getItem().setItemMeta(meta);
			}
		}
	}
}
 
开发者ID:mcardy,项目名称:Zephyrus-II,代码行数:21,代码来源:CoreEnchantManager.java

示例2: onEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchant(final EnchantItemEvent event) {
    final ItemStack item = getItem(event.getItem(), event.getEnchanter());
    final long seed = enchantSeeds.get(event.getEnchanter().getUniqueId());
    final EnchantResult result = mechanics.generateEnchantments(
            event.getEnchanter(), item, event.getExpLevelCost(), true, seed);

    placeholders.remove(event.getEnchanter().getUniqueId());
    event.getEnchantsToAdd().clear();
    result.getEnchantments().forEach((enchant, level) -> enchant.addToItem(item, level));
    GlowEffects.finalize(item);
    enchantSeeds.put(event.getEnchanter().getUniqueId(), random.nextLong());
    event.getInventory().setItem(0, item);
    event.setCancelled(true);

    if (event.getEnchanter().getGameMode() != GameMode.CREATIVE) {
        int cost = 0;
        final int[] tiers = offers.get(event.getEnchanter().getUniqueId());
        for (int i = 0; i < 6; i += 2) {
            if (tiers[i] == event.getExpLevelCost()) cost = tiers[i + 1];
        }
        event.getEnchanter().setLevel(event.getEnchanter().getLevel() - cost);
        event.getInventory().removeItem(new ItemStack(Material.INK_SACK, cost, (short) 4));
    }
}
 
开发者ID:Eniripsa96,项目名称:EnchantmentAPI,代码行数:26,代码来源:EnchantListener.java

示例3: onEnchantItem

import org.bukkit.event.enchantment.EnchantItemEvent; //导入方法依赖的package包/类
@EventHandler
public void onEnchantItem(EnchantItemEvent event) {
	if (event.getItem().getType().equals(Material.BOW)) {			
		if (event.getExpLevelCost() > 10) {
			if (ran.nextInt(8) == 0) {
				if (event.getExpLevelCost() < 18) {
					level = 1;
				} else if (event.getExpLevelCost() < 25){
					level = 2;
				} else {
					level = 3;
				}
				event.getItem().addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, level);
			}
		}
	}
}
 
开发者ID:SugarCaney,项目名称:DirtyArrows,代码行数:18,代码来源:EnchantmentListener.java

示例4: onPlayerEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerEnchant(EnchantItemEvent event)
{
	int cost = event.getExpLevelCost();
	if (cost < 15)
		return;

	Player player = event.getEnchanter();
	if (player == null || plugin.isDisabledWorld(player))
		return;

	int xp = xpGain + (cost / 2);

	String message = plugin.getPrefix() + FormatUtil.format(plugin.getMessage("enchant_gain"), xp);
	plugin.getExperienceHandler().handleXpGain(player, xp, message);
}
 
开发者ID:dmulloy2,项目名称:SwornRPG,代码行数:17,代码来源:Enchanting.java

示例5: onEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入方法依赖的package包/类
@EventHandler
public void onEnchant(EnchantItemEvent e) {
	int level = e.getExpLevelCost() / enchantLevelCost();
	int chance = new Random().nextInt(chance() * Zephyrus.getConfig().getInt("Enchantment-Chance"));
	if (chance == 0 && level != 0) {
		if (e.getItem().getType() != Material.BOOK && !incompatible(e.getEnchantsToAdd())
				&& canEnchantItem(e.getItem())) {
			if (level > this.getMaxLevel()) {
				level = this.getMaxLevel();
			}
			Random rand = new Random();
			if (rand.nextInt(2) == 0 && level > 1) {
				level = level - 1;
			}
			e.getEnchantsToAdd().put(this, level);
			ItemMeta m = e.getItem().getItemMeta();
			List<String> lore;
			if (m.hasLore()) {
				lore = m.getLore();
			} else {
				lore = new ArrayList<String>();
			}
			lore.add(ChatColor.GRAY + this.getName() + " " + numeral(level));
			m.setLore(lore);
			e.getItem().setItemMeta(m);
		}
	}
}
 
开发者ID:mcardy,项目名称:Zephyrus,代码行数:29,代码来源:CustomEnchantment.java

示例6: EnchantItemEvent

import org.bukkit.event.enchantment.EnchantItemEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EnchantItemEvent(EnchantItemEvent e) {
    if (e.getExpLevelCost() == 30)
        if (Tools.random.nextInt(100) < (Float.parseFloat(Main.config.getString("Global.Enchantments.CEnchantingProbability"))))
            CEventHandler.handleEnchanting(e);
}
 
开发者ID:Taiterio,项目名称:ce,代码行数:7,代码来源:CEListener.java


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