Java 类org.bukkit.event.enchantment.EnchantItemEvent 实例源码

项目:HCFCore    文件:EnchantLimitListener.java   
@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();
            }
        }
    }
}
项目:HCFCore    文件:EnchantLimitListener.java   
@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();
            }
        }
    }
}
项目:CanaryBukkit    文件:CanaryPlayerListener.java   
@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.
}
项目:Zephyrus-II    文件:CoreEnchantManager.java   
@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);
            }
        }
    }
}
项目:TheSurvivalGames    文件:EnchantmentListener.java   
@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);
            }
        }
    }

}
项目:EnchantmentAPI    文件:EnchantListener.java   
@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));
    }
}
项目:PV-Star    文件:ArenaEventForwarder.java   
@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);
        }
    }
}
项目:TNE-Bukkit    文件:RewardsListener.java   
@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);
    }
  }
}
项目:DirtyArrows    文件:EnchantmentListener.java   
@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);
            }
        }
    }
}
项目:SwornRPG    文件:Enchanting.java   
@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);
}
项目:EpicQuest    文件:TypeEnchant.java   
@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);
        }
    }
}
项目:BukkitOldCombatMechanics    文件:ModuleNoLapisEnchantments.java   
@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());
}
项目:OmniWorldMCPlugin    文件:EnchantItemListener.java   
@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);
    }
}
项目:AdvancedAchievements    文件:AchieveEnchantListener.java   
@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);
}
项目:modules-extra    文件:ListenerItem.java   
@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());
    }
}
项目:BetonQuest    文件:EnchantObjective.java   
@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;
                }
}
项目:ce    文件:Main.java   
public void initializeListener() {
    if (listener != null)
        HandlerList.unregisterAll(listener);

    listener = new CEListener();

    // Register the events
    getServer().getPluginManager().registerEvents(listener, this);

    // Unregister unused events

    // EnchantItemEvent may be used
    if (!getConfig().getBoolean("Global.Enchantments.CEnchantmentTable"))
        EnchantItemEvent.getHandlerList().unregister(listener);
}
项目:GoogleAnalyticsPlugin    文件:GoogleAnalyticsEventListener.java   
@EventHandler(priority = EventPriority.MONITOR)
public void onEnchantItem(EnchantItemEvent event){
    if(enableEventEnchantItem) {
        try {
            Player player = event.getEnchanter();

            if(!player.hasPermission("googleanalyticsplugin.ignore")) {
                plugin.getTracker().TrackAction(getClientName(plugin, player), getClientId(player), getClientIP(player.getAddress().getAddress()), player.getName(), "Enchant Item", getItemSummary(event));
            }
        }
        catch(Exception e) {
            plugin.getLogger().warning("Event Listener Error: " + e.getMessage());
        }
    }
}
项目:GoogleAnalyticsPlugin    文件:GoogleAnalyticsEventListener.java   
private static String getItemSummary(EnchantItemEvent event) {
    String itemSummary = event.getItem().getType().name() + " with";

    for(Enchantment enchantment : event.getEnchantsToAdd().keySet()) {
        itemSummary += " " + enchantment.getName() + " [" + event.getEnchantsToAdd().get(enchantment) + "]";
    }

    return itemSummary;
}
项目:TerraCraftTools    文件:LimitEnchants.java   
@EventHandler
public void onEnchantItem(EnchantItemEvent event) {
    if (behaviorOfList) {
        Material item = event.getItem().getType();
        if (!allowed.contains(item)) {
            event.setCancelled(true);
            event.getEnchanter().sendMessage(ChatColor.DARK_RED + "You are not allowed to enchant non-tool items.");
        }
    } else {
        if (!canEnchant(event.getEnchanter())) {
            event.setCancelled(true);
            event.getEnchanter().sendMessage(ChatColor.DARK_RED + "You must vote for the server if you wish to enchant items.");
        }
    }
}
项目:Bits    文件:ConfigurationManager.java   
private static HashMap<String, Class> getEventClassAssociations()
    {
        HashMap<String, Class> classHashMap = new HashMap<String, Class>();
        classHashMap.put("block-break", BlockBreakEvent.class);
        classHashMap.put("block-place", BlockPlaceEvent.class);

//      classHashMap.put("entity-leash", PlayerLeashEntityEvent.class);
        classHashMap.put("entity-kill", EntityDeathEvent.class);
        classHashMap.put("entity-shear", PlayerShearEntityEvent.class);

        classHashMap.put("item-brew", BrewEvent.class);
        classHashMap.put("item-enchant", EnchantItemEvent.class);
        classHashMap.put("item-furnace", FurnaceExtractEvent.class);

        classHashMap.put("painting-create", HangingPlaceEvent.class);

        classHashMap.put("player-regenerate", EntityRegainHealthEvent.class);
        classHashMap.put("player-shoot", EntityShootBowEvent.class);
        classHashMap.put("player-chat", AsyncPlayerChatEvent.class);
        classHashMap.put("player-death", PlayerDeathEvent.class);
        classHashMap.put("player-sleep", PlayerBedEnterEvent.class);
        classHashMap.put("player-author", PlayerEditBookEvent.class);
        classHashMap.put("player-egg", PlayerEggThrowEvent.class);
        classHashMap.put("player-fish", PlayerFishEvent.class);
        classHashMap.put("player-eat", PlayerItemConsumeEvent.class);
        classHashMap.put("player-join", PlayerJoinEvent.class);
        classHashMap.put("player-move", PlayerMoveEvent.class);

        classHashMap.put("portal-create", PortalCreateEvent.class);

        classHashMap.put("vehicle-move", VehicleMoveEvent.class);

        classHashMap.put("world-change", PlayerChangedWorldEvent.class);

        return classHashMap;
    }
