當前位置: 首頁>>代碼示例>>Java>>正文


Java PrepareItemCraftEvent.isRepair方法代碼示例

本文整理匯總了Java中org.bukkit.event.inventory.PrepareItemCraftEvent.isRepair方法的典型用法代碼示例。如果您正苦於以下問題:Java PrepareItemCraftEvent.isRepair方法的具體用法?Java PrepareItemCraftEvent.isRepair怎麽用?Java PrepareItemCraftEvent.isRepair使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.event.inventory.PrepareItemCraftEvent的用法示例。


在下文中一共展示了PrepareItemCraftEvent.isRepair方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onPrepareCrowbarCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPrepareCrowbarCraft(PrepareItemCraftEvent event) {
    CraftingInventory inventory = event.getInventory();
    if (event.isRepair() && event.getRecipe().getResult().getType() == Crowbar.CROWBAR_TYPE) {
        int endFrameUses = 0;
        int spawnerUses = 0;
        boolean changed = false;

        ItemStack[] matrix = inventory.getMatrix();
        for (ItemStack ingredient : matrix) {
            Optional<Crowbar> crowbarOptional = Crowbar.fromStack(ingredient);
            if (crowbarOptional.isPresent()) {
                Crowbar crowbar = crowbarOptional.get();
                spawnerUses += crowbar.getSpawnerUses();
                endFrameUses += crowbar.getEndFrameUses();
                changed = true;
            }
        }

        // Finally update the result.
        if (changed) {
            inventory.setResult(new Crowbar(spawnerUses, endFrameUses).getItemIfPresent());
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:CrowbarListener.java

示例2: prepareCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入方法依賴的package包/類
@EventHandler public void prepareCraft(final PrepareItemCraftEvent event) {
    Recipe recipe = event.getRecipe();
    if (event.isRepair() || recipe instanceof MerchantRecipe || recipe instanceof FurnaceRecipe) {
        return;
    }
    if (recipe.getResult() != null) {
        return;
    }
    CraftingInventory inventory = event.getInventory();
    ItemStack[] matrix = inventory.getMatrix();
    PlayerheadItemStack skull = null;
    int gold = 0, skulls = 0;
    for (ItemStack item : matrix) {
        if (item.getType() == Material.SKULL_ITEM) {
            if (item instanceof PlayerheadItemStack && ((SkullMeta) item.getItemMeta()).hasOwner()) {
                ++skulls;
                skull = (PlayerheadItemStack) item;
            }
        } else if (item.getType() == Material.GOLD_INGOT) {
            ++gold;
        }
    }
    if (skull == null || gold != 7 || skulls != 1) {
        return;
    }
    skull.setGolden(true);
    inventory.setResult(skull);
}
 
開發者ID:Project-Coalesce,項目名稱:UHC,代碼行數:29,代碼來源:CraftingHandler.java

示例3: CraftTool

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入方法依賴的package包/類
@EventHandler
public void CraftTool(PrepareItemCraftEvent event)
{
    if (event.isRepair()) return;
    
    List<ItemStack> items = new ArrayList<ItemStack>();
    boolean success = false;
    for(ItemStack a : event.getInventory().getContents()) {
        if(a.getType().equals(Material.AIR)) continue;
        items.add(a);
    } // Get an easier to handle list.

    if (items.size() != 3) return;
    
    if(items.contains(ToolRegistry.getVeinMinerCoupon())){
        for (ItemStack i : items){
            if(ToolRegistry.veinMinerAllowedTools.contains(i.getType())) {
                ItemMeta iMeta = i.getItemMeta();
                
                List<String> lore = new ArrayList<String>();
                lore.add(ToolRegistry.VEIN_TAG);
                iMeta.setLore(lore);
                
                i.setItemMeta(iMeta);
                event.getInventory().setResult(i);
                success = true;
            }
        }
    }else{
        return;
    }
    

    if (success == false) {
        event.getInventory().setResult(null);
    }
}
 
開發者ID:sabersamus,項目名稱:Bytecraft,代碼行數:38,代碼來源:ToolListener.java

示例4: onPrepareItemCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入方法依賴的package包/類
@EventHandler
public void onPrepareItemCraft(PrepareItemCraftEvent event)
{
    ItemStack[] items = event.getInventory().getMatrix();

    for(ItemStack itemStack : items)
    {
        if(!NBTHelper.getName(itemStack).equals("null"))
        {
            EnhancedItem item = EnhancedItemUtil.getItem(itemStack);
            
            if(item != null)
            {
                if(event.isRepair() && !Boolean.parseBoolean(item.getProperty("canRepair")))
                {
                    event.getInventory().setResult(new ItemStack(Material.AIR));
                }
                else if(event.isRepair() && Boolean.parseBoolean(item.getProperty("canRepair")))
                {
                    ItemStack result = event.getRecipe().getResult();
                    ItemStack newStack = EnhancedItemUtil.createItem(item, result);
                    event.getInventory().setResult(newStack);
                }
            }
        }
    }
    
    if(EnhancedItemUtil.getItem(event.getInventory().getResult()) != null)
    {
        event.getInventory().setResult(new ItemStack(Material.AIR));
    }
    
    for(Recipe recipe : EnhancedItems.getInstance().getRecipes())
    {
        if(RecipeUtil.matches(items, recipe))
        {
            if(RecipeUtil.matchesExact(items, recipe))
            {       
                event.getInventory().setResult(EnhancedItemUtil.createItem(recipe.getOutput(), null));
                
                break;
            }
            else
            {
                event.getInventory().setResult(new ItemStack(Material.AIR));
                
                continue;
            }
        }
    }
}
 
開發者ID:ItzDennisz,項目名稱:Enhanced-Items,代碼行數:52,代碼來源:EnhancedItemsEvents.java


注:本文中的org.bukkit.event.inventory.PrepareItemCraftEvent.isRepair方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。