Java 类org.bukkit.inventory.AnvilInventory 实例源码

项目:AsgardAscension    文件:AbilityListener.java   
@EventHandler
public void onRepair(InventoryClickEvent event) {
    if(event.isCancelled() || !(event.getWhoClicked() instanceof Player) || !(event.getInventory() instanceof AnvilInventory))
        return;

    InventoryView view = event.getView();
    int rawSlot = event.getRawSlot();

    if(rawSlot != view.convertSlot(rawSlot) || rawSlot != 2)
        return;

    ItemStack item = event.getInventory().getItem(0);
    if(!plugin.getAbilityManager().hasAbility(item) || !plugin.getAbilityManager().isTemporaryItem(item))
        return;

    Ability ability = plugin.getAbilityManager().getAbility(item);
    event.getInventory().setItem(0, plugin.getAbilityManager().removeItemLore(item, ability));
    event.setCancelled(true);
}
项目:ChestKit    文件:ChestKitsListener.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e) {
    // Only looking for anvils
    if (!(e.getInventory() instanceof AnvilInventory)) {
        return;
    }

    ItemStack item = e.getCurrentItem();

    // Only looking for kits
    if (!item.hasItemMeta()) {
        return;
    }

    ItemMeta meta = item.getItemMeta();

    if (meta.hasDisplayName() && meta.hasLore() && meta.getDisplayName().startsWith("Kit ")) {
        if (meta.getLore().contains(ChestKitsPlugin.LORE_KEY)) {
            e.setCancelled(true);
        }
    }
}
项目:MythicDrops    文件:AnvilListener.java   
@EventHandler(priority = EventPriority.MONITOR)
public void onItemRename(InventoryClickEvent e) {
  if (e.isCancelled()) {
    return;
  }
  if (!mythicDrops.getConfigSettings().isRepairingEnabled()) {
    return;
  }
  HumanEntity ent = e.getWhoClicked();
  if (!(ent instanceof Player)) {
    return;
  }
  Inventory inv = e.getInventory();
  if (!(inv instanceof AnvilInventory)) {
    return;
  }
  ItemStack fis = inv.getItem(0);
  ItemStack sis = inv.getItem(1);

  if (mythicDrops.getConfigSettings().isAllowRepairingUsingAnvil()) {
    preventGems(fis, sis, e);
  } else {
    preventTiersAndGems(fis, sis, e);
  }
}
项目:SharpSK    文件:ExprEventAnvilCost.java   
@Override
@Nullable
protected Number[] get(Event e) {
    try {
        AnvilInventory a = ((PrepareAnvilEvent) e).getInventory();
        return new Number[] { a.getRepairCost() };
    } catch (NullPointerException ex) {
        return new Number[] { 0 };
    }
}
项目:OmniWorldMCPlugin    文件:InventoryClickListener.java   
@EventHandler(priority= EventPriority.LOW, ignoreCancelled=true)
public void canEnchant(InventoryClickEvent event) {
    if (!(event.getInventory() instanceof AnvilInventory)) {
        return;
    }
    if (event.getSlotType() != InventoryType.SlotType.RESULT) {
        return;
    }
    ItemStack item = event.getInventory().getItem(0);
    ItemStack item2 = event.getInventory().getItem(1);
    if (!PowerUtils.isPowerTool(item)) {
        return;
    }
    if (item2 == null) {
        return;
    }
    if (item2.getType() != Material.ENCHANTED_BOOK) {
        switch (item2.getType()) {
            case LEATHER_HELMET:
            case LEATHER_LEGGINGS:
            case LEAVES:
                return;
        }
        if (PowerUtils.isPowerTool(item2)) {
            if (!item.getEnchantments().isEmpty()) {}
        } else {
            event.setCancelled(true);
            return;
        }
    }
    if (!PowerUtils.checkEnchantPermission((Player) event.getWhoClicked(), item.getType())) {
        event.setCancelled(true);
    }
}
项目:PortalBlock    文件:ClickPortalBlockListener.java   
@EventHandler(priority = EventPriority.NORMAL)
public void onInventoryChange(InventoryClickEvent e){
    Inventory inven = e.getInventory();
    if(inven instanceof AnvilInventory){
        if(e.getRawSlot() == 2){
            ItemStack item = e.getCurrentItem();

            if(item != null){
                if(item.getType().equals(Material.ENDER_PORTAL_FRAME)){
                    ItemMeta meta = item.getItemMeta();

                    if(meta != null){
                        if(meta.hasDisplayName()){
                            String displayName = meta.getDisplayName();
                            PortalFile pf = new PortalFile();
                            if(pf.contains(displayName)){
                                e.setCancelled(true);
                                 ((Player) e.getWhoClicked()).sendMessage(messageData.get("portalblock.alreadyexist")
                                        .replace("%name%", displayName));
                            }
                        }
                    }
                }
            }
        }
    }
}
项目:BelovedBlocks    文件:CraftingListener.java   
/**
 * - Workaround to fix the crafting grid being not updated when the item is
 * taken from the grid.
 * <p>
 * - Used to prevent our blocks to be renamed using an anvil.
 * <p>
 * - Used to allow our tools to be enchanted (ensure the name is kept).
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent ev)
{
    if (ev.getInventory() instanceof CraftingInventory && ev.getSlot() == 0)
    {
        InventoryUtils.updateInventoryLater(ev.getInventory());
    }

    // Disable Anvil overrides if not using item names.
    else if (ev.getInventory() instanceof AnvilInventory && BBConfig.USE_ITEM_NAMES_FALLBACK.get())
    {
        ItemStack item = ev.getInventory().getItem(0);
        ItemStack result = ev.getInventory().getItem(2);
        if (item == null) return;
        BelovedBlock block = BelovedBlocks.getBelovedBlocksManager().getFromItem(item);

        // Items cannot be renamed
        if(block != null)
        {
            ev.getInventory().setItem(2, new ItemStack(Material.AIR, 0));
            return;
        }

        BelovedTool tool = BelovedBlocks.getToolsManager().getFromItem(item);

        // Players can add enchantments to the tools.
        if(tool != null) 
        {
            ItemUtils.setDisplayName(result, tool.getDisplayName());
            ev.getInventory().setItem(2, result);
        }
    }
}
项目:EnchantmentAPI    文件:AnvilListener.java   
private EnchantmentMerger getMerger(final AnvilInventory anvil) {
    final ItemStack result = select(anvil.getItem(0), anvil.getItem(1), true).clone();
    final ItemStack supplement = select(anvil.getItem(0), anvil.getItem(1), false);
    return new EnchantmentMerger()
            .merge(result, false)
            .merge(supplement, true);
}
项目:EnchantmentAPI    文件:AnvilListener.java   
@EventHandler
public void onClick(InventoryClickEvent event) {
    if (event.getInventory().getType() == InventoryType.ANVIL && event.getRawSlot() == 2) {
        final AnvilInventory anvil = (AnvilInventory) event.getInventory();
        if (anvil.getRepairCost() == 0
                && isPresent(anvil.getItem(2))
                && !isPresent(event.getWhoClicked().getItemOnCursor()) || !event.getAction().name().startsWith("PICKUP")) {
            final Player player = (Player)event.getWhoClicked();
            if (player.getGameMode() == GameMode.CREATIVE || checkLevels(player, anvil)) {
                player.setItemOnCursor(anvil.getItem(2));
                anvil.clear();
            }
        }
    }
}
项目:EnchantmentAPI    文件:AnvilListener.java   
private boolean checkLevels(final Player player, final AnvilInventory anvil) {
    final EnchantmentMerger merger = getMerger(anvil);
    if (player.getLevel() >= merger.getCost()) {
        player.setLevel(player.getLevel() - merger.getCost());
        return true;
    }
    return false;
}
项目:NucleusFramework    文件:AnvilRenameItemEvent.java   
/**
 * Constructor.
 *
 * @param player          The player.
 * @param anvilInventory  The anvil inventory.
 * @param item            The item being renamed.
 * @param newName         The new name.
 * @param oldName         The old name.
 */