项目:Zephyrus    文件:CustomEnchantment.java   
@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);
        }
    }
}
项目:OpenUHC    文件:InfiniteEnchanter.java   
@EventHandler(ignoreCancelled = true)
public void onEnchantItem(EnchantItemEvent event) {
  Bukkit.getScheduler().runTask(OpenUHC.getInstance(), () -> event.getEnchanter().setLevel(30));
}
项目:SurvivalAPI    文件:AutomaticLapisModule.java   
/**
 * Fill the lapis lazuli slot
 *
 * @param event Event
 */
@EventHandler
public void enchantItemEvent(EnchantItemEvent event)
{
    event.getInventory().setItem(1, new ItemStack(Material.INK_SACK, 64, (short) 4));
}
项目:DoubleRunner    文件:DoubleRunnerGameLoop.java   
@EventHandler
public void onEnchantItem(EnchantItemEvent event)
{
    if (event.getItem().getType() == Material.LEATHER_BOOTS || event.getItem().getType() == Material.IRON_BOOTS || event.getItem().getType() == Material.CHAINMAIL_BOOTS || event.getItem().getType() == Material.GOLD_BOOTS || event.getItem().getType() == Material.DIAMOND_BOOTS)
        event.getItem().addEnchantment(Enchantment.DEPTH_STRIDER, 2);
}
项目:AbilityAPI    文件:SequenceListener.java   
@EventHandler
public void onEnchantItem(EnchantItemEvent event) {
    this.manager.invoke(event.getEnchanter(), event);
}
项目:ExilePearl    文件:ExileListener.java   
/**
 * Prevent exiled players from enchanting
 * @param e The event
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerEnchant(EnchantItemEvent e) {
    checkAndCancelRule(ExileRule.ENCHANT, e, e.getEnchanter());
}
项目:RpgPlus    文件:ScriptEventManager.java   
@EventHandler
public void onPlayerEnchant(EnchantItemEvent event) {
    callHandlers("player.enchant", event);
}
项目:civcraft    文件:CustomItemManager.java   
@EventHandler(priority = EventPriority.NORMAL)
public void onEnchantItemEvent(EnchantItemEvent event) {
    CivMessage.sendError(event.getEnchanter(), "Items cannot be enchanted with enchantment tables.");
    event.setCancelled(true);
}
项目:ce    文件:CEListener.java   
@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);
}
项目:Wayward    文件:EnchantItemListener.java   
@EventHandler
public void onEnchantItem(EnchantItemEvent event) {
    event.setCancelled(true);
}
项目:Demigods3    文件:FlagListener.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onEnchantEvent(EnchantItemEvent event) {
    if (Demigods.getMythos().itemHasFlag(event.getItem(), DivineItem.Flag.UNENCHANTABLE)) event.setCancelled(true);
}
项目:Breakpoint    文件:BanListener.java   
@EventHandler public void e(EnchantItemEvent event) { event.setCancelled(true); }
项目:Breakpoint    文件:BanListener.java   
@EventHandler public void e(EnchantItemEvent event) { event.setCancelled(true); }