@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); } } } } } }
@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; } } } } }
@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()); } } }
@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); } }
@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); }
@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())); }
@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)); } } } }
@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()); } } } } }
@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); } } }
@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); } } } } } }
@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); } } } } }
@EventHandler public void onPrepareItemCraft(PrepareItemCraftEvent event) { ItemStack stack = event.getInventory().getResult(); if(applyRules(stack)) { event.getInventory().setResult(stack); } }
@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)); } } }
@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); } } } }
@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)); } } }
@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); }
@EventHandler public void onPrepareItemCraft(PrepareItemCraftEvent event){ for(ItemStack item : event.getInventory().getMatrix()){ if(item == null) continue; if(ItemUtil.matches(item, SelectorLayout.getSelectorItem())){ event.getInventory().setResult(new ItemStack(Material.AIR)); break; } } }
@EventHandler public void onSaddleSign(final PrepareItemCraftEvent event) { if (event.getRecipe() instanceof ShapelessRecipe) { final ShapelessRecipe recipe = (ShapelessRecipe)event.getRecipe(); if (recipe.getIngredientList().equals(Sddls.recipe.getIngredientList())) { final Player player = (Player) event.getView().getPlayer(); ItemStack saddle = null; for (final ItemStack item : event.getInventory().getMatrix()) if (item.getType() == Material.SADDLE) saddle = item; saddle = Sddls.signSaddle(saddle, player); event.getInventory().setResult(saddle); } } }
@EventHandler (priority = EventPriority.HIGHEST) public void onPrepareItemCraft (PrepareItemCraftEvent e) { if (e.getViewers().size() < 1) return; World world = e.getViewers().get(0).getWorld(); if(!isEnabled(world)) return; CraftingInventory inv = e.getInventory(); ItemStack result = inv.getResult(); if(result != null && denied.contains(result.getType())) inv.setResult(null); }
@EventHandler public void onCraft(PrepareItemCraftEvent e) { if(Config.getConfig().getBoolean("BlockEnderCrystals.Crafting")) { if (e.getRecipe().getResult().getType() == Material.END_CRYSTAL) { e.getInventory().setResult(new ItemStack(Material.AIR)); } } }
@EventHandler public void onCraft(PrepareItemCraftEvent event) { if (event.getRecipe().getResult().getType() == Material.WOOD_PICKAXE) event.getInventory().setResult(new ItemStack(Material.STONE_PICKAXE)); else if (event.getRecipe().getResult().getType() == Material.WOOD_AXE) event.getInventory().setResult(new ItemStack(Material.STONE_AXE)); else if (event.getRecipe().getResult().getType() == Material.WOOD_SPADE) event.getInventory().setResult(new ItemStack(Material.STONE_SPADE)); }
@EventHandler public void onCraftItem(PrepareItemCraftEvent e){ if (e.getView().getPlayer() instanceof Player){ Player p = (Player) e.getView().getPlayer(); ItemStack result = e.getInventory().getResult(); if (RPUtil.denyPotion(result, p)){ e.getInventory().setResult(new ItemStack(Material.AIR)); } } }
public static ItemStack callPreCraftEvent(InventoryCrafting matrix, ItemStack result, InventoryView lastCraftView, boolean isRepair) { CraftInventoryCrafting inventory = new CraftInventoryCrafting(matrix, matrix.resultInventory); inventory.setResult(CraftItemStack.asCraftMirror(result)); PrepareItemCraftEvent event = new PrepareItemCraftEvent(inventory, lastCraftView, isRepair); Bukkit.getPluginManager().callEvent(event); org.bukkit.inventory.ItemStack bitem = event.getInventory().getResult(); return CraftItemStack.asNMSCopy(bitem); }
@EventHandler public void onPrepareCraft(PrepareItemCraftEvent e) { Player player = (Player) e.getView().getPlayer(); if (e.getRecipe() instanceof ShapedRecipe) { ShapedRecipe recipe = (ShapedRecipe) e.getRecipe(); if (PlayerMeta.getMeta(player).getKit() != Kit.ARCHER) { if (sameRecipe(recipe, arrowRecipe)) { e.getInventory().setResult(null); } } } }
@EventHandler public void onPrepare(PrepareItemCraftEvent e) { CraftingInventory inv = e.getInventory(); if(inv.getRecipe().getResult().hasItemMeta()) { if(inv.getRecipe().getResult().getItemMeta().hasDisplayName()) { if(inv.getRecipe().getResult().getItemMeta().getDisplayName().equalsIgnoreCase("crate")) { if(inv.getItem(5) != null) { if(inv.getItem(5).hasItemMeta()) { if(inv.getItem(5).getItemMeta().hasDisplayName()) { if(pl.isCrate(inv.getItem(5).getItemMeta().getDisplayName())) { Crate crate = pl.getCrate(inv.getItem(5).getItemMeta().getDisplayName()); if(crate.needsKey()) { if(inv.getItem(5).getType() == (crate.getType() == CrateType.NORMAL ? Material.GOLD_INGOT : Material.DIAMOND)) { inv.setResult(crate.getKeyItem()); } else { inv.setResult(null); } } else { inv.setResult(null); } } else { inv.setResult(null); } } else { inv.setResult(null); } } else { inv.setResult(null); } } } } } }
@EventHandler public void onPrepareCraftItemEvent(PrepareItemCraftEvent e) { //if we are enabled if(isEnabled() && !isRecipeAllowedForPermissible(e.getView().getPlayer(), e.getRecipe())) { //set to air if not allowed e.getInventory().setResult(new ItemStack(Material.AIR)); } }
/** * Whenever an item is about to pop up on the crafting table * * @param e the prepareitemcraftevent */ @EventHandler public void onPrepareCraftItemEvent(PrepareItemCraftEvent e) { //if we are enabled if(isEnabled()) { //check if no permission to create if(!isRecipeAllowedForPermissible(e.getView().getPlayer(), e.getRecipe())) { //set to air if not allowed e.getInventory().setResult(new ItemStack(Material.AIR)); } } }
@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); } }
@EventHandler public void onPrepareItemCraft(PrepareItemCraftEvent event) { Player player = (Player) event.getView().getPlayer(); ItemStack result = event.getInventory().getResult(); if (!permissionChecker.check(player, "craft", result.getType())) { // Change display name ItemMeta meta = result.getItemMeta(); meta.setDisplayName(ChatColor.RED + messageHelper.getMessage("messages.craft.denied", result.getType(), "You cannot craft this item")); result.setItemMeta(meta); // Update crafting result event.getInventory().setResult(result); } }
@EventHandler(priority = EventPriority.NORMAL) public void onPrepareItemCraft(PrepareItemCraftEvent event) { boolean isUpgradeRecipe = RecipeUtil.areEqual(event.getRecipe(), ResurrectionScroll.getResurrectionScrollUpgradeRecipe()); if (!isUpgradeRecipe) { return; } CraftingInventory inventory = event.getInventory(); boolean resurrectionScrollFound = false; int tier = 0; for (ItemStack itemStack : inventory.getMatrix()) { if (itemStack == null) { continue; } if (ItemUtils.isResurrectionScroll(itemStack)) { resurrectionScrollFound = true; tier = Tier.getTier(itemStack).toNumerical(); } } if (!resurrectionScrollFound || tier >= 3) { inventory.setResult(null); return; } inventory.setResult(ResurrectionScroll.getResurrectionScroll(1, tier + 1)); }
@EventHandler(priority = EventPriority.HIGH) public void onPrepareItemCraft(PrepareItemCraftEvent event) { // Check custom items aren't used in non-plugin related recipes final Iterator<FXRecipe> it = registry.get().getRecipes().iterator(); final ItemStack[] matrix = event.getInventory().getMatrix(); FXRecipe recipe = null; while (it.hasNext()) { recipe = it.next(); if (recipe instanceof FXFurnaceRecipe) continue; if (recipe.matches(matrix)) break; else recipe = null; } // recipe == null if matrix didn't match precisely if (recipe == null) { // make sure if this is a custom item it matches the recipe if (registry.get().getDefinition(event.getRecipe().getResult()).isPresent()) { event.getInventory().setResult(null); return; } for (ItemStack item : event.getInventory().getMatrix()) { // If any of the items in matrix are registered they are custom if (registry.get().getDefinition(item).isPresent()) { event.getInventory().setResult(null); return; } } } else { // recipe result may not be what the event says since MC compresses down to material event.getInventory().setResult(recipe.getResult()); } }