public AnvilRenameItemEvent(Player player, AnvilInventory anvilInventory,
                            ItemStack item, String newName, @Nullable String oldName) {

    _player = player;
    _anvilInventory = anvilInventory;
    _item = item;
    _newName = newName;
    _oldName = oldName;
}
项目:SleepingPlus    文件:PlayerEvent.java   
@EventHandler
public void onPlayerInventoryClick(InventoryClickEvent event)
{
    if(plugin.isXpBar())
    {
        /**
         * This part of code, is not by me.(como89)
         * Credit : Zelnehlun
         */
        if(!event.isCancelled())
        {
            HumanEntity human = event.getWhoClicked();
            if(human instanceof Player)
            {
                Inventory inv = event.getInventory();
                if(inv instanceof AnvilInventory)
                {
                    InventoryView view = event.getView();
                    int rawSlot = event.getRawSlot();

                    if(rawSlot == view.convertSlot(rawSlot))
                    {
                        if(rawSlot == 2)
                        {
                            ItemStack item = event.getCurrentItem();
                            if(item != null)
                            {
                                event.setCancelled(true);
                            }
                        }
                    }
                }
            }
        }
        /**
         * END part of code
         */
    }
}
项目:SurvivalPlus    文件:NoAnvil.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent e)
{
    Inventory inv = e.getInventory();

    if(inv instanceof AnvilInventory)
    {
        AnvilInventory anvil = (AnvilInventory)inv;
        InventoryView view = e.getView();
        int rawSlot = e.getRawSlot();

        // compare raw slot to the inventory view to make sure we are in the upper inventory
        if(rawSlot == view.convertSlot(rawSlot))
        {
            // 2 = result slot
            if(rawSlot == 2)
            {
                // item in the left slot
                ItemStack item = anvil.getContents()[0];

                if(item != null)
                {
                    if
                    (
                        item.getType() == Material.GOLD_AXE
                        || item.getType() == Material.GOLD_PICKAXE
                        || item.getType() == Material.GOLD_SPADE
                        || item.getType() == Material.GOLD_HOE
                        || item.getType() == Material.GOLD_SWORD
                        || item.getType() == Material.WOOD_AXE
                        || item.getType() == Material.WOOD_PICKAXE
                        || item.getType() == Material.WOOD_SPADE
                        || item.getType() == Material.WOOD_HOE
                        || item.getType() == Material.WOOD_SWORD
                    )
                    {
                        e.setCancelled(true);
                        e.getWhoClicked().closeInventory();
                        e.getWhoClicked().sendMessage(ChatColor.RED + Survival.Words.get("You cannot rename or repair ") + item.getItemMeta().getDisplayName() + ChatColor.RED + Survival.Words.get("period"));
                    }
                }
            }
        }
    }
}
项目:QuestManager    文件:QuestManager.java   
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryClick(InventoryClickEvent e){

    if (e.isCancelled() || !(e.getWhoClicked() instanceof Player)) {
        return;
    }

    if (!(e.getInventory() instanceof AnvilInventory)) {
        return;
    }

    Player p = (Player) e.getWhoClicked();
    if (!QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getWorlds().contains(
            p.getWorld().getName())) {
        return;
    }
    AnvilInventory inv = (AnvilInventory) e.getInventory();

    int rawSlot = e.getSlot();

    if(rawSlot != 2){
        return;
    }
    if (inv.getItem(2) == null) {
        return;
    }
    //trying to finish it. Just compare name from slot 0 to slot 2 and make sure the same
    ItemStack left = inv.getItem(0);
    ItemStack right = inv.getItem(2);

    //first check: left has nothing, right should have nothing
    if ( (!left.hasItemMeta() && right.hasItemMeta() && right.getItemMeta().hasDisplayName())) {
        e.setCancelled(true);
        return;
    }
    //second check: the name has changed
    if (left.hasItemMeta() && left.getItemMeta().hasDisplayName()) { //we odn't need to make sure the right does cause it always will
        if (!left.getItemMeta().getDisplayName().equals(right.getItemMeta().getDisplayName())) {
            e.setCancelled(true);
            return;
        }
    }
    //last check: left has meta, no name but right does
    if (left.hasItemMeta() && !left.getItemMeta().hasDisplayName() && right.getItemMeta().hasDisplayName()) {
        e.setCancelled(true);
        return;
    }
}
项目:Skellett    文件:ExprAnvilPrepareInventoryCost.java   
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] e, int arg1, Kleenean arg2, ParseResult arg3) {
    inventory = (Expression<AnvilInventory>) e[0];
    return true;
}
项目:Skellett    文件:ExprAnvilPrepareInventory.java   
@Override
public Class<? extends AnvilInventory> getReturnType() {
    return AnvilInventory.class;
}
项目:Skellett    文件:ExprAnvilPrepareInventory.java   
@Override
@Nullable
protected AnvilInventory[] get(Event e) {
    return new AnvilInventory[]{((PrepareAnvilEvent)e).getInventory()};
}
项目:NucleusFramework    文件:JCGEventListener.java   
@EventHandler(priority=EventPriority.NORMAL, ignoreCancelled = true)
private void onInventoryClick(InventoryClickEvent event) {

    HumanEntity entity = event.getWhoClicked();

    if (!(entity instanceof Player))
        return;

    final Player p = (Player)entity;

    Inventory inventory = event.getInventory();
    if (!(inventory instanceof AnvilInventory))
        return;

    final AnvilInventory anvilInventory = (AnvilInventory)inventory;
    InventoryView view = event.getView();
    int rawSlot = event.getRawSlot();

    if (rawSlot != view.convertSlot(rawSlot) || rawSlot != 2)
        return;

    ItemStack resultItem = anvilInventory.getItem(2);
    if (resultItem == null)
        return;

    ItemStack slot1 = anvilInventory.getItem(0);
    ItemStack slot2 = anvilInventory.getItem(1);

    ItemStack slot1Clone = slot1 == null ? null : slot1.clone();
    ItemStack slot2Clone = slot2 == null ? null : slot2.clone();

    // check for rename
    String originalName = slot1 != null
            ? ItemStackUtils.getDisplayName(slot1, DisplayNameOption.OPTIONAL)
            : null;

    String newName = ItemStackUtils.getDisplayName(resultItem, DisplayNameOption.OPTIONAL);

    if (newName != null && !newName.equals(originalName)) {

        AnvilRenameItemEvent renameEvent = new AnvilRenameItemEvent(
                p, anvilInventory, resultItem, newName, originalName);

        Nucleus.getEventManager().callBukkit(this, renameEvent);

        if (renameEvent.isCancelled()) {
            cancelAnvilEvent(p, anvilInventory, slot1Clone, slot2Clone);
            return;
        }

        ItemStackUtils.setDisplayName(resultItem, renameEvent.getNewName());
    }

    if (slot2 == null || slot2.getType() == Material.AIR)
        return;

    if (slot2.getType() == Material.ENCHANTED_BOOK) {

        AnvilEnchantItemEvent enchantEvent = new AnvilEnchantItemEvent(p, anvilInventory);
        Nucleus.getEventManager().callBukkit(this, enchantEvent);

        if (enchantEvent.isCancelled()) {
            cancelAnvilEvent(p, anvilInventory, slot1Clone, slot2Clone);
        }
    }
    else {

        AnvilRepairItemEvent repairEvent = new AnvilRepairItemEvent(p, anvilInventory, resultItem);
        Nucleus.getEventManager().callBukkit(this, repairEvent);

        if (repairEvent.isCancelled()) {
            cancelAnvilEvent(p, anvilInventory, slot1Clone, slot2Clone);
        }
    }
}
项目:NucleusFramework    文件:AnvilRenameItemEvent.java   
/**
 * Get the anvil inventory.
 */
