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


Java PrepareItemCraftEvent類代碼示例

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


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

示例1: onPreCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPreCraft(final PrepareItemCraftEvent event) 
{
    final Recipe recipe = event.getRecipe();

    // Invalid or incomplete recipe entered
    if (recipe == null)
        return;

    BelovedItem item = BelovedBlocks.getBelovedBlocksManager().getFromItem(recipe.getResult());
    if(item == null)
        item = BelovedBlocks.getToolsManager().getFromItem(recipe.getResult());
    
    if(item != null)
    {
        for(HumanEntity entity : event.getViewers())
        {
            if(!(entity instanceof Player && item.canCraft((Player)entity)))
            {
                event.getInventory().setResult(new ItemStack(Material.AIR));
            }
        }
    }
}
 
開發者ID:zDevelopers,項目名稱:BelovedBlocks,代碼行數:25,代碼來源:CraftingListener.java

示例2: handleWoolCrafting

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void handleWoolCrafting(PrepareItemCraftEvent event) {
    ItemStack result = event.getRecipe().getResult();
    InventoryHolder holder = event.getInventory().getHolder();

    if (holder instanceof Player) {
        MatchPlayer playerHolder = this.match.getPlayer((Player) holder);

        if (playerHolder != null && result != null && result.getType() == Material.WOOL) {
            for(MonumentWool wool : this.wools) {
                if(wool.getDefinition().isObjectiveWool(result)) {
                    if(!wool.getDefinition().isCraftable()) {
                        playerHolder.sendMessage(ChatColor.RED + PGMTranslations.t("match.wool.craftDisabled", playerHolder, BukkitUtils.woolMessage(wool.getDyeColor())));
                        event.getInventory().setResult(null);
                    }
                }
            }
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:21,代碼來源:WoolMatchModule.java

示例3: onPrepareCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void onPrepareCraft(PrepareItemCraftEvent e)
{
	CraftingInventory inv = e.getInventory();
	ItemStack result = inv.getResult();
	if(result != null && result.getType() != Material.GLASS_BOTTLE)
	{
		List<ItemStack> bottles = Arrays.asList(inv.getMatrix());
		Iterator<ItemStack> it = bottles.iterator();
		
		while(it.hasNext())
		{
			ItemStack bottle = it.next();
			if(bottle == null) continue;
			if(bottle.getType().equals(Material.POTION))
			{
				if(!checkWaterBottle(bottle))
				{
					inv.setResult(null);
					return;
				}
			}
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:26,代碼來源:WaterBottleCrafting.java

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

示例5: onPrepareItemCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGH)
public void onPrepareItemCraft(PrepareItemCraftEvent e) {
	if (e.getInventory() == null) return;

	ItemStack item = e.getInventory().getResult();
	if (item == null) return; // This should never ever ever ever run. If it does then you probably screwed something up.

	if (item.getType() == Material.GOLDEN_APPLE && item.getDurability() == (short) 1) {

		World world = e.getView().getPlayer().getWorld();

		if (isSettingEnabled("no-conflict-mode")) return;

		if (!isEnabled(world))
			e.getInventory().setResult(null);
		else if (isEnabled(world) && !isSettingEnabled("enchanted-golden-apple-crafting"))
			e.getInventory().setResult(null);
	}
}
 
開發者ID:gvlfm78,項目名稱:BukkitOldCombatMechanics,代碼行數:20,代碼來源:ModuleGoldenApple.java

示例6: onWoolCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true)
public void onWoolCraft(PrepareItemCraftEvent event) {
    if (this.isCraftable()) {
        return;
    }

    ItemStack result = event.getInventory().getResult();
    if (result == null || !WoolUtils.isWool(result, this.color)) {
        return;
    }

    GamePlayer player = this.getGame().getPlayer(event.getActor());
    if (player != null) {
        player.sendError("You may not craft " + ChatColor.GOLD +
                this.getColoredName() + Messageable.ERROR_COLOR + ".");
    }

    event.getInventory().setResult(null);
}
 
開發者ID:ShootGame,項目名稱:Arcade2,代碼行數:20,代碼來源:Wool.java

示例7: onPrepareItemCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void onPrepareItemCraft(PrepareItemCraftEvent event) {
	if(event.getViewers().isEmpty()) {
		return;
	}

	NovaPlayer nPlayer = PlayerManager.getPlayer(event.getViewers().get(0));

	if(event.getRecipe() == null
			|| event.getRecipe().getResult() == null
			|| event.getRecipe().getResult().getType() != Material.SHIELD
			|| !nPlayer.hasGuild()
			|| nPlayer.getGuild().getBannerMeta().numberOfPatterns() == 0) {
		return;
	}

	for(ItemStack ingredient : event.getInventory().getContents()) {
		if(ingredient != null
				&& ingredient.getType() == Material.SHIELD
				&& ingredient.hasItemMeta()) {
			return;
		}
	}

	event.getInventory().setResult(BannerUtils.applyMeta(event.getRecipe().getResult(), nPlayer.getGuild().getBannerMeta()));
}
 
開發者ID:MarcinWieczorek,項目名稱:NovaGuilds,代碼行數:27,代碼來源:RegionInteractListener.java

示例8: onCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void onCraft(PrepareItemCraftEvent event) {
	if (event.getRecipe() != null && event.getRecipe().getResult() != null) {
		Item item = Zephyrus.getItemManager().getItem(event.getRecipe().getResult());
		if (item == null) {
			return;
		}
		for (HumanEntity human : event.getViewers()) {
			if (human instanceof Player) {
				Player player = (Player) human;
				if (!player.hasPermission("zephyrus.craft." + item.getInternalName())) {
					event.getInventory().setResult(null);
					Language.sendError("crafting.item.nopermission", player, "[ITEM]", item.getName());
				} else if (Zephyrus.getUser(player).getLevel() < item.getCraftingLevel()) {
					event.getInventory().setResult(null);
					Language.sendError("crafting.item.requiredlevel", player, "[LEVEL]", item.getCraftingLevel()
							+ "", "[ITEM]", item.getName());
				}
			}
		}
	}
}
 
開發者ID:mcardy,項目名稱:Zephyrus-II,代碼行數:23,代碼來源:ItemListener.java

示例9: onPrepareItemCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
private void onPrepareItemCraft(PrepareItemCraftEvent event) {

    FilteredWorkbenchView workbench = _viewMap.get(event.getView());
    if (workbench == null)
        return;

    ItemStack result = event.getRecipe().getResult();

    ItemFilter filter = workbench.getItemFilter();
    if (filter == null)
        return;

    if (!filter.isValid(result)) {
        InventoryView invView = event.getView();
        if (invView != null) {
            ItemStack stack = result.clone();
            ItemStackUtils.setLore(stack, workbench.getDenyLore());
            invView.setItem(0, stack);
        }
    }
}
 
開發者ID:JCThePants,項目名稱:NucleusFramework,代碼行數:23,代碼來源:FilteredWorkbenchView.java

示例10: onPrepareItemCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void onPrepareItemCraft(PrepareItemCraftEvent event) {
    for (HumanEntity viewer : event.getViewers()) {
        if (viewer.getGameMode() != GameMode.CREATIVE) {
            if(viewer instanceof Player) {
                RegisteredServiceProvider<CharacterPlugin> characterPluginProvider = Bukkit.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
                if (characterPluginProvider != null) {
                    ItemStack craftedItem = event.getInventory().getResult();
                    if (plugin.canGainCraftEfficiency(craftedItem.getType())) {
                        CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
                        net.wayward_realms.waywardlib.character.Character character = characterPlugin.getActiveCharacter((Player) viewer);
                        int craftEfficiency = plugin.getCraftEfficiency(character, craftedItem.getType());
                        int amount = (int) Math.max(1, Math.round(((double) craftEfficiency / 50D) * (double) craftedItem.getAmount()));
                        craftedItem.setAmount(amount);
                        if (ToolType.getToolType(event.getInventory().getResult().getType()) != null) {
                            ToolType type = ToolType.getToolType(event.getInventory().getResult().getType());
                            craftedItem.setDurability((short) (craftedItem.getType().getMaxDurability() - (0.75D * (double) plugin.getMaxToolDurability(character, type))));
                        }
                        event.getInventory().setResult(craftedItem);
                    }
                }
            }
        }
    }
}
 
開發者ID:WaywardRealms,項目名稱:Wayward,代碼行數:26,代碼來源:PrepareItemCraftListener.java

示例11: craftingHandler

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void craftingHandler(PrepareItemCraftEvent e) {
	if (results.containsKey(e.getRecipe().getResult())) {
		ICustomItem item = results.get(e.getRecipe().getResult());
		List<HumanEntity> players = e.getViewers();
		PlayerCraftCustomItemEvent event = new PlayerCraftCustomItemEvent(players, item, e);
		Bukkit.getPluginManager().callEvent(event);
		if (event.isCancelled()) {
			e.getInventory().setResult(null);
		}
		for (HumanEntity en : e.getViewers()) {
			if (en instanceof Player) {
				Player player = (Player) en;
				if (!player.hasPermission("zephyrus.craft." + item.getPerm())) {
					e.getInventory().setResult(null);
				}
				if (Zephyrus.getUser(player).getLevel() < item.getReqLevel()) {
					Lang.msg("zephyrus.craft.nolevel", player);
					e.getInventory().setResult(null);
				}
			}
		}
	}
}
 
開發者ID:mcardy,項目名稱:Zephyrus,代碼行數:25,代碼來源:PlayerListener.java

示例12: onPrepareItemCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void onPrepareItemCraft(PrepareItemCraftEvent event) {
    ItemStack stack = event.getInventory().getResult();
    if(applyRules(stack)) {
        event.getInventory().setResult(stack);
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:8,代碼來源:ItemModifyMatchModule.java

示例13: stopCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void stopCraft(PrepareItemCraftEvent e){
	for(HumanEntity he : e.getViewers()){
		if(he instanceof Player){
			Player p = (Player) he;
			if(! p.hasPermission("kaos.owner")) e.getInventory().setResult(new ItemStack(Material.AIR));
		}
	}
}
 
開發者ID:OverloadedCore,項目名稱:kaosEssentials,代碼行數:10,代碼來源:Core.java

示例14: onPrepareCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler
public void onPrepareCraft(PrepareItemCraftEvent e) {

	Recipe r = e.getInventory().getRecipe();
	if (r == null || e.getViewers().size() != 1) {
		return;
	}

	Player viewer = (Player) e.getViewers().get(0);

	if (r.getResult() != null) {
		DuctDetails ductDetails = DuctItemUtils.getDuctDetailsOfItem(r.getResult());
		if (ductDetails != null) {
			if (!viewer.hasPermission(ductDetails.getCraftPermission())) {
				e.getInventory().setResult(null);
				return;
			}
		} else if (DuctItemUtils.getWrenchItem().isSimilar(r.getResult())) {
			if (!viewer.hasPermission("transportpipes.craft.wrench")) {
				e.getInventory().setResult(null);
				return;
			}
		}

		if (ductDetails != null && ductDetails.getDuctType() == DuctType.PIPE) {
			boolean prevent = false;
			for (int i = 1; i < 10; i++) {
				ItemStack is = e.getInventory().getItem(i);
				if (is != null && is.getType() == Material.SKULL_ITEM && is.getDurability() == SkullType.PLAYER.ordinal()) {
					DuctDetails isDuctDetails = DuctItemUtils.getDuctDetailsOfItem(is);
					prevent |= isDuctDetails == null;
				}
			}
			if (prevent) {
				e.getInventory().setResult(null);
			}
		}
	}
}
 
開發者ID:RoboTricker,項目名稱:Transport-Pipes,代碼行數:40,代碼來源:CraftUtils.java

示例15: onPrepareCraft

import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPrepareCraft(PrepareItemCraftEvent event) {
    if (event.getInventory().getHolder() instanceof Player) {
        CraftingInventory inventory = event.getInventory();
        Player player = (Player) inventory.getHolder();
        if (isBottledExperience(inventory.getResult())) {
            int exp = new ExperienceManager(player).getCurrentExp();
            inventory.setResult(exp > 0 ? createExpBottle(exp) : new ItemStack(Material.AIR, 1));
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:12,代碼來源:BottledExpListener.java


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