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


Java EnchantItemEvent类代码示例

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


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

示例1: onEnchantItem

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onEnchantItem(EnchantItemEvent event) {
    Map<Enchantment, Integer> adding = event.getEnchantsToAdd();
    Iterator<Map.Entry<Enchantment, Integer>> iterator = adding.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<Enchantment, Integer> entry = iterator.next();
        Enchantment enchantment = entry.getKey();
        int maxLevel = getMaxLevel(enchantment);
        if (entry.getValue() > maxLevel) {
            if (maxLevel > 0) {
                adding.put(enchantment, maxLevel);
            } else {
                iterator.remove();
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:18,代码来源:EnchantLimitListener.java

示例2: onEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@HookHandler(priority = Priority.CRITICAL, ignoreCanceled = true)
public void onEnchant(final EnchantHook hook) {
    EnchantItemEvent event = new EnchantItemEvent(new CanaryPlayer(hook.getPlayer()), null, new CanaryBlock(hook
            .getEnchantmentTable().getBlock()), null, 0, null, 0) {
        @Override
        public void setExpLevelCost(int level) {
            super.setExpLevelCost(level);
            // How can you do this in Canary?
        }
    };
    event.setCancelled(hook.isCanceled());
    server.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        hook.setCanceled();
    }
    // TODO: Fill in.
}
 
开发者ID:CanaryBukkitTeam,项目名称:CanaryBukkit,代码行数:18,代码来源:CanaryPlayerListener.java

示例3: 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

示例4: EnchantItem

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void EnchantItem(EnchantItemEvent e) {
    if (e.getItem().getType() == Material.GOLD_SWORD || e.getItem().getType() == Material.WOOD_SWORD || e.getItem().getType() == Material.STONE_SWORD
            || e.getItem().getType() == Material.DIAMOND_SWORD) {
        e.getEnchantsToAdd().clear();
        Random r = new Random();
        if (r.nextInt(1) == 0) {
            e.getEnchantsToAdd().put(Enchantment.DAMAGE_ALL, 1);
        } else {
            int rnd = r.nextInt(3);
            if (rnd == 0 || rnd == 3) {
                e.getEnchantsToAdd().put(Enchantment.DAMAGE_ALL, 2);
            }

            if (rnd == 1) {
                e.getEnchantsToAdd().put(Enchantment.KNOCKBACK, 1);
            }

            if (rnd == 2) {
                e.getEnchantsToAdd().put(Enchantment.getByName("Shocking"), 1);
            }
        }
    }

}
 
开发者ID:SurvivalGamesDevTeam,项目名称:TheSurvivalGames,代码行数:26,代码来源:EnchantmentListener.java

示例5: 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

示例6: onInventoryEvent

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@Override
protected void onInventoryEvent(InventoryEvent event) {
    if (event instanceof EnchantItemEvent) {
        callEvent(((EnchantItemEvent) event).getEnchanter(), event);
    }
    else if (event instanceof PrepareItemEnchantEvent) {

        callEvent(((PrepareItemEnchantEvent) event).getEnchanter(), event);
    }
    else {
        InventoryHolder holder = event.getInventory().getHolder();

        if (holder instanceof Player) {
            callEvent((Player)holder, event);
        }
    }
}
 
开发者ID:JCThePants,项目名称:PV-Star,代码行数:18,代码来源:ArenaEventForwarder.java

示例7: onEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler
public void onEnchant(final EnchantItemEvent event) {
  if (TNE.instance().api().getBoolean("Materials.Enabled", WorldFinder.getWorld(event.getEnchanter(), WorldVariant.CONFIGURATION), IDFinder.getID(event.getEnchanter()))) {
    if (event.getItem() != null && !event.getItem().getType().equals(Material.AIR)) {

      ItemStack result = event.getItem();
      String name = result.getType().name();
      BigDecimal cost = InteractionType.ENCHANT.getCost(name, WorldFinder.getWorld(event.getEnchanter(), WorldVariant.CONFIGURATION), IDFinder.getID(event.getEnchanter()).toString());

      List<String> lore = new ArrayList<>();
      lore.add(ChatColor.WHITE + "Enchanting Cost: " + ChatColor.GOLD + cost);

      ItemMeta meta = result.getItemMeta();
      meta.setLore(lore);

      for (Enchantment e : event.getEnchantsToAdd().keySet()) {
        meta.addEnchant(e, event.getEnchantsToAdd().get(e), false);
      }

      result.setItemMeta(meta);
      event.getInventory().setItem(0, result);
    }
  }
}
 
开发者ID:TheNewEconomy,项目名称:TNE-Bukkit,代码行数:25,代码来源:RewardsListener.java

示例8: 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

示例9: 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

示例10: onItemEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler
public void onItemEnchant(EnchantItemEvent event){
	
	//Get player and questlist
	Player player = (Player)event.getInventory().getHolder();
	EpicPlayer epicPlayer = EpicSystem.getEpicPlayer(player.getUniqueId());
	List<EpicQuestTask> taskList = epicPlayer.getTasksByType(TaskTypes.ENCHANT_ITEM);
	
	for(EpicQuestTask task : taskList){
		Material itemID = event.getItem().getType();
		String itemNeeded = task.getTaskID();
		
		if(itemID == Material.matchMaterial(itemNeeded)){
			task.ProgressTask(1, epicPlayer, true);
		}
	}
}
 
开发者ID:Randehh,项目名称:EpicQuest,代码行数:18,代码来源:TypeEnchant.java

示例11: onEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler
public void onEnchant(EnchantItemEvent e) {
	Block block = e.getEnchantBlock();
	if(!isEnabled(block.getWorld())) return;

	if(!hasPermission(e.getEnchanter())) return;

	EnchantingInventory ei = (EnchantingInventory) e.getInventory(); //Not checking here because how else would event be fired?
	ei.setSecondary(getLapis());
}
 
开发者ID:gvlfm78,项目名称:BukkitOldCombatMechanics,代码行数:11,代码来源:ModuleNoLapisEnchantments.java

示例12: canEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler(priority= EventPriority.LOW, ignoreCancelled=true)
public void canEnchant(EnchantItemEvent event)
{
    ItemStack item = event.getItem();
    if (!PowerUtils.isPowerTool(item)) {
        return;
    }
    if (!PowerUtils.checkEnchantPermission(event.getEnchanter(), item.getType())) {
        event.setCancelled(true);
    }
}
 
开发者ID:OmniWorldMC,项目名称:OmniWorldMCPlugin,代码行数:12,代码来源:EnchantItemListener.java

示例13: onEnchantItem

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchantItem(EnchantItemEvent event) {
	Player player = event.getEnchanter();
	NormalAchievements category = NormalAchievements.ENCHANTMENTS;
	if (!shouldIncreaseBeTakenIntoAccount(player, category)) {
		return;
	}

	updateStatisticAndAwardAchievementsIfAvailable(player, category, 1);
}
 
开发者ID:PyvesB,项目名称:AdvancedAchievements,代码行数:11,代码来源:AchieveEnchantListener.java

示例14: onEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchant(EnchantItemEvent event)
{
    ItemEnchant action = this.newAction(ItemEnchant.class, event.getEnchanter().getWorld());
    if (action != null)
    {
        this.setPlayerAndLocation(event.getEnchanter(), action);
        if (event.getEnchantBlock() != null)
        {
            action.setLocation(event.getEnchantBlock().getLocation());
        }
        action.setItemstack(event.getItem());
        action.setEnchants(event.getEnchantsToAdd());
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:16,代码来源:ListenerItem.java

示例15: onEnchant

import org.bukkit.event.enchantment.EnchantItemEvent; //导入依赖的package包/类
@EventHandler
public void onEnchant(EnchantItemEvent event) {
	String playerID = PlayerConverter.getID(event.getEnchanter());
	if (!containsPlayer(playerID))
		return;
	if (!item.compare(event.getItem()))
		return;
	for (Enchantment enchant : event.getEnchantsToAdd().keySet())
		if (enchant == this.enchant)
			if (event.getEnchantsToAdd().get(enchant) >= level)
				if (checkConditions(playerID)) {
					completeObjective(playerID);
					return;
				}
}
 
开发者ID:Co0sh,项目名称:BetonQuest,代码行数:16,代码来源:EnchantObjective.java


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