public AnvilInventory getAnvilInventory() {
    return _anvilInventory;
}
项目:NucleusFramework    文件:AnvilEnchantItemEvent.java   
/**
 * Get the inventory of the anvil that is repairing the item.
 */
public AnvilInventory getAnvilInventory() {
    return _anvilInventory;
}
项目:NucleusFramework    文件:AnvilRepairItemEvent.java   
/**
 * Get the inventory of the anvil that is repairing the item.
 */
public AnvilInventory getAnvilInventory() {
    return _anvilInventory;
}
项目:DirtyArrows    文件:AnvilListener.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory() instanceof AnvilInventory && e.getWhoClicked() instanceof Player) {
        Player player = (Player) e.getWhoClicked();
        AnvilInventory inv = (AnvilInventory) e.getInventory();
        if (e.getSlot() == 2) {
            ItemStack item = inv.getItem(2);

            if (!item.hasItemMeta()) {
                return;
            }

            if (!item.getItemMeta().hasDisplayName()) {
                return;
            }

            String name = item.getItemMeta().getDisplayName();
            String node = "";

            if ((node = Util.isBastard(name)) == Util.NONE) {
                return;
            }

            int levels = plugin.getConfig().getInt(node + ".levels");

            if (levels < 0) {
                return;
            }

            int required = (player.getGameMode() == GameMode.CREATIVE ? 0 : levels);

            if (player.getLevel() < required) {
                player.sendMessage(Message.NOT_ENOUGH_LEVELS_1);
                player.sendMessage(Message.NOT_ENOUGH_LEVELS_2.replace("%l%", required + ""));
                player.playSound(player.getLocation(), Sound.BAT_HURT, 1L, 1L);
                e.setCancelled(true);
                return;
            }

            player.setLevel(player.getLevel() - required);
            if (player.getGameMode() != GameMode.CREATIVE) {
                player.getInventory().addItem(e.getCurrentItem());
                inv.setItem(0, null);
                player.playSound(player.getLocation(), Sound.ANVIL_USE, 1L, 1L);
                player.closeInventory();
            }
        }
    }
}
项目:EpicQuest    文件:TypeRepair.java   
@EventHandler
public static void onInventoryClick(InventoryClickEvent e){
    if(e.isCancelled()) return;

    HumanEntity ent = e.getWhoClicked();
    if(!(ent instanceof Player)) return;

    Player player = (Player)ent;
    Inventory inv = e.getInventory();
    if(!(inv instanceof AnvilInventory)) return;

    EpicPlayer epicPlayer = EpicSystem.getEpicPlayer(player.getUniqueId());
    List<EpicQuestTask> taskList = epicPlayer.getTasksByType(TaskTypes.REPAIR_ITEM);

    for(EpicQuestTask task : taskList){

        AnvilInventory anvil = (AnvilInventory)inv;
        InventoryView view = e.getView();
        int rawSlot = e.getRawSlot();

        if(rawSlot == view.convertSlot(rawSlot)){

            // 2 = result slot
            if(rawSlot != 2) return;

            ItemStack[] items = anvil.getContents();
            ItemStack item1 = items[0];
            ItemStack item3 = e.getCurrentItem();
            //if(item1 == null || item2 == null || item3 == null) return;

            Material id1 = item1.getType();
            Material id3 = item3.getType();

            if(id1 != id3) return;

            //See if correct item is repaired
            if(id3 == Material.matchMaterial(task.getTaskID())){

                ItemMeta meta = item3.getItemMeta();
                if(meta == null) return;

                if(meta instanceof Repairable){
                    Repairable repairable = (Repairable)meta;
                    int repairCost = repairable.getRepairCost();

                    if(player.getLevel() >= repairCost){
                        task.ProgressTask(1, epicPlayer, true);
                    }
                }
            }
        }
    }
}
项目:MinecraftPlugins    文件:AnvilRename.java   
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {

    CommonString commonString = new CommonString();

    Inventory inventory = event.getClickedInventory();

    if (inventory == null) return;

    if (inventory instanceof AnvilInventory) {

        if (event.getCurrentItem() != null && event.getCurrentItem().hasItemMeta()) {

            if (event.getCurrentItem().getItemMeta().hasDisplayName()) {

                Set<String> rocketItems = new HashSet<>(Arrays.asList(
                        "Rocket Boots",
                        "Rocket Boot Repair Station",
                        "Rocket Boot Repair Tank",
                        "Rocket Boot Repair Stand",
                        "Rocket Boot Control",
                        "Rocket Boot Fly Zone Controller",
                        "Rocket Boot Booster",
                        "Rocket Boot Saddle",
                        "Rocket Boot Fuel Jacket",
                        "Rocket Boot Variant",
                        "Rocket Boot Enhancement"));

                ItemStack currentItem = event.getCurrentItem();

                if (rocketItems.contains(ChatColor.stripColor(currentItem.getItemMeta().getDisplayName()))) {

                    if (currentItem.getItemMeta().hasLore()) {

                        if (!currentItem.getItemMeta().getLore().get(0).equals(ChatColor.YELLOW + "Rocket Level X")) {

                            Player player = (Player) event.getWhoClicked();
                            player.closeInventory();
                            commonString.messageSend(RocketInit.getPlugin(), player, true, RocketLanguage.RB_MOD_ERROR);

                        }

                    }

                }

            }

        }

    }

}
项目:NucleusFramework    文件:AnvilEnchantItemEvent.java   
/**
 * Constructor.
 *
 * @param player          The player
 * @param anvilInventory  The anvil inventory.
 */
public AnvilEnchantItemEvent(Player player, AnvilInventory anvilInventory) {
    _player = player;
    _anvilInventory = anvilInventory;
}
项目:NucleusFramework    文件:AnvilRepairItemEvent.java   
/**
 * Constructor.
 *
 * @param player          The player
 * @param anvilInventory  The anvil inventory.
 * @param item            The item being repaired.
 */
public AnvilRepairItemEvent(Player player, AnvilInventory anvilInventory, ItemStack item) {
    _player = player;
    _anvilInventory = anvilInventory;
    _item = item;
}