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


Java AnvilInventory类代码示例

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


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

示例1: onRepair

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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);
}
 
开发者ID:benNek,项目名称:AsgardAscension,代码行数:20,代码来源:AbilityListener.java

示例2: onInventoryClick

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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);
		}
	}
}
 
开发者ID:ShyAlly,项目名称:ChestKit,代码行数:23,代码来源:ChestKitsListener.java

示例3: onItemRename

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:Nunnery,项目名称:MythicDrops,代码行数:26,代码来源:AnvilListener.java

示例4: get

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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 };
	}
}
 
开发者ID:Sharpjaws,项目名称:SharpSK,代码行数:11,代码来源:ExprEventAnvilCost.java

示例5: canEnchant

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:OmniWorldMC,项目名称:OmniWorldMCPlugin,代码行数:35,代码来源:InventoryClickListener.java

示例6: onInventoryChange

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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));
							}
						}
					}
				}
			}
		}
	}
}
 
开发者ID:Eelviny,项目名称:PortalBlock,代码行数:28,代码来源:ClickPortalBlockListener.java

示例7: onInventoryClick

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
/**
 * - 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);
        }
    }
}
 
开发者ID:zDevelopers,项目名称:BelovedBlocks,代码行数:42,代码来源:CraftingListener.java

示例8: getMerger

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
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);
}
 
开发者ID:Eniripsa96,项目名称:EnchantmentAPI,代码行数:8,代码来源:AnvilListener.java

示例9: onClick

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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();
            }
        }
    }
}
 
开发者ID:Eniripsa96,项目名称:EnchantmentAPI,代码行数:16,代码来源:AnvilListener.java

示例10: checkLevels

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
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;
}
 
开发者ID:Eniripsa96,项目名称:EnchantmentAPI,代码行数:9,代码来源:AnvilListener.java

示例11: AnvilRenameItemEvent

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:JCThePants,项目名称:NucleusFramework,代码行数:19,代码来源:AnvilRenameItemEvent.java

示例12: onPlayerInventoryClick

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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
		 */
	}
}
 
开发者ID:como89,项目名称:SleepingPlus,代码行数:40,代码来源:PlayerEvent.java

示例13: onInventoryClick

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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"));
					}
				}
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:46,代码来源:NoAnvil.java

示例14: onInventoryClick

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:Dove-Bren,项目名称:QuestManager,代码行数:49,代码来源:QuestManager.java

示例15: init

import org.bukkit.inventory.AnvilInventory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] e, int arg1, Kleenean arg2, ParseResult arg3) {
	inventory = (Expression<AnvilInventory>) e[0];
	return true;
}
 
开发者ID:TheLimeGlass,项目名称:Skellett,代码行数:7,代码来源:ExprAnvilPrepareInventoryCost.java